Since all the diagram files are stored in the form of a square rectangle, but sometimes we may need to put a picture of a monster on the background of the window, and in this case if we map directly, the background of this picture will be pasted together into the window background picture, which is certainly not what we want, All we have to do is to paste the unwanted parts of the picture, is called the picture transparent effect processing.
The main thing is to use the BitBlt () mapping function and the operation of the raster value to remove unnecessary parts of the picture (also known as back), so that the theme of the diagram can be fully integrated with the background image. There are a number of ways to make transparent effects, but basically the use of different raster operations, through the conversion and finally produce the same transparency effect. Here's a way to introduce a transparent operation first:
First you have to prepare a bitmap:
The picture on the left is a foreground map to the foreground on the background and the black and white image on the right is called a "shield", which is used in the transparent process. To the back of the bitmap and screen map merged into the same picture, transparent when the need to cut. It can be divided into two graphs, but the program will have to run two times the loading of the diagram file. The following mapping steps:
(1): The screen and background map to do "and" (raster value of Srcand) operation, affixed to the destination DC;
(2): The foreground and background image as "OR" (raster value is srcpaint) operation, paste into the destination DC.
Why does this have a transparent effect?
This is because: the RGB value of white is (255,255,255), the binary is 111111111111 ...
The RGB value of black is (0,0,0), the Longjiang binary system is 000000000000 ...
Operation procedure:
1: Screen map and background image to do "and" operations
(1) The black part of the diagram in the screen map is used as "and" with the background image:
000000 ....---------------------the color value of a black point in a screen map
And) 011010 ....---------------------color values of color points in a background image
000000.------------------------operation is black
(2) The white part of the screen map and the background image do the "and" Operation:
11111 ....---------------------the color value of a white point in a screen map
And) 011010 ....---------------------color values of color points in a background image
011010 the color of the original background image after------------------------operation
2, the foreground and background images are "OR" operations:
(1) The color portion of the foreground graph is calculated as "OR" by the graph above:
101011 ....---------------------color values of color points in a foreground chart
OR) 000000 .... The color value of a black point in a---------------------background image
101011 the color of the foreground image after------------------------operation
(2) The black portion of the foreground graph is an "OR" operation following the graph above:
000000 ....---------------------the color values of black points in the foreground chart
OR) 101010 ....---------------------color values of color points in a background image
011010 the color of the original background image after------------------------operation
The picture shown after this operation is the transparent diagram needed.
Note;
BOOL BitBlt (HDC purpose DC,//Map
int purpose DC x coordinates, int purpose dc y coordinates, int to the width of the destination DC,
int to the height of the destination DC, HDC source DC, int source DC x coordinate, int source DC y coordinate,
DWORD mapping method);