Create image file (using C # or VB.NET) from Access OLE object column

The OLE Object column contains images, but the type of image (jpg / gif / tiff) is unknown. These images must be retrieved from the database and saved to disk. The app mostly uses VB.NET, but C # examples are welcome too.

thank you Rahul

+1


a source to share


2 answers


Try using System.Drawing.Image.FromStream

to load an image. You can create a stream from a byte array withSystem.IO.MemoryStream foo = new System.IO.MemoryStream(MyByteArray);



Once the image is loaded, you can use whatever GDI stuff you want to keep (for example ImageInstance.Save(FileName);

)

+3


a source


Create a byte array large enough to hold the OLE object:

Dim bArr(Len(<OLE Object Field>)) as Byte

      

Read in the first line of the column of the OLE object and put it in a byte array.



For a GIF file, bytes 0 through 2 will have the ASCII value "GIF". For a JPEG file, bytes 6 through 9 are usually "JFIF". For a PNG file, bytes 1 through 3 will have the ASCII value "PNG".

TIFF is more complex as there are so many different TIFF standards.

Once you have determined the file type, you can use Brian's method to save the file

+3


a source







All Articles