471,666 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,666 software developers and data experts.

Get Bytes from Bitmap Object

I have a Bitmap Object and I need to return it as array of bytes is it possible
Nov 17 '05 #1
2 5922

"Raed Sawalha" <Ra*********@discussions.microsoft.com> wrote in message
news:1E**********************************@microsof t.com...
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

Nov 17 '05 #2
You can use the Lock method on the bitmap.

"Raed Sawalha" <Ra*********@discussions.microsoft.com> schrieb im
Newsbeitrag news:1E**********************************@microsof t.com...
I have a Bitmap Object and I need to return it as array of bytes is it

possible
Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jeroen Ceuppens | last post: by
1 post views Thread by News VS.NET \( MS ILM \) | last post: by
8 posts views Thread by Nathan Sokalski | last post: by
2 posts views Thread by Ron M. Newman | last post: by
1 post views Thread by =?Utf-8?B?UmljYXJkbyBGdXJ0YWRv?= | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
1 post views Thread by hala adnan | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.