Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving gif from MS access database 1

Status
Not open for further replies.

DonnaB

Programmer
Apr 23, 2001
34
0
0
AU
hi,

i have a gif image stored in an access database as an ole object. i've seen a lot about retrieving this using getBinaryStream or getBytes, but it all is using an oracle database, with longraw data.

does anyone know if this should also work with ole objects?

i am reading in the image and writing it in chunks to a file, but they cannot be opened and are nearly twice the size of what they should be.

is there a good resource anyone knows of that i can look at?

thanks, donna.
[bigcheeks]
 
I don't know a lot about OLE, but as I understood it, it is a Microsoft framework for containing information that can be accessible by an OLE container application - like an application that implements COM /COM+ objects, or the MFC's. I don't know that an application written in java alone can encapsulate the architecture that is required to display OLE objects.

So while the gif image is wrapped by an OLE object and placed inside Access, I think it has to be accessed by an application that understands how to extract OLE information.

Sorry ! That wasn't much help at all was it ...
 
hmm, so does that mean there is no way of retrieving a gif from an access database using java?!

it can only be stored as an ole object can't it?
 
yay! i got it to work.

Using and OLE object data field in MS Access will cause all kinds of problems, because Access adds extra info to the file header, which stuffs up the image. (This info is to point to the Object Linked App to handle the saved data)

so you'll need to remove the bytes of data that are used for the header and footer.

here's the code if anyone needs it in the future...

byte[] imageAndHeaderBytes = (byte[])resultSet.getObject("elementImage");
FileOutputStream fos = new FileOutputStream(name + ".gif");

// remove header and footer bytes
int headerOffset = 153 + 3*(name.length());
int footerOffset = 280 + name.length();
byte[] imageBytes = new byte[imageAndHeaderBytes.length - headerOffset - footerOffset];
for (int i=headerOffset; i<imageAndHeaderBytes.length - footerOffset; i++)
imageBytes[i-headerOffset] = imageAndHeaderBytes;

fos.write( imageBytes ) ;
fos.close();


name is just the name of the file that was originally put into the database. the code above can also be used for bmp images. just change the name of the fos created and the headerOffset and footerOffset. to determine the correct offsets comment out the second block of the code and change the second last line to:
fos.write(imageAndHeaderBytes);

open the image file created with this code in wordpad and also open the original image file in word pad and compare them to determine how many bytes need to be discarded. (for me the header was around 75 + name.length, didn't get around to doing the footer)

hope this helps someone, one day...
donna.

[ponytails]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top