Connecting Tech Pros Worldwide Forums | Help | Site Map

Reading access ole fields

Marco Castro
Guest
 
Posts: n/a
#1: Nov 20 '05
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.



Ken Tucker [MVP]
Guest
 
Posts: n/a
#2: Nov 20 '05

re: Reading access ole fields


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
-------------
"Marco Castro" <marco_dontspamme@benlan.com> wrote in message
news:uSaC8SLIEHA.3476@TK2MSFTNGP11.phx.gbl...[color=blue]
> Along time ago I created an access database where I used the ole field[/color]
type[color=blue]
> to store images. If I look at the table data it has the work Picture in[/color]
its[color=blue]
> 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[/color]
would[color=blue]
> be content with just being able to display the picture in an application[/color]
but[color=blue]
> really I would like a way to extract them from there and converting them[/color]
to[color=blue]
> a real picture format. Can someone help me out with this dilemma please.
> Thanks.
>
>[/color]


Marco Castro
Guest
 
Posts: n/a
#3: Nov 20 '05

re: Reading access ole fields


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.


"Ken Tucker [MVP]" <vb2ae@bellsouth.net> wrote in message
news:%237EbsXOIEHA.3772@TK2MSFTNGP12.phx.gbl...[color=blue]
> Hi,
>
> Access stores the images in binary format. Here is a function[/color]
that[color=blue]
> 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
> -------------
> "Marco Castro" <marco_dontspamme@benlan.com> wrote in message
> news:uSaC8SLIEHA.3476@TK2MSFTNGP11.phx.gbl...[color=green]
> > Along time ago I created an access database where I used the ole field[/color]
> type[color=green]
> > to store images. If I look at the table data it has the work Picture in[/color]
> its[color=green]
> > 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[/color][/color]
to[color=blue][color=green]
> > anything useful outside of access.
> >
> > Is there some way to read what's in there from a .net application? I[/color]
> would[color=green]
> > be content with just being able to display the picture in an application[/color]
> but[color=green]
> > really I would like a way to extract them from there and converting them[/color]
> to[color=green]
> > a real picture format. Can someone help me out with this dilemma[/color][/color]
please.[color=blue][color=green]
> > Thanks.
> >
> >[/color]
>
>[/color]


Ken Tucker [MVP]
Guest
 
Posts: n/a
#4: Nov 20 '05

re: Reading access ole fields


Hi,

Try changing the offset. It might be 0 or it might be 78. play
around

Ken
--------------
"Marco Castro" <marco_dontspamme@benlan.com> wrote in message
news:%23bJJWNVIEHA.2948@TK2MSFTNGP11.phx.gbl...[color=blue]
> I tried your code but I keep on getting the error "Invalid parameter[/color]
used."[color=blue]
> at the line bm = New Bitmap(ms). Any idea why that would be? Thanks.
>
>
> "Ken Tucker [MVP]" <vb2ae@bellsouth.net> wrote in message
> news:%237EbsXOIEHA.3772@TK2MSFTNGP12.phx.gbl...[color=green]
> > Hi,
> >
> > Access stores the images in binary format. Here is a function[/color]
> that[color=green]
> > 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
> > -------------
> > "Marco Castro" <marco_dontspamme@benlan.com> wrote in message
> > news:uSaC8SLIEHA.3476@TK2MSFTNGP11.phx.gbl...[color=darkred]
> > > Along time ago I created an access database where I used the ole field[/color]
> > type[color=darkred]
> > > to store images. If I look at the table data it has the work Picture[/color][/color][/color]
in[color=blue][color=green]
> > its[color=darkred]
> > > 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[/color][/color]
> to[color=green][color=darkred]
> > > anything useful outside of access.
> > >
> > > Is there some way to read what's in there from a .net application? I[/color]
> > would[color=darkred]
> > > be content with just being able to display the picture in an[/color][/color][/color]
application[color=blue][color=green]
> > but[color=darkred]
> > > really I would like a way to extract them from there and converting[/color][/color][/color]
them[color=blue][color=green]
> > to[color=darkred]
> > > a real picture format. Can someone help me out with this dilemma[/color][/color]
> please.[color=green][color=darkred]
> > > Thanks.
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Marco Castro
Guest
 
Posts: n/a
#5: Nov 20 '05

re: Reading access ole fields


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



