A bitmap format
Windows Bitmap in two formats: the device is called a correlation diagram (Device Depend Bitmap, DDB), the other is called device-independent FIG (Device Independ Bitmap, DIB)
Two .DDB Bitmap
DDB bitmap yet GDI (Graphics Device Interface, Graphics Device Interface) bitmap.
In HBITMAP WinSDK represented by, in CBitmap MFC represented by, it is a device and related data (memory read)
Three .DIB Bitmap
A DIB bitmap file divided into four parts: BITMAPFILEHAEDER BITMAPINFOHEADER palette data and actual image data of
the DIB DDB is different from the bottom row byte array from the image memory row starts up, the image is inverted then over progressive scan, additional bytes in the byte array for each scan line must be a multiple of 4, if required insufficient padded 0
1.BITMAPFILEHEADER header
The structure of a fixed length of 14 bytes
struct {tagBITMAPFILEHEADER typedef WORD bfType; // length of 2, whether or bmp image files DWORD bfSize; // length of 4, the specified file size, including the entire header WORD bfReserved1; // length of 2, a reserved byte 0 WORD bfReserved2; // 2 length, reserved byte 0 DWORD bfOffBits; // length 4, from the file header to specify the image data of the actual number of bytes offset } BITMAPFILEHEADER;
2.BITMAPINFOHEADER header
The structure of a fixed length of 14 bytes
struct {tagBITMAPINFOHEADER typedef DWORD biSize; // length of 4, a specified length of the structure LONG biWidth; // length of 4, the width of the specified image pixel LONG biHeight; // length of 4, the height of the specified image pixel WORD biPlanes; // length is 2, the value must be 1, represents a plane WORD biBitCount; // length of 2, the specified color bit depth, 1 (black and white binary image) / 4 (FIG. 16 colors) / eight-bit (256 color chart) 16 (color) / 24 (FIG true color) / 32-bit DWORD biCompression; // length 4 that specifies whether to compress the bitmap, either BI_RGB indicates no image compression DWORD biSizeImage; // length of 4, the actual image data is designated the number of bytes occupied LONG biXPelsPerMeter; // length of 4, the horizontal resolution of the target device LONG biYPelsPerMeter; // length of 4, the vertical resolution of the target device DWORD biClrUsed; // length is 4, the number of colors showing DWORD biClrImportant; // length image color are important 4,0 } BITMAPINFOHEADER;
3. palette data
DIB bit depth greater than 8 palette data is not present
struct {tagRGBQUAD typedef BYTE rgbBlue; // the blue color component BYTE rgbGreen; // the green color component BYTE rgbRed; // the red color component BYTE rgbReserved; // Retention 0 } of RGBQUAD;
4. The actual image data
For 2-color bitmap represented by a color of a pixel (0 representing black and 1 for white), a byte can represent eight pixels
for the color chart 16, one pixel is represented by four color (0 <= n <= 16)
for the color chart 24, by 8 bits represent the color of a pixel (0 <= n <= 256 )
to FIG. 16, 2 bytes (WORD) indicates a pixel
to FIG. 24, using 3 byte represents one pixel
to FIG 32 shows a pixel with four byte
The display image DIB
MFC does not provide any support function for the DIB, but WinSDK provides some DIB manipulation functions
GetDIBits // Get a DDB from the bitmap image bit SetDIBits // set bitmap image bit DIB, DIB for converting into the form of DDB CreateDIBitmap // DDB created with the specified DIB, DIB and initialization information with the bitmap image bit SetDIBitmap // directly DIB bitmap image bit to output device for displaying the DIB StretchDIBits // the DIB bitmap to a rectangular area map output device, the bitmap can be scaled CreateDIBPatternBrush // create a bitmap DIB mode brush CreateDIBSection // create a direct written DIB GetDIBColorable // get DIB color table SetDIBColorTable // set the DIB color table