How does Bitmap.Save(Stream, ImageFormat) format the data?
- by Matt Jacobsen
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?