BMP bitmap file format

Source: Internet
Author: User
Tags bmp image windows support

Recently, we have been collecting video data. We need to save the collected data to the BMP format. Now we can post the knowledge about BMP for everyone to learn.

BMP is a standard Windows Image format compatible with DOS and Windows. The BMP format supports RGB, index color, grayscale, and bitmap color modes. Can I specify windows or OS/2 for images? Format and bit depth. You can also specify RLE compression for 4-and 8-bit images in Windows format.

BMP images are usually compiled from the bottom up, but you can also select the "flip row order" option to write from the top down. You can also click "Advanced Mode" to select other encoding methods. ("Flip the line Order" and "Advanced Mode" are most useful for game programmers and other people using DirectX .)

Windows bitmap, a bitmap file. This is the most common file format on the computer. You can find a lot in the Windows directory, most of which are Windows desktop and wallpaper patterns. Basically all software supports it. Common BMP images are not compressed, so the image quality is good, but it is relatively large. BMP has multiple formats, such as black and white, gray scale, 256 color, and true color. The more colors there are, the larger the file is, the more realistic the image is. Because the uncompressed BMP image records the image information point by point, the file size is fixed with the pixel and color number, such as a true-color 352x288 uncompressed BMP image, no matter what the content is, even if it is blank, its file size will always be 304182 bytes.

BMP is the abbreviation of Bitmap. (Oh, everyone knows it. It's nonsense. You can skip it ). Bitmap format files were first used in Windows operating system environments of MS-Windows3.0 and later versions (DIB) Dot Matrix bitmap file format, that is, Windows can display bitmap files on any device. Windows has become an industrial standard for PC operating systems as windows expands and its versions become increasingly sophisticated. Currently, graphics and image file processing tools running in various versions of Windows support bitmap files. Its main features include: the file structure is similar to that of a PCX file. Each file can only store one image. Whether the image data is compressed can be selected by the user as needed.
Each BMP file contains three parts:
1. bitmapfileheader: it contains a class of device-independent bitmap files.
Type, size, display content, and other information.

The bitmapfileheader of the BMP file header can be described in the following structure:

Typedef struct

{

Int bftype;

Long bfsize;

Int bfreserved1;

Int bfreserved2;

Long bfoffbits;

} Bitmapfileheader;

The meanings of fields in this structure are as follows:

· The bitmap file type specified by bftype must be "BM" as the mark of the recognized BMP file

Log.

· Bfsize: the size of the bitmap file, in bytes.

· Bfrserved1: Reserved Words for bitmap files, which must be set to 0.

· Bfrserved2: Reserved Words for bitmap files, which must be set to 0.

· Bfoffbits provides a bitmap array, that is, the offset between the actual bitmap and bitmapfileheader.

In bytes.
2. (1) bitmapinfoheader Data Structure: it contains information about the size and format of a device-independent bitmap of windows3.0 and later versions, including the image width, height, and compression method.

Its structure is as follows:

Typedef struct

{

Long bisize;

Long biwidth;

Long biheight;

Int biplanes;

Int bibitcount;

Long bicomprission;

Long bisizeimage;

Long bixpelspermeter;

Long biypelspermeter;

Long biclrused;

Long biclrimportant;

} Bitmapinfoheader;

The meanings of fields in the structure are as follows:

· The number of bytes required for the bisize bitmapinfoheader structure.

· Biwidth: the width of the bitmap (in pixels ).

· The height of the biheight Bitmap (in pixels ).

· The number of bit planes of the biplanes output device must be set to 1.

· Bibitcount: the number of digits required for each pixel. It must be 1 (monochrome), 4 (16 colors), 8 (256

Color) or 24 (true color.

· The compression type specified by bicompression bitmap. The values must be 0 (not compressed) and 1 (bi_rle8 ).

Compression type) or 2 (bi_rle4 compression type.

· Bisizeimage: the number of bytes of bitmap data.

· Horizontal resolution of the target device of the bixpeispermeter bitmap, in the unit of prime number of each meter.

· The vertical resolution of the target device of the biypeispermeter bitmap, in the unit of prime number of each meter.

· The actual number of colors used by the image in the biclrused color palette.

· Color index values that are considered important during the bitmap display of biclrimportant.

(2) color table (rgbquad): used to describe the color in the bitmap. It has several table items, each of which is an rgbquad structure and defines a color.

Its structure is as follows:

Typedef struct

{

Unsigned char rgbblue;

Unsigned char rgbgreen;

Unsigned char rgbred;

Unsigned char rgbreserved;

} Rgbquad;

In the color defined by rgbquad, the blue brightness is determined by rgbblue, the green brightness is determined by rgbgreen, and the red brightness is determined by rgbred. Rgbreserved is a reserved word and must be set to 0.

When bibitcount = 1, 4, and 8, there are 2, 16, and 256 table items in the color table.

When bibitcount = 24, the table items in the color table are empty. Each three bytes of the bitmap array represents a pixel. The three bytes directly define the relative brightness of blue, green, and red in the pixel color. Therefore, the item in the color table is omitted.

3. Bitmap array.

Store the gray value of a pixel from bottom left to top right. It has two storage formats: compression and non-compression.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.