简体   繁体   English

在WP7中为BitmapImage调用SetSource时出现OutOfMemoryException

[英]OutOfMemoryException when calling SetSource for BitmapImage in WP7

I am basically trying to convert a GIF image to a PNG image using the ImageTools library in WP7. 我基本上是在尝试使用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);

As soon as I call pngImage.SetSource(pngBytes) I get OutOfMemoryException . 一旦我调用pngImage.SetSource(pngBytes)我就会得到OutOfMemoryException

Maybe there's something else I don't grock here since the debugger also shows that gifImage is 0x0 after I called gifImage.SetSource(new MemoryStream(gifBytes)) . 也许还有其他我不满意的地方,因为调试器还显示在我调用gifImage.SetSource(new MemoryStream(gifBytes))后gifImage为0x0。 For what's its worth, I've checked that gifBytes[] contains valid GIF bytes... 为了检查它的价值,我检查了gifBytes[]包含有效的GIF字节...

Any ideas what I am doing wrong? 有什么想法我做错了吗?

I am pretty sure the issue is with the ImageTools library that I am using. 我很确定问题出在我使用的ImageTools库中。 Not sure how to 100% confirm this, but it seems that if ImageTools encodes faulty image bytes that I try to set as source for the BitmapImage, the BitmapImage will throw an OutOfMemoryException. 不知道如何100%确认这一点,但是似乎如果ImageTools编码了我尝试设置为BitmapImage的源的错误图像字节,则BitmapImage将抛出OutOfMemoryException。

So I would call this a bug in both ImageTools library for not being able to encode a perfectly good Gif image to PNG format but also in BitmapImage for throwing the wrong exception in this case. 因此,我将在ImageTools库中将其称为无法将完美的Gif图像编码为PNG格式,而在BitmapImage中将其引发错误的错误称为这种错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM