Get Bytes from Bitmap Object

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a Bitmap Object and I need to return it as array of bytes is it possible
 
Raed Sawalha said:
I have a Bitmap Object and I need to return it as array of bytes is it
possible

private static byte[] GetBitmapBytes(Bitmap Bitmap)
{
MemoryStream memStream = new MemoryStream();
byte[] bytes;

try {
// Save the bitmap to the MemoryStream.
Bitmap.Save(memStream, Bitmap.RawFormat);

// Create the byte array.
bytes = new byte[memStream.Length];

// Rewind.
memStream.Seek(0, SeekOrigin.Begin);

// Read the MemoryStream to get the bitmap's bytes.
memStream.Read(bytes, 0, bytes.Length);

// Return the byte array.
return bytes;
} finally {
// Cleanup.
memStream.Close();
}
}

HTH :)

Mythran
 

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

Back
Top