Link to home
Start Free TrialLog in
Avatar of jpadkins49
jpadkins49

asked on

Convert Binary String to Image

All,

I have a binary string that is an image in stored in a database. I am at a loss on how to convert this binary string to an image and display in an item such as picturebox using Vb.net

Thanks
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

You can either write the bytes to a file or create a stream

IO.File.WriteAllBytes("path to picture file", bytearray)

Then
Picturebox1.Image = Image.FromFile("path of file")
Or

Dim str as New MemoryStream(bytearray)
Picturebox1.Image = Image.FromStream(str)
Avatar of jpadkins49
jpadkins49

ASKER

Here is what I have written in the meantime, but I get an error on the second line stating 'Value of type system.data.linq.binary' cannot be converted to 1-dimensional array.

 
       Any help is greatly appreciated.
Dim Inspections = Context.InspectionSignatures.Single(Function(p) p.ID_PKEY = 36)
        Dim barrImg As Byte() = CType(Inspections.FirmRepSignature, Byte())
        Dim strfn As String = Convert.ToString(DateTime.Now.ToFileTime())
        Dim fs As New FileStream(strfn, FileMode.CreateNew, FileAccess.Write)
        fs.Write(barrImg, 0, barrImg.Length)
        fs.Flush()
        fs.Close()
        PictureBox1.Image = Image.FromFile(strfn)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the help. That fixed the problem. I had a temporary lapse in memory and could not figure it out.
Glad to help :-)