我正在尝试开发将图像编码为gif的应用程序。我发现了这段代码,但它在encode.SetPixelData(...
之后抛出了一个System.Exceptionreadonly 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();
});
}
是因为缺乏记忆? 如何解决这个异常?
感谢您的帮助:)