Convert Bitmap to Byte and Byte to Bitmap

E

Eka Gautama

Hi all,

I need help for a sample code to convert a bitmap to byte as well from byte
to bitmap..

Thanks for the help

Eka
 
M

Mattias Sjögren

I need help for a sample code to convert a bitmap to byte as well from byte
to bitmap..

I doubt you'll be able to squeeze an entire bitmap into a single byte
- did you mean a byte array?

There are many ways to do that, depending on the format you want it
in. The easiest way is probably to save the bitmap to a stream and
then read it's content. Something like

MemoryStream ms = new MemoryStream();
yourBitmap.Save( ms, ImageFormat.Bmp );
byte[] bitmapData = ms.ToArray();



Mattias
 
E

Eka Gautama

I doubt you'll be able to squeeze an entire bitmap into a single byte
- did you mean a byte array?

Yep.. a byte of array...
There are many ways to do that, depending on the format you want it
in. The easiest way is probably to save the bitmap to a stream and
then read it's content. Something like

MemoryStream ms = new MemoryStream();
yourBitmap.Save( ms, ImageFormat.Bmp );
byte[] bitmapData = ms.ToArray();

Cool.. I'll try this... Thanks for your help...

Eka
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top