Convert a bitmap to byte array....and back

jayy66

Newcomer
Joined
Aug 24, 2006
Messages
14
Location
texas
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 to display what i had previously saved.
I found something like this on the internet:
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??
 
I'm slightly confused, the code you posted doesn't seem to have alot todo with the situation you described.
Visual Basic:
BackGroundImage = New Bitmap(ImageFileName)
Basically this line of code is designed to load a Bitmap file into your application. The ImageFileName field would contain the path of a Bitmap for example "c:\myImage.bmp". If you pass this overload a path to a valid Image I see no reason why it wouldn't work correctly. What you described however was creating a bitmap object from a Byte array, is this what you want todo? Because it isn't quite as simple as this. It's a while since I've loaded a bitmap from a byte array, but if you can clarify this is what you wish todo, I can try and rustle up an example.
[edit]Just to send you in the right direction, I believe the best approach is to read the byte array into a stream as the Bitmap class has a constuctor overload that supports streams.[/edit]
 
Sorry for the confusion but you're right that does work. My problem was the path wasn't correctly stated.

Thanks.


and by the way, i was looking for an alternative way to display the bitmap since i couldn't get:
BackGroundImage = New Bitmap(ImageFileName)
to work correctly and i had been tyring to find my problem for two days now.
its funny how the smallest things are always overlooked.

thanks again.
 
Back
Top