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]
# 1
try doing seek to position 0 before you set the stream source
leed at 2007-9-13 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 2
Thanks for fast reply, but i still have the same error.

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 );
strm.Seek(0, SeekOrigin.Begin);
// Read the image into the bitmap object
bitmap.BeginInit();
bitmap.StreamSource = strm;
bitmap.EndInit();
// Set the Image with the Bitmap
theImage.Source = bitmap;

MyP3uK at 2007-9-13 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 3
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 at 2007-9-13 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 4
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.
MyP3uK at 2007-9-13 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 5

Code Snippet

byte[] m_source = File.ReadAllBytes(path);

MemoryStream stream = new MemoryStream(Source);

BitmapImage m_Image = new BitmapImage();

m_Image.BeginInit();

//m_Image.UriSource = new Uri(m_origPath); - This way in inefficient

m_Image.DecodePixelWidth = 500;

m_Image.StreamSource = stream;

m_Image.EndInit();

m_Image.Freeze();

TamirKhason at 2007-9-13 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 6

I've been blogging about things like that recently, check out:

http://www.wiredprairie.us/journal/2007/04/extracting_thumbnails_from_a_j.html

I dive into a couple of cases that I've run into recently when dealing with dynamically loaded Images, especially when related to BitmapMetadata.

WPCoder at 2007-9-13 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 7

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).

AnthonyHodsdon-MSFT at 2007-9-13 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 8
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.

Lukasz_S at 2007-9-13 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 9
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;
Jay Lin at 2008-2-3 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified