我正在从字节数组转换 BitmapImage,它工作正常,除了一个特定的 .tif 文件。它在 EndInit() 处给出了一个例外:
位图像素格式不受支持。(来自 HRESULT 的异常:0x88982F80)
用于将字节数组读取到 BitmapImage 的代码是:
public BitmapImage LoadImage(byte[] ImageData)
var image = new BitmapImage();
using (var mem = new MemoryStream(imageData))
{
mem.Position = 0;
image.BeginInit();
image.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
image.CacheOption = BitmapCacheOption.OnLoad;
image.UriSource = null;
image.StreamSource = mem;
image.EndInit(); //Exception here
}
image.Freeze();
return image;
}
这是什么意思?图像在 Windows 中打开得很好,所以它没有损坏或任何东西。有没有办法在 EndInit 之前将图像转换为支持的像素格式?