By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,637 Members | 1,945 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,637 IT Pros & Developers. It's quick & easy.

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

P: n/a
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 ?

Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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!
Nov 17 '05 #2

P: n/a
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" <na***@dao2com.com> wrote in message
news:u7**************@TK2MSFTNGP12.phx.gbl...
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!

Nov 17 '05 #3

P: n/a
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!
Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.