适用于Windows 10的C#Universal应用程序'System.Exception'

时间:2016-01-10 21:19:19

标签: c# exception gif encode windows-10-universal

我正在尝试开发将图像编码为gif的应用程序。我发现了这段代码,但它在encode.SetPixelData(...

之后抛出了一个System.Exception
readonly List<byte[]> frames = new List<byte[]>();
    public IAsyncInfo GenerateAsync(StorageFile file)
    {
        return AsyncInfo.Run(async ctx =>
        {
            var outStream = await file.OpenAsync(FileAccessMode.ReadWrite);

            var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.GifEncoderId, outStream);

            for (int i = 0; i < frames.Count; i++)
            {
                var pixels = frames[i];

                encoder.SetPixelData(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Ignore,
                                     frameWidth, frameHeight,
                                     92.0, 92.0,
                                     pixels);


                if (i < frames.Count - 1)
                    await encoder.GoToNextFrameAsync();
            }

            await encoder.FlushAsync();
            outStream.Dispose();
        });
    }

是因为缺乏记忆? 如何解决这个异常?

感谢您的帮助:)

0 个答案:

没有答案