Digital image processing into introductory notes--chapter one Windows bitmaps and palettes

Source: Internet
Author: User
Tags image line

the concept of 1.1 bitmaps and palettes

1. True Color map: Its color is as high as 256x256x256 species, that is, including the above mentioned R, G, B color to represent all the colors in the method. A true color image is that it has the ability to display all colors, that is, to include all colors.

1.2 bmp file format

(Word is an unsigned 16-bit integer, DWORD is an unsigned 32-bit integer, Long is a 32-integer)

1. bmp files are roughly divided into four parts:

1 bitmap file Header Bitmapfileheader, a total of 14 bytes.

2 Bitmap Information Header Bitmapinfoheader, a total of 40 bytes.

3) Palette Palette

4 The actual bitmap data imagedate

The palette is actually an array with a total of biclrused elements (if the value is zero, there is an element). The type of each element in the array is a RGBQUAD structure, accounting for 4 bytes. ( red, green and blue sort are the exact opposite of the color data of a general image file. )

For a bitmap that uses a palette, the image data is the index value of the image Sohe in the palette. For true color graphs, image data is the actual R, G, B value

2. Attention to two points:

1 The number of bytes per line must be the integer multiple of 4, if not, then need to be padded.

2 in general,BMP file data from the bottom to the top, from left to right .

1.3 A C program that displays a BMP file

First, the Loadbmpfile function implementation process:

1. Open the file to the hfile structure variable.

2. Read Bitmpfileheader and Bitmapinfoheader two structural variables from the hfile variable.

3. Calculates the number of image line bytes and total image bytes.

4. Calculate the number of colors actually used and verify the results.

5. Fill in bf.bfsize;

6. Allocates the global memory space, the size is (bitmapinfoheader+palette+ actual image) returns a handle.

7. Lpbitmapinfoheader points to the allocated global memory space.

8. The file pointer is repositioned to the beginning of the Bitmapinfoheader and the content is read into the Lpbitmapinfoheader type pointer. Closes the file. The difference between _hread and _lread.

9. Numcolors is not zero, the color palette is used in the description. Allocates local memory for the logical palette, which is the logical palette structure length plus numcolors a palettentry.

The 10.LOGPALETTE type pointer ppal points to the memory area and fills in the head of the logical palette structure. Lprgb points to the beginning of the palette and fills in each item of the Ppal->palpalentry.

11. Generate Logical Palette global variable Hpalette, unlock and free local memory.

12. Obtain the device context handle.

13. If a logical palette is generated, the new logical palette is selected into the DC, and the old logical palette handle is saved in the Hprevpalette.

14. Produces a bitmap handle. When you finish using the current palette, restore the original palette to the DC.

15. Release the device context and unlock the memory area.

two, in response to WM_PAINT message:

1. Get the difference between screen device context BeginPaint and GETDC.

2. Establish a memory device context. When there is a palette, select the palette into the screen device context and the memory device context.

3. Select the bitmap into the memory device context, display the bitmap, release the memory device context, and release the screen device context.

Note: 1 The reason for the 2 DCs is that the contents of the source (memory) device context are copied to the destination (screen) device context when the bitmap is drawn.

The book provides the code to run has the problem, after the modification, the error is gone, but is the picture does not appear. And some of its code is not clear, such as how the system sent wm_loadbitmap this message.

finally solved the.

A: Reading the code provided in the book did not notice that there is a. RC is a suffix of the resource file, which defines a menu,menu inside there is a child control open, which is associated with the Wm_loadbitmap. Never wanted to go to the past manually edit the resource file, if not yesterday to try to use DOS to compile C + + files, how did not want to open this file to see. Seems to put a release is right, endure for so long finally liberated. Write a later on if the VC resource file structure of the article, for later learning is helpful.

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.