Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert byte array to bitmap

Status
Not open for further replies.

jayy66

Programmer
Joined
Aug 21, 2006
Messages
56
Location
US
Well, i figured out how to convert a bitmap into a byte array. I use this to save signatures from a pocket pc emulator. How would i convert the byte array back to a bitmap??

I tried using the code below:
Code:
Dim BackGroundImage As Bitmap
Dim ImageFileName As String = "path"

BackGroundImage = New Bitmap(ImageFileName)
GraphicsHandle = Graphics.FromImage(BackGroundImage)
but that doesn't seem to be working. i get an "Exception"
error on BackGroundImage = New bitmap(imagefilename)

Any thoughts??
 
Here's what I use to transmit it through a socket:

Code:
Public Function Bmp2Byte(ByVal Data As System.Drawing.Bitmap) As Byte()
        Dim str As New System.IO.MemoryStream
        Data.Save(str, System.Drawing.Imaging.ImageFormat.Bmp)
        Dim sendBytes(str.Length - 1) As Byte
        str.Position = 0
        str.Read(sendBytes, 0, str.Length)
        str.Close()
        Return sendBytes
End Function
 
Oh and about the actuall exception you're getting try this instead of you assignment:

Code:
BackGroundImage = Bitmap.FromFile(ImageFileName)

Hope those help you out.
 
Thanks.

This line
Code:
BackGroundImage = Bitmap.FromFile(ImageFileName)
worked liked a charm.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top