How to display an image from a OLE Object field of an Access database ?

Discussion in 'ASP .Net' started by Sandi, Nov 5, 2003.

  1. Sandi

    Sandi Guest

    I have a simple problem:
    I have an Access database (images.mdb) that has 2 columns: one is the id if
    the picture (an integer) and one (column named picture) is a field of type
    OLE Object which contains an image (it can store jpg, bmp, gif, but I don't
    know what image is stored inside).
    I want to retrieve the picture stored in the database and identified by a
    given id and display it in a web page (.aspx).
    I write in Visual C#, but it does not matter, VB answers are just as
    wellcome.
    My problem is that this OLE Object field does not contain just the raw array
    of bytes that form the image. So I can not just read the array of bytes and
    output it to the browser.
    no, it contains some extra information about the type of the file stored
    (which would be good to know so I can know what kind of image it is). but I
    don't know how to get this information.
    I also don't know how to separate this information from the actual image.
    Does anyone know how to solve this ?
    Sandi, Nov 5, 2003
    #1
    1. Advertising

  2. Sandi

    Natty Gur Guest

    Hi,

    This code works for me. I think i took it from Visual studio magazine.

    int offset = 78;

    cn.Open();
    byte [] img = (byte[])
    cmd.ExecuteScalar();
    ms.Write(img, offset,
    img.Length-offset);
    cn.Close();

    Bitmap bmp = null;
    bmp = new Bitmap(ms);
    Response.ContentType = "image/gif";
    bmp.Save(Response.OutputStream,
    ImageFormat.Gif);
    ms.Close();


    Natty Gur[MVP]
    Phone Numbers:
    Office: +972-(0)9-7740261
    Fax: +972-(0)9-7740261
    Mobile: +972-(0)58-888377


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur, Nov 5, 2003
    #2
    1. Advertising

  3. Sandi

    Sandi Guest

    THANKS a LOT !!!!!!!!!

    This is the best answer anyone gave me, but still...
    If a bitmap is stored in the OLE Object, than indeed this offset (78) works,
    because the header that Access adds to the image is indeed 78 bytes long.
    However, if a .gif or a .jpg or a .png is stored, than this offset no longer
    works because the header has a different length.
    My problem is that I do not know what type of image I am retrieving. It can
    be a .bmp but it can just as well be a .gif or a .jpg
    So do you have any ideea what should be the offset for theese types of
    images (.gif, .jpg) ???

    And by the way, I did not design the database like this :(
    I just have to read it...


    "Natty Gur" <> wrote in message
    news:...
    > Hi,
    >
    > This code works for me. I think i took it from Visual studio magazine.
    >
    > int offset = 78;
    >
    > cn.Open();
    > byte [] img = (byte[])
    > cmd.ExecuteScalar();
    > ms.Write(img, offset,
    > img.Length-offset);
    > cn.Close();
    >
    > Bitmap bmp = null;
    > bmp = new Bitmap(ms);
    > Response.ContentType = "image/gif";
    > bmp.Save(Response.OutputStream,
    > ImageFormat.Gif);
    > ms.Close();
    >
    >
    > Natty Gur[MVP]
    > Phone Numbers:
    > Office: +972-(0)9-7740261
    > Fax: +972-(0)9-7740261
    > Mobile: +972-(0)58-888377
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    Sandi, Nov 6, 2003
    #3
  4. Sandi

    Natty Gur Guest

    Hi,

    Sorry don’t have any clue.

    Try to write a program that increases the off set until you will get
    viewable image. That the best I can offer?

    Natty Gur[MVP]
    Phone Numbers:
    Office: +972-(0)9-7740261
    Fax: +972-(0)9-7740261
    Mobile: +972-(0)58-888377


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur, Nov 6, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sandi

    Read OLE Object field to Image ?

    Sandi, Nov 5, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    571
    Sandi
    Nov 5, 2003
  2. Sandi

    Read OLE Object field to Image ?

    Sandi, Nov 5, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    10,357
    Kevin Spencer
    Nov 6, 2003
  3. =?Utf-8?B?U2VvayBCZWU=?=

    Display Access Database OLE Object

    =?Utf-8?B?U2VvayBCZWU=?=, Jan 25, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    1,014
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tp?=
    Jan 25, 2006
  4. M P
    Replies:
    0
    Views:
    112
  5. Lance Hoffmeyer
    Replies:
    0
    Views:
    228
    Lance Hoffmeyer
    Nov 17, 2003
Loading...

Share This Page