Groups | Blog | Home
all groups > vb.net data > september 2005 >

vb.net data : How to make a bitmap image from a string


Wilbur Slice
9/20/2005 3:12:51 PM
My application does and HTTP transaction with a web service provider
that returns an XML document to me that includes a big bag 'o' bytes
that is supposed to be a bitmap (a GIF or a PNG, my choice) of a label
to print.

So when I parse this XML doc, I have a string with a bunch of bytes -
how do I translate this into an image? Any ideas?

Ultimately, I'd like to write it to a GIF or PNG file.


TIA
Ken Tucker [MVP]
9/20/2005 7:59:14 PM
Hi,

Here is some sample code I used to get the image from the nortwind
databases category table when I stored it in an xml file. The northwind
database has an offset of 78 you might not have one.

Dim strPicture As String = dr.Item("Picture")
Dim arData() As Byte = Convert.FromBase64String(strPicture)

ms.Write(arData, 78, arData.Length - 78)
'ms.Write(arData, 0, arData.Length) Use for no offset
Try
bm = New Bitmap(ms)
picBlob.Image = bm
Catch ex As Exception

End Try


Ken
--------------------------
[quoted text, click to view]

Wilbur Slice
9/21/2005 9:18:59 AM
On Tue, 20 Sep 2005 19:59:14 -0400, "Ken Tucker [MVP]"
[quoted text, click to view]


Thanks - that hit the spot. The part I was missing was the
Convert.FromBase64String(strPicture) - I didn't know how to get it
from the string into the array of Bytes. I tried that, and it worked
like a charm.

Thanks again



[quoted text, click to view]
AddThis Social Bookmark Button