0
我試圖從bmp文件加載BitmapImage。 當我加載PNG或JPG =>此代碼工作沒有問題。 但是,當我試圖加載BMP文件 - 我得到例外。無法從位圖加載BitmapImage(附帶代碼)
異常信息:災難性故障(從HRESULT異常:0x8000FFFF(E_UNEXPECTED))
代碼:
OpenFileDialog dialog = new OpenFileDialog()
{
Multiselect = false,
Filter = "Image(*.png; *.jpg; *.bmp;)| *.png; *.jpg; *.bmp;"
};
if(dialog.ShowDialog() == true)
{
using(System.IO.Stream stream = dialog.File.OpenRead())
{
byte[] img = new byte[ stream.Length ];
stream.Read(img , 0, img .Length);
BitmapImage image = new BitmapImage();
image.SetSource(stream); // Here i have the exception
itemImage.Source = image;
}
}