Bitmap File Format
To describe details of bitmap file structure, this site consists the following image for every time.

This image has following properties.
width 1024 [pix]
height 1024 [pix]
bit depth 24 [bit]
Bitmap File Structure
The first 54 bytes area highlighted with yellow background is a header of bitmap file. The left shown data is what the binary file looks like and the right shown data is a decoded version of binary file as ASCII characters set. Yellow background represents the separation of each field.
42 4d 36 00 30 00 00 00 00 00 36 00 00 00 28 00
00 00 00 04 00 00 00 04 00 00 01 00 18 00 00 00
00 00 00 00 30 00 74 12 00 00 74 12 00 00 00 00
00 00 00 00 00 00 39 42 44 38 42 44 3b 46 4a 3e
BM6.0.....6...(.
................
....0.t...t.....
......9BD8BD;FJ>
Here's a table explaining each field meaning. Bitmap file format adopts Little Endian format.
Property | Offset [Byte] | Size [Byte] | Value | Meaning | |
---|---|---|---|---|---|
File Header |
bfType | 0 | 2 | 0x 42 4d | Always "BM" in ASCII code |
bfSize | 2 | 4 | 0x 00 30 00 36 | The size of its entire file. Here's 0x300036 [byte], which is 3,145,782 [byte] | |
bfReserved1 | 6 | 2 | 0x 00 00 | Always 0 for future extension | |
bfReserved2 | 8 | 2 | 0x 00 00 | Always 0 for future extension | |
bfOffBits | 10 | 4 | 0x 00 00 00 36 | The size of entire bitmap file header. Almost always 0x36 [byte], which is 54 [byte] | |
Info Header |
biSize | 14 | 4 | 0x 00 00 00 28 | The size of its information header. Almost always 0x28 [byte], which is 40 [byte] |
biWidth | 18 | 4 | 0x 00 00 04 00 | Width of image. Here's 0x400 [pix], which is 1024 [pix] | |
biHeight | 22 | 4 | 0x 00 00 04 00 | Hight of image. Here's 0x4000 [pix], which is 1024 [pix] | |
biPlanes | 26 | 2 | 0x 00 01 | Always 0x01 | |
biBitCount | 28 | 2 | 0x 00 18 | Bit depth for expression of a single pixcel. 0x18 [bit] ( = 24 [bit]) means that a pixcel can be represented as value ranging from 0 to \(2^{24}\) - 1 | |
biCompression | 30 | 4 | 0x 00 00 00 00 | When this value is 0x00, then no compression is applied | |
biSizeImage | 34 | 4 | 0x 00 30 00 00 | This value is total size of data region. Here's 0x30000 [byte], which is 3,145,728 [byte] | |
biXPixPerMeter | 38 | 4 | 0x 00 00 12 74 | The value represents a horizontal resolution with unit of pixel per meter. Here's 0x1274 [ppm], which is 4724 [ppm]. This field can be 0. | |
biYPixPerMeter | 42 | 4 | 0x 00 00 12 74 | The value represents a horizontal resolution with unit of pixel per meter. Here's 0x1274 [ppm], which is 4724 [ppm]. This field can be 0. | |
biClrUsed | 46 | 4 | 0x 00 00 00 00 | The value menas how many colors are stored in the pallete segment. When this value is 0, the number of color present in the palette is depending on bBitCount filed. | |
biCirImportant | 50 | 4 | 0x 00 00 00 00 | The number of colors ciritical for rendering in the palette. |
Bit Depth
In a smaple image, bit depth is 0x18 [bit], which is 24 [bit]. This 24 bits are allocated to Red, Green , and Blue values equally. This means that:Red0~255
Green0~255
Blue0~255
Color Table / Palette
Binary Editor
C++ codes
namespace MyStandard
{
typedef uint8_t BYTE;
typedef uint16_t WORD;
typedef uint32_t DWORD;
typedef uint64_t QWORD;
struct BITMAP_FILEHEADER
{
BYTE bfType[2]; // 0
BYTE bfSize[4]; // 2
BYTE bfReserved1[2]; // 6
BYTE bfReserved2[2]; // 8
BYTE bfOffBits[4]; // 10
};
struct BITMAP_INFOHEADER
{
BYTE biSize[4]; // 14
BYTE biWidth[4]; // 18
BYTE biHeight[4]; // 22
BYTE biPlanes[2]; // 26
BYTE biBitCount[2]; // 28
BYTE biCompression[4]; // 30
BYTE biSizeImage[4]; // 34
BYTE biXPixPerMeter[4]; // 38
BYTE biYPixPerMeter[4]; // 42
BYTE biClrUsed[4]; // 46
BYTE biCirImportant[4]; // 50
};
struct BITMAP_HEADER {
BITMAP_FILEHEADER file;
BITMAP_INFOHEADER info;
};
// ...
}