BMP image format

Source: Internet
Author: User
Tags bmp image

First look at the header file format of BMP:

Note: The above multi-byte type, for example, int32 is stored after the first high level and low level, such as the BIT file size: 0002-0005, int32 type, the obtained integer is correct and must be combined in the order of 5th, 4, 3, and 2 bytes.

With the header file information, we can find the bitmap data. Bitmap data is processed in a group of 4 bytes (32-bit, corresponding to 32-bit CPU optimization.

Example 1. Let's first look at the simple internal storage method (0: Black, 1: White) with only two colors of black and white ):

Original BMP image (one square indicates one pixel)

Binary Code of the BMP Image

The red box indicates the bitmap data information. Four bytes are used as a group (7*5 pixels). The bitmap data is 5 bytes, and the figure height is 5 pixels. Therefore, each row contains 1 byte, they are:
7E 00 00 00; 0111 1110 0000 0000 0000 0000
Fe 00 00 00; 1111 1110 0000 0000 0000 0000 0000
7E 00 00 00; 0111 1110 0000 0000 0000 0000
Fe 00 00 00; 1111 1110 0000 0000 0000 0000 0000
54 00 00 00; 0101 0100 0000 0000 0000 0000 0000
By comparing the original BMP image, you will find that it is stored horizontally and vertically, first down and then on. Because there are only 7 horizontal pixels, 4 bytes (32 bits) use only the first 7 bits, and then 0.

Example 2. view the 24-Bit Bitmap, which is composed of three RGB primary colors. Each color is represented by one byte.


24-bit BMP source Image


 

24-bit BMP Image Binary Code

The red box indicates the bitmap data information. Four bytes are used as a group (2*3 pixels). The bitmap data contains 24 bytes. The height of the image is 3 pixels. Therefore, each row contains 8 bytes, they are:
FF 00 ff 00 00 00; FF 00 ff 00 00 00 00 indicates: white green
00 ff 00 00 00 ff 00 00; 00 ff 00 00 00 ff 00 00 indicates: green red
00 00 00 ff 00 00 00 00; 00 00 00 ff 00 00 00 00 means: black and blue

Because 24 bits use RGB primary colors, each primary color uses one byte.
After observation, it is found that the color is in BGR sequence, which may be related to the order of word storage. The color is first high and then low.

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.