BMP bitmap file format

Source: Internet
Author: User

Four components of BMP:

1. File Header information block

0000-0001: File ID, which is the ASCII code "BM ".
0002-0005: file size.
0006-0009: Reserved. Each byte is set to "00.
000a-000d: records the starting position of the image data area. The meaning of each byte is as follows: size of the file header information block, size of the image description information block, size of the image color table, and retention (01 ).

2. image description information block

000e-0011: size of the image description block, usually 28 h.
0012-0015: image width.
0016-0019: Image Height.
001a-001b: Total number of Plane Images (constant: 1 ).

001c-001d: records the number of pixels, which is an important value. The number of colors of an image is determined by this value.
001e-0021: Data Compression Method (value 0: no compression; compression ).
0022-0025: the size of the image area data.
0026-0029: the number of pixels in a horizontal meter. In a device-independent Bitmap (. Dib), each byte is set to H.
002a-002d: the number of pixels in a vertical field per meter. In a device-independent Bitmap (. Dib), each byte is set to 00h.
002e-0031: number of colors used by the image. If the value is 0, it indicates that all colors are equally important.

3. Color Table

The size of the color table depends on the color mode used: the two-color image is 8 bytes, the 16-color image is 64 bytes, And the 256-color image is 1024 bytes. Each 4 bytes represents a color with the transparency values of B (blue), g (green), R (red), and alpha (32-Bit Bitmap, usually not required ). That is, four bytes indicate the color of the color number 0, followed by the color of the color number 1, and so on.

4. Image Data Zone

The next part of the color table is the image data area of the bitmap file. In this part, the color numbers corresponding to each pixel are recorded. The recording method varies with the color mode, A two-color image occupies 1 position (8 bits in 1 byte), a 16-color image occupies 4 bits (half byte), and a 256-color image occupies 8 bits (1 byte ); A true color image occupies 24 bits per point (3 bytes ). Therefore, the size of the entire data zone also changes. According to the rule, the following formula is provided: image data size = (Image Width * Image Height * records the number of pixels)/8.

However, the size of the uncompressed image information area. Except for the true color mode, all other values are greater than or equal to the data information size. Why? There are two reasons:
1. The BMP file records a row of images in bytes. Therefore, the data bit information in one byte does not represent the point in two different rows. That is to say, set the display mode bit to 16 colors. When two vertices are allocated to each byte, if the image width bit is odd, the information of the last pixel will exclusive to one byte, the last four digits of this byte are meaningless. The next byte records the information of the next row.
2. For ease of display, in addition to true color, the number of bytes in each color mode must be set to an integer multiple of 4 by "00" of the data. If the display mode is 16 colors, when the image width is 19, 4-(19/2 + 1) must be added for each row during storage) % 4 = 2 bytes (plus 1 because one pixel excludes one byte ). If the display mode is 256 colors, when the image width is 19, each line must be 4-19% 4 = 1 byte

Related Article

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.