"Ken Tucker [MVP]" <vb2ae@bellsouth.net> wrote in message
news:ezmPvUaIEHA.3440@TK2MSFTNGP09.phx.gbl...[color=blue]
> Hi,
>
> Try changing the offset. It might be 0 or it might be 78. play
> around
>
> Ken
> --------------
> "Marco Castro" <marco_dontspamme@benlan.com> wrote in message
> news:%23bJJWNVIEHA.2948@TK2MSFTNGP11.phx.gbl...[color=green]
> > I tried your code but I keep on getting the error "Invalid parameter[/color]
> used."[color=green]
> > at the line bm = New Bitmap(ms). Any idea why that would be? Thanks.
> >
> >
> > "Ken Tucker [MVP]" <vb2ae@bellsouth.net> wrote in message
> > news:%237EbsXOIEHA.3772@TK2MSFTNGP12.phx.gbl...[color=darkred]
> > > Hi,
> > >
> > > Access stores the images in binary format. Here is a function[/color]
> > that[color=darkred]
> > > 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
> > > -------------
> > > "Marco Castro" <marco_dontspamme@benlan.com> wrote in message
> > > news:uSaC8SLIEHA.3476@TK2MSFTNGP11.phx.gbl...
> > > > Along time ago I created an access database where I used the ole[/color][/color][/color]
field[color=blue][color=green][color=darkred]
> > > type
> > > > to store images. If I look at the table data it has the work[/color][/color][/color]
Picture[color=blue]
> in[color=green][color=darkred]
> > > its
> > > > field. The image in that field displays properly if I display it[/color][/color][/color]
from[color=blue][color=green][color=darkred]
> > > > inside of access but I can't figure out how to convert what's in[/color][/color][/color]
there[color=blue][color=green]
> > to[color=darkred]
> > > > anything useful outside of access.
> > > >
> > > > Is there some way to read what's in there from a .net application?[/color][/color][/color]
I[color=blue][color=green][color=darkred]
> > > would
> > > > be content with just being able to display the picture in an[/color][/color]
> application[color=green][color=darkred]
> > > but
> > > > really I would like a way to extract them from there and converting[/color][/color]
> them[color=green][color=darkred]
> > > to
> > > > a real picture format. Can someone help me out with this dilemma[/color]
> > please.[color=darkred]
> > > > Thanks.
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Marco Castro
Guest
 
Posts: n/a
#6: Nov 20 '05

re: Reading access ole fields


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.

"Marco Castro" <marco_dontspamme@benlan.com> wrote in message
news:ONYtx28IEHA.3720@tk2msftngp13.phx.gbl...[color=blue]
> 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
>
>
>
> "Ken Tucker [MVP]" <vb2ae@bellsouth.net> wrote in message
> news:ezmPvUaIEHA.3440@TK2MSFTNGP09.phx.gbl...[color=green]
> > Hi,
> >
> > Try changing the offset. It might be 0 or it might be 78. play
> > around
> >
> > Ken
> > --------------
> > "Marco Castro" <marco_dontspamme@benlan.com> wrote in message
> > news:%23bJJWNVIEHA.2948@TK2MSFTNGP11.phx.gbl...[color=darkred]
> > > I tried your code but I keep on getting the error "Invalid parameter[/color]
> > used."[color=darkred]
> > > at the line bm = New Bitmap(ms). Any idea why that would be? Thanks.
> > >
> > >
> > > "Ken Tucker [MVP]" <vb2ae@bellsouth.net> wrote in message
> > > news:%237EbsXOIEHA.3772@TK2MSFTNGP12.phx.gbl...
> > > > Hi,
> > > >
> > > > Access stores the images in binary format. Here is a[/color][/color][/color]
function[color=blue][color=green][color=darkred]
> > > that
> > > > converts the binary data into a bitmap. I put a parameter for[/color][/color][/color]
offset[color=blue][color=green][color=darkred]
> > > > because the northwind database has an offset of 78.
> > > >
> > > > Private Function ConvertToBitmap(ByVal data() As Byte, ByVal offset[/color][/color][/color]
As[color=blue][color=green][color=darkred]
> > > > 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
> > > > -------------
> > > > "Marco Castro" <marco_dontspamme@benlan.com> wrote in message
> > > > news:uSaC8SLIEHA.3476@TK2MSFTNGP11.phx.gbl...
> > > > > Along time ago I created an access database where I used the ole[/color][/color]
> field[color=green][color=darkred]
> > > > type
> > > > > to store images. If I look at the table data it has the work[/color][/color]
> Picture[color=green]
> > in[color=darkred]
> > > > its
> > > > > field. The image in that field displays properly if I display it[/color][/color]
> from[color=green][color=darkred]
> > > > > inside of access but I can't figure out how to convert what's in[/color][/color]
> there[color=green][color=darkred]
> > > to
> > > > > anything useful outside of access.
> > > > >
> > > > > Is there some way to read what's in there from a .net application?[/color][/color]
> I[color=green][color=darkred]
> > > > would
> > > > > be content with just being able to display the picture in an[/color]
> > application[color=darkred]
> > > > but
> > > > > really I would like a way to extract them from there and[/color][/color][/color]
converting[color=blue][color=green]
> > them[color=darkred]
> > > > to
> > > > > a real picture format. Can someone help me out with this dilemma
> > > please.
> > > > > Thanks.
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Closed Thread


Similar Visual Basic .NET bytes