none
Converting Ole Object(jpeg) into System.Drawing.Bitmap Problem RRS feed

  • Question

  • How can I convert the OLE Object(byte array) from db1(my Access database) into a c# Bitmap object?
    The Ole Object is a jpeg.

    Source Code:
    byte[] pictureData = <<...Ole Object...>>
    int offsetValue = 78;
    Stream stream = new MemoryStream();
    stream.Write(pictureData, offsetValue, pictureData.Length - offsetValue);
    Bitmap bitmap = new Bitmap(stream);


    Notes:
         I have tried an offset value of 0-pictureData.Length.
         I get an ArgumentException with message "Parameter is not valid." when instantiating bitmap object.

    Thursday, March 13, 2008 10:31 PM

Answers

  • Have you tried creating the Bitmap from an Image like below?  Just a thought.  The only other thing that I can think of is maybe you are not reading the byte array properly.  Just some thoughts.

     

    Bitmap bitmap = (Bitmap)Image.FromStream(stream);

     

    Friday, March 14, 2008 12:42 AM

All replies

  • Have you tried creating the Bitmap from an Image like below?  Just a thought.  The only other thing that I can think of is maybe you are not reading the byte array properly.  Just some thoughts.

     

    Bitmap bitmap = (Bitmap)Image.FromStream(stream);

     

    Friday, March 14, 2008 12:42 AM
  • Thanks for the suggestions.

    I have tried your code but did not work:

         Bitmap bitmap = (Bitmap)Image.FromStream(stream);

     

    I'm starting to consider that your idea that the byte array might not be properly read.

    But, i have no way to verify this idea.

    Friday, March 14, 2008 4:21 AM