How does Bitmap.Save(Stream, ImageFormat) format the data?

Posted by Matt Jacobsen on Stack Overflow See other posts from Stack Overflow or by Matt Jacobsen
Published on 2010-04-07T10:44:50Z Indexed on 2010/04/07 10:53 UTC
Read the original article Hit count: 313

Filed under:
|
|
|

I have a non transparent, colour bitmap with length 2480 and width 3507.

Using Bitmap.GetPixel(int x, int y) I am able to get the colour information of each pixel in the bitmap.

If I squirt the bitmap into a byte[]:

MemoryStream ms = new MemoryStream();
bmp.Save(ms, ImageFormat.Bmp);
ms.Position = 0;
byte[] bytes = ms.ToArray();

then I'd expect to have the same information, i.e. I can go to bytes[1000] and read the colour information for that pixel.

It turns out that my array of bytes is larger than I anticipated. I thought I'd get an array with 2480 x 3507 = 8697360 elements. Instead I get an array with 8698438 elements - some sort of header I presume.

In what format the bytes in my array stored? Is there a header 1078 bytes long followed by Alpha, Red, Green, Blue values for every byte element, or something else?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about bitmap