A bmp file consists of four parts: File Header, bitmap information header, color information, and image data:
Bitmapfileheader |
Bitmapinfoheader |
Bitmap color table rgbquad |
Bitmap pixel data |
1. Bitmap File Header
The bitmap file header contains information such as the type, size, and start position of the BMP file. Its structure is defined as follows:
Typedef struct tagbitmapfileheader {word bftype; // The type of the bitmap file, which must be bmp dword bfsize; // the size of the bitmap file, in bytes: Word bfreserved1; // reserved words of the bitmap file, it must be 0 word bfreserved2; // reserved word of the bitmap file, which must be 0 DWORD bfoffbits; // the starting position of the bitmap data, expressed in bytes as the offset relative to the file header} bitmapfileheader;
2. Bitmap header
The structure of the BMP bitmap information header is used to describe the size and other information of the bitmap. Its structure is as follows:
Typedef struct tagbitmapinfoheader {DWORD bisize; // The number of bytes occupied by this structure long biwidth; // The width of the bitmap, in pixels long biheight; // The height of the bitmap, in pixels, word lanlanes; // The level of the target device, which must be 1 word bibitcount; // The number of digits required for each pixel, which must be 1 (two-color ), 4 (16 colors), 8 (256 colors), or 24 (true color) One DWORD bicompression; // bitmap compression type, must be 0 (not compressed), 1 (bw.rle8 compression type) or 2 (bw.rlb4 compression type) DWORD bisizeimage; // bitmap ing, in bytes long bixpelspermeter; // bitmap horizontal resolution, in pixels/meters long biypelspermeter; // bitmap vertical resolution, in the unit of pixels/meters DWORD biclrused; // number of colors in the color table used by the bitmap DWORD biclrimportant; // number of important colors in the bitmap display process} bitmapinfoheader