none
No imaging component suitable to complete this operation was found.

    Question

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


    Friday, April 13, 2007 6:02 PM

All replies

  • try doing seek to position 0  before you set the stream source
    Friday, April 13, 2007 6:08 PM
  • 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;

    Friday, April 13, 2007 6:27 PM
  • 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.


    Friday, April 13, 2007 9:13 PM
  •  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.
    Saturday, April 14, 2007 7:24 AM
  • 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();

     

    Saturday, April 14, 2007 2:21 PM
  • 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.

     

     

    Saturday, April 14, 2007 7:59 PM
  • 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).

    Monday, April 16, 2007 11:17 PM
  • 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.
    Thursday, May 03, 2007 12:46 AM
  • It seems this kind of error "No imaging component suitable to complete this operation was found." has something to do with a corrupt byte array.

    I'm using enterprise library for saving and reading image from disk.

    for reading:

    byte[] bits = myclass.Photo;
    using (MemoryStream stream = new MemoryStream(bits))
    {
        image1.Source = BitmapFrame.Create(stream, BitmapCreateOptions.IgnoreImageCache, BitmapCacheOption.OnLoad);
    }
    and for saving:
    var bi = new BitmapImage();
    bi.BeginInit();
    bi.CacheOption = BitmapCacheOption.OnLoad;
    bi.UriSource = new Uri(p, UriKind.RelativeOrAbsolute);
    bi.EndInit();
    
    byte[] bits = null;
    FileInfo fiImage = new FileInfo(bi.UriSource.AbsolutePath);
    long tam = fiImage.Length;
    FileStream fs = new FileStream(bi.UriSource.AbsolutePath, FileMode.Open, FileAccess.Read, FileShare.Read);
    bits = new byte[Convert.ToInt32(tam)];
    int iBytesRead = fs.Read(bits, 0, Convert.ToInt32(tam));
    fs.Close();
    
    //bits is what you are going to pass as binary type parameter in your procedure, which expects a sql server "image type"

    a little clutter I know, but I have a schedule and it's saving me time now!
    Friday, November 06, 2009 11:07 PM