No error if PngEncoder produces faulty bytes?

Apr 12, 2012 at 6:23 PM

I am using ImageTools to convert any Gif image to a PNG image and then showing the PNG image on the UI.

 

ExtendedImage gifImage = (ExtendedImage)s;
MemoryStream pngBytes = new MemoryStream();

ImageTools.IO.Png.PngEncoder enc = new PngEncoder();
enc.Encode(gifImage, pngBytes);

BitmapImage outputImage = new BitmapImage();
outputImage.SetSource(pngBytes);

 

This works rather well, but sometimes I get OutOfMemoryException when calling SetSource (last line). I suspect this is because the content of pngBytes (the result of the Gif encoding to PNG) contains faulty image bytes. Meaning the encoding failed. For what it's worth, the Gif I try to convert is this one: http://www.phdcomics.com/comics/archive/phd041112s.gif

Is there a way for me to know if the encoding was successful or not? And secondly, why would that particular Gif not work while others I've tested do work?