开发者

Can't load BitmapImage from bitmap ( code attached )

I trying to load BitmapImage from bmp file. When i load png or jpg => this code work with no problem. But when i trying to load bmp file - i开发者_StackOverflow get exception.

The exception information: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

The code:

        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;
            }
        }


Silverlight does not support the Windows bitmap (BMP) format. Only JPG and PNG. The use of the name BitmapImage refers to the generic bitmap term rather than the specific file format.

JPG is the best format for photographic images and PNG the best format for other images as it has half-decent alpha channel support (unlike bitmaps and GIFs).

To load bitmap files (assuming you really need to) there are libraries about.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