簡體   English   中英

在WP7中為BitmapImage調用SetSource時出現OutOfMemoryException

[英]OutOfMemoryException when calling SetSource for BitmapImage 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);

一旦我調用pngImage.SetSource(pngBytes)我就會得到OutOfMemoryException

也許還有其他我不滿意的地方,因為調試器還顯示在我調用gifImage.SetSource(new MemoryStream(gifBytes))后gifImage為0x0。 為了檢查它的價值,我檢查了gifBytes[]包含有效的GIF字節...

有什么想法我做錯了嗎?

我很確定問題出在我使用的ImageTools庫中。 不知道如何100%確認這一點,但是似乎如果ImageTools編碼了我嘗試設置為BitmapImage的源的錯誤圖像字節,則BitmapImage將拋出OutOfMemoryException。

因此,我將在ImageTools庫中將其稱為無法將完美的Gif圖像編碼為PNG格式,而在BitmapImage中將其引發錯誤的錯誤稱為這種錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM