Remove white borders and make border transparent.

Source: Internet
Author: User
Tags transparent image

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

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.