• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1118
  • Last Modified:

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
0
jpadkins49
Asked:
jpadkins49
  • 4
  • 2
1 Solution
 
CodeCruiserCommented:
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")
0
 
CodeCruiserCommented:
Or

Dim str as New MemoryStream(bytearray)
Picturebox1.Image = Image.FromStream(str)
0
 
jpadkins49Author Commented:
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

0
Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

 
CodeCruiserCommented:
If this is the binary

Inspections.FirmRepSignature

then try

Inspections.FirmRepSignature.ToArray
0
 
jpadkins49Author Commented:
Thanks for the help. That fixed the problem. I had a temporary lapse in memory and could not figure it out.
0
 
CodeCruiserCommented:
Glad to help :-)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now