Reading access ole fields

  • Thread starter Thread starter Marco Castro
  • Start date Start date
M

Marco Castro

Along time ago I created an access database where I used the ole field type
to store images. If I look at the table data it has the work Picture in its
field. The image in that field displays properly if I display it from
inside of access but I can't figure out how to convert what's in there to
anything useful outside of access.

Is there some way to read what's in there from a .net application? I would
be content with just being able to display the picture in an application but
really I would like a way to extract them from there and converting them to
a real picture format. Can someone help me out with this dilemma please.
Thanks.
 
Hi,

Access stores the images in binary format. Here is a function that
converts the binary data into a bitmap. I put a parameter for offset
because the northwind database has an offset of 78.

Private Function ConvertToBitmap(ByVal data() As Byte, ByVal offset As
Integer) As Bitmap

Dim ms As New System.IO.MemoryStream

Dim bm As Bitmap

ms = New MemoryStream

ms.Write(data, offset, data.Length - offset)

bm = New Bitmap(ms)

Return bm

End Function



Ken
 
I tried your code but I keep on getting the error "Invalid parameter used."
at the line bm = New Bitmap(ms). Any idea why that would be? Thanks.
 
Well I figured out what the problem was. It turns out that the offset has
to be set after the byte array is read. So if anyone else was interested
this is how the code looks for me now. And my offset ended up being 74.
Thanks for the help again Ken.

Private Function ConvertToBitmap(ByVal data() As Byte, ByVal offset As
Integer) As Bitmap

Dim ms As New System.IO.MemoryStream

ms.Write(data, 0, data.Length)

ms.Position = offset

Return New Bitmap(ms)

End Function
 
Umm, I just realized that you original code would also work and be more
efficient then mine if you simply add the ms.position to it. Well ... me =
dumb.
 
Back
Top