Background:
There are two pictures, one is the target background picture, the other is a color picture with its own background color
The color picture is first drawn to the target background image, which can be achieved by BitBlt. But the effect is: the target picture, painted up color pictures with its own background.
The problem is, we want to remove the background color picture itself, how should we solve?
Workaround:
Using API functions: TransparentBlt This function draws a picture from the original DC to the target DC and sets the original shape's transparent color on the target graphic.
BOOL TransparentBlt (
HDC hdcdest, //handle to destination DC
int nxorigindest, //X-coord of Destination Upper-left corner
int nyorigindest, //Y-coord of destination Upper-left
-corner int nwidthdest, //width of destination rectangle
int hheightdest, //height of destination rectangle
HDC HDCSRC,
//handle to source DC
int nxoriginsrc, //X-coord of source upper-left corner
int nyoriginsrc, //Y -coord of source upper-left corner
int nwidthsrc, //width of source rectangle
int nheightsrc, //Hei Ght of source Rectangle
UINT crtransparent//color to make transparent
);
In this example, when the transparent color is set to a color graphic with its background color, the resulting color of the colored graphic on the final shape is eliminated when the function is used.
cdc* pdc=getdc ();
CBitmap bmp;
Bmp. LoadBitmap (IDB_BITMAP1);
BITMAP Bmpinfo;
Bmp. GetObject (sizeof (BITMAP), &bmpinfo);
CDC Imagedc;
Imagedc.createcompatibledc (PDC);
CBitmap *poldimagebmp=imagedc.selectobject (&bmp);
CBitmap bmpbk;
Bmpbk.loadbitmap (IDB_BITMAP2);
BITMAP Bmpbkinfo;
Bmpbk.getobject (sizeof (BITMAP), &bmpbkinfo);
CDC BKDC;
Bkdc.createcompatibledc (PDC);
Bkdc.selectobject (&BMPBK);
TransparentBlt (Bkdc.m_hdc,100,150,bmpinfo.bmwidth,bmpinfo.bmheight,imagedc.m_hdc,0,0,bmpinfo.bmwidth, Bmpinfo.bmheight,rgb (255,0,0)); Set red to Transparent color
BitBlt (pdc->m_hdc,0,0,bmpbkinfo.bmwidth,bmpbkinfo.bmheight,bkdc.m_hdc,0,0,srccopy);//Draw to screen
Principle: By setting the mask bitmap to implement
1 Create mask Bitmap first
2 Using a mask bitmap to the color of the original image, get a new map (transparent color is black, the other area is the primary color)
3 Use mask bitmap and target background image (transparent area is transparent, other area is black)
4 Use the new variant and the target background image or, get the final diagram
The above mentioned is the entire content of this article, I hope you can enjoy.