Reprinted please indicate the source: http://blog.csdn.net/lonelyrains/article/details/9243179
1. Use the cximage library to do this. Download the source code and compile all lib and DLL
2. Open the demo project and add the following code at the end of the case wm_user_newimage function in void cdemoview: onupdate (cview * psender, lparam lhint, cobject * phint) of demo \ demoview. cpp:
// Transparent image for (INT I = 0; I <ima-> getwidth (); I ++) {for (Int J = 0; j <ima-> getheight (); j ++) {rgbquad RGB = ima-> getpixelcolor (I, j); If (RGB. rgbred> 250 & RGB. rgbgreen> 250 & RGB. rgbblue> 250) {ima-> alphaset (I, j, 0);} else {ima-> alphaset (I, j, 255) ;}} invalidate (0 );
Note that you cannot directly use this setting to make the image transparent. Therefore, the image to be operated must have the property of transparent settings. Therefore, a common practice is to use a function (such as QQ) to capture the image to be taken to the white edge, and then open it with a drawing program and save it as PNG. Then there is a transparent property, drag the PNG file into the window that processes the demo compiled by the code, and then automatically process the effect. Save the file to obtain the required transparent boundary. The condition is RGB. rgbred> 250 & RGB. rgbgreen> 250.
& RGB. rgbblue> 250 indicates the white edge, which can be changed to an edge of another color, which is a threshold value.
Before: After processing:
Figure 1 Figure 2
Before: After processing:
Figure 3 Figure 4
Expansion requirement: white edge removal: No matter what kind of image, it is transparent in the closed loop or all the white or black parts; (Closed Loop concept: when determining the basic threshold value, if it is to be processed as a transparent pixel, if it is not processed as a transparent pixel circle by a closed loop, it is not regarded as a transparent pixel. White clouds in 1 should not be set as transparent pixels in Figure 2 in the closed loop of blue pixels)
Extended implementation: Determine whether bitmap coordinates are implemented in a closed loop, define transparent pixel thresholds in white or black, convert to transparent, and save images
Final tool binary: http://download.csdn.net/detail/lonelyrains/5702821