C# 在WP7中为BitmapImage调用SetSource时发生OutOfMemoryException

C# 在WP7中为BitmapImage调用SetSource时发生OutOfMemoryException,c#,windows-phone-7,C#,Windows Phone 7,我基本上是在尝试使用WP7中的ImageTools库将GIF图像转换为PNG图像 byte[] gifBytes = // GIF image bytes from the web ImageTools.IO.Decoders.AddDecoder<GifDecoder>(); ImageTools.IO.Encoders.AddEncoder<PngEncoder>(); ImageTools.IO.Png.PngEncoder enc = new PngEncode

我基本上是在尝试使用WP7中的ImageTools库将GIF图像转换为PNG图像

byte[] gifBytes = // GIF image bytes from the web

ImageTools.IO.Decoders.AddDecoder<GifDecoder>();
ImageTools.IO.Encoders.AddEncoder<PngEncoder>();
ImageTools.IO.Png.PngEncoder enc = new PngEncoder();

ExtendedImage gifImage = new ExtendedImage();
gifImage.SetSource(new MemoryStream(gifBytes));                

MemoryStream pngBytes = new MemoryStream();
enc.Encode(gifImage, pngBytes);

BitmapImage pngImage = new BitmapImage(); 
pngImage.SetSource(pngBytes);
byte[]gifBytes=//来自web的GIF图像字节
ImageTools.IO.Decoders.AddDecoder();
ImageTools.IO.Encoders.AddEncoder();
ImageTools.IO.Png.PngEncoder enc=new PngEncoder();
ExtendedImage gifImage=新的ExtendedImage();
SetSource(新内存流(gifBytes));
MemoryStream pngBytes=新的MemoryStream();
enc.Encode(gifImage,pngBytes);
BitmapImage pngImage=新的BitmapImage();
pngImage.SetSource(pngBytes);
只要我调用
pngImage.SetSource(pngBytes)
我就会得到
OutOfMemoryException

也许还有一些我在这里没有提到的东西,因为在我调用
gifImage.SetSource(newmemoryStream(gifBytes))
之后,调试器还显示gifImage是0x0。为了证明它的价值,我检查了
gifBytes[]
是否包含有效的GIF字节


你知道我做错了什么吗

我很确定问题出在我使用的ImageTools库上。不确定如何100%确认,但如果ImageTools对我尝试设置为BitmapImage源的错误图像字节进行编码,BitmapImage将抛出OutOfMemoryException


因此,我认为这是ImageTools库中的一个错误,因为它无法将完美的Gif图像编码为PNG格式,但在BitmapImage中,它在这种情况下引发了错误的异常

你正在处理的图像的尺寸是多少?我事先不知道。我基本上有一组我知道是GIF图像的字节。出于好奇,在这种情况下,哪里需要这些信息?为了创建一个扩展图像(即GIF),我需要知道吗?哦,但是对于我现在的这个特殊情况,图像是600px×205px。这是一个动画GIF吗?处理动画gif时,ImageTools在内部存储gif的未压缩位图表示(每帧一个位图,每像素4个字节)。在这种情况下,每帧600*205*4=492千焦。根据gif上的帧数,它可以增长得非常快。不,它不是动画gif。Gif字节数组的长度为42919字节。对我来说,这听起来不算太大,这让我相信一定还有别的事情我不明白。。。