No imaging component suitable to complete this operation was found.
I'm new at WPF, I'm trying to load
image from bytes array with following code:
Code Snippet
// bytes of the image
byte[] photoSource = (byte[])row["Photo"];
// the bitmap object
BitmapImage bitmap = new BitmapImage();
MemoryStream strm = new MemoryStream();
strm.Write(photoSource, 0, photoSource.Length );
// Read the image into the bitmap object
bitmap.BeginInit();
bitmap.StreamSource = strm;
bitmap.EndInit();
// Set the Image with the Bitmap
theImage.Source = bitmap;
and i got this error when EndEdit method of BitmapImage object is called :
NotSupprotedException
No imaging component suitable to complete this operation was found.
[892 byte] By [
MyP3uK] at [2008-1-2]
Are you trying to read images from Northwind database? If so, then there is oddity about them: first 78 bytes need to be skipped.
This is well known problem, and here's one of links that mentions it: http://msdn2.microsoft.com/en-us/library/aa480226.aspx
I could be wrong of course but quite recently I've been assembling quick example on how to use DataTemplates and met exactly the same problem, using practically same code you do, and having same diagnostics.
sfedorov wrote: |
| Are you trying to read images from Northwind database? If so, then there is oddity about them: first 78 bytes need to be skipped. This is well known problem, and here's one of links that mentions it: http://msdn2.microsoft.com/en-us/library/aa480226.aspx I could be wrong of course but quite recently I've been assembling quick example on how to use DataTemplates and met exactly the same problem, using practically same code you do, and having same diagnostics. | |
Yes i was using Northwind database, and i made a workaround that was in this example, but still i have this error, moreover i made another example to load image from FileStream and i have the same error, it's very frustrating for me to start my wpf experience with such strange things in Framework 3.0.
Here is the code:
Code Snippet
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = " Jpeg and Gif files|*.jpeg;*.gif;*.jpg";
bool? result = dialog.ShowDialog();
if ( result == true)
{
string fileName = dialog.FileName;
FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
stream.Seek(0, SeekOrigin.Begin);
BitmapImage img = new BitmapImage();
img.BeginInit();
img.StreamSource = stream;
img.EndInit();
}
No imaging component suitable to complete this operation was found.
ImageSourceConverter has explicit support for OLE-style bitmaps (the kind that Northwind uses). Take a look at:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=885812&SiteID=1
In particular, something like :
ImageSourceConverter isc = new ImageSourceConverter();
BitmapSource bs = (BitmapSource)isc.ConvertFrom(null, null, m_source);
Should work (don't have access to a compiler at the moment, so you'll probably have to tweak this).
Did anyone manage to solve this issue? I have exactly the same problem. I tried to use seek method and ImageSourceConverter but with no result. Here is my code:
MemoryStream ms = new MemoryStream();
BitmapImage bitMap = new BitmapImage();
ms.Write(bmpBytes,0,bmpBytes.Length);
ms.Seek(0, SeekOrigin.Begin);
try
{
bitMap.BeginInit();
bitMap.StreamSource = ms;
bitMap.EndInit();
/*
ImageSourceConverter isc = new ImageSourceConverter();
BitmapSource bm = (BitmapSource)isc.ConvertFrom(bmpBytes);*/
}
catch (Exception ex)
{
s = ex.ToString();
}
I'm not using Northwind database.
You need to set the Offset to 78 and then Seek to 0.
Byte[] photobyte = row["Photo"] as Byte[];
System.IO.MemoryStream stream = new System.IO.MemoryStream(photobyte);
int offset = 78;
stream.Write(photobyte, offset, photobyte.Length - offset);
stream.Seek(0, System.IO.SeekOrigin.Begin);
BitmapImage bitimg = new BitmapImage();
bitimg.BeginInit();
bitimg.StreamSource = stream;
bitimg.EndInit();
Image img = new Image();
img.Source = bitimg;