How to Create a hollow-out chart
A hollow-out image is to display a part of the image on another background image, and remove unnecessary parts in the image (these parts must be white or black), that is, the display effect of the hollow-out image.
The image is a hollow image:
To generate a hollow-out image, you only need to use the bitblt function and raster operation described earlier. This section describes the principle of a hollow-out image and creates an example of a hollow-out image.
Procedure
There are many ways to create a hollow-out chart. However, different raster operations are used to convert the image to produce the same hollow-out effect. Here we will introduce the simplest and easiest way to remember.
The bitmap in can be divided into two parts (two parts are combined in a bitmap), the left half is the character, the hollow part is black, and the right half is only black and white, it is called a mask ;. The following describes how to generate a hollow-out diagram:
Step 1: Use the bitblt function to perform and operations on the mask and background image and paste them to the destination DC.
Step 2: perform or operations on the image and background image to be hollow out and paste them to the destination DC.
Principle of creating a hollow-out chart
Why can the hollow-out effect be achieved after the above two steps?
Perform and operations on the mask and background image in step 1.
1. The middle character of the mask is black, and the "and" operation is performed on the background image to become:
2. The mask is white, and the and operation with the background image is changed:
The result of step 1 is shown in:
In step 2, perform the or operation on the image to be hollow out and the background image:
1. The characters in the image are in color, and the or operation is performed with the previous image to change:
2. The four sides of the character are black, and the or operation with the background image is changed:
In this way, the result is the hollow figure we want:
Finally, let's look at an example of a hollow-out chart:
(1) generate a dialog box program named ch2_5
(2) Add several public members to ch2_5dlg.h:
Public:
CDC * MDC;
Cbitmap * bgbmp, * bitmap;
Rect;
Load two bitmaps In the bool cch2_5dlg: oninitdialog () function. The program source code is as follows:
Cclientdc DC (this );
Getclientrect (& rect );
MDC = new CDC;
Bgbmp = new cbitmap;
Bitmap = new cbitmap;
MDC-> createcompatibledc (& DC );
Bgbmp-> m_hobject = LoadImage (null, "Res/mslinux.bmp", image_bitmap, rect. Right, rect. Bottom, lr_loadfromfile );
Bitmap-> m_hobject = LoadImage (null, "Res/zzz.bmp", image_bitmap, 0, 0, lr_loadfromfile );
Attach the background image to the void cch2_5dlg: onpaint () function, perform the and operation on the masked image and background image, and then perform the or operation on the hollowing out and background image.
Cclientdc DC (this );
MDC-> SelectObject (bgbmp );
// Paste the background image
DC. bitblt (0, 0, rect. Right, rect. Bottom, MDC, 0, srccopy );
MDC-> SelectObject (Bitmap );
// Perform and operations on the mask and background image
DC. bitblt (97,125, MDC, srcand );
// Perform the or operation on the image and background image to be hollow out
DC. bitblt (97,125, MDC, srcpaint );
When the program starts loading, we find that if we combine the hollow pattern with the mask as a bitmap, we can use the bitblt function to dynamically select the pattern to be pasted into the window, in this way, the computer operation efficiency can be improved. In addition, loading all the required images at a time can reduce the I/O actions of hard disk data, because the speed of selecting the image to be attached to the screen from the memory is far faster than loading the image from the hard disk, this can be kept in mind when designing a program.