Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to display an image from a OLE Object field of an Access database ?

Reply
Thread Tools

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

 
 
Sandi
Guest
Posts: n/a
 
      11-05-2003
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 ?



 
Reply With Quote
 
 
 
 
Natty Gur
Guest
Posts: n/a
 
      11-05-2003
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!
 
Reply With Quote
 
 
 
 
Sandi
Guest
Posts: n/a
 
      11-06-2003
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 (7 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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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!



 
Reply With Quote
 
Natty Gur
Guest
Posts: n/a
 
      11-06-2003
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!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Display Access Database OLE Object =?Utf-8?B?U2VvayBCZWU=?= ASP .Net 1 01-25-2006 12:10 PM
Displaying OLE Object Field from MS Access M P ASP General 0 02-12-2004 08:12 AM
Win32::OLE adding shape to OLE Object (xlsheet) in PPT Lance Hoffmeyer Perl Misc 0 11-17-2003 07:44 PM
Read OLE Object field to Image ? Sandi ASP .Net 3 11-06-2003 02:47 PM
Read OLE Object field to Image ? Sandi ASP .Net 0 11-05-2003 02:11 PM



Advertisments