Read OLE Object field to Image ?

A

Andre

I have an Access database (images.mdb) that has 2 columns: one is the id of
the picture (an integer) and one (column named picture) is a field of type
OLE Object which contains an image stored as on OLE Object (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# and use Visual Studio .NET, 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 ?
 
T

Tim Ferguson

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# and use Visual Studio .NET, 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.

You are probably better armed by starting with C++ than the rest of us, as
VBA does not expose any easy way of interacting with an OLE object. You
will find that it is part of the FileStream family, and you certainly can
get at the original data behind all the presentation formats. I read a web
page about it long ago, but most of the details went over my head.

Storing pictures in an OLE field is a pretty bad idea though; not just
because of the access, but because the huge overhead starts to head toward
the 2 GB limit after a few records. Most people suggest keeping the files
on a HDD and storing the path/filename in the database.

Best of luck!

Tim F
 
S

Sandi

I know this is not the best design for my database.
But I did not create the database :(
I just have to read it...
 
E

Exponent

Once you can extract an image file from the field you may as well store again it as raw binary instead
of using OLE Embedding. Then, the code to display the image in your web page becomes trivial, you avoid
the (potentially huge) storage and performance overhead, and the extraction and interoperability issues
and other possible drawbacks to OLE Embedding. You might as well do this once as an offline/batch process
for your existing images, rather than each time an image is viewed from the database.

The actual extraction from OLE Embedded objects, however, can be difficult - particularly so if there are
multiple file types and/or different OLE servers used to store them.
It is usually possible to extract images using a Metafile approach (there are examples at www.lebans.com)
but this does not consider the original format. Generating jpegs, for example, will require an additional
(lossy) compression cycle, and metadata (e.g. EXIF info) would be lost. Also, there would be no way to
identify which images should be saved as jpeg, gif etc other without some manual processing, so this may
depend on your specific requirements e.g. number of images, suitability of different image/compression
formats (e.g. for photos vs. documents/computer artwork etc).
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top