Image translucent Effect

Source: Internet
Author: User

I encapsulated a method, passed in the corresponding image, it will turn the image into a translucent effect and display it on the program interface.

Void cmegajoycontainer: converttoalpha (cwindowgc & GC, cfbsbitmap * imgtobrighten) const
{
Cfbsbitmap * iemptybitmap = new (eleave) cfbsbitmap ();
Cleanupstack: pushl (iemptybitmap );

User: leaveiferror (iemptybitmap-> Create (imgtobrighten-> sizeinpixels (), ceikonenv: static ()-> defaultdisplaymode ()));

Cfbsbitmapdevice * IgD = cfbsbitmapdevice: newl (iemptybitmap );
Cleanupstack: pushl (IGD );
Cfbsbitgc * IGC;
User: leaveiferror (IGD-> createcontext (IGC ));

IGC-> setpenstyle (cgraphicscontext: enullpen );
IGC-> setbrushcolor (krgbwhite );
IGC-> setbrushstyle (cgraphicscontext: esolidbrush );
IGC-> drawrect (trect (tpoint (0, 0), iemptybitmap-> sizeinpixels ()));
IGC-> setbrushstyle (cgraphicscontext: enullbrush );

Delete IGC;
Cleanupstack: popanddestroy (IGD );

Cfbsbitmap * iemptybitmapmask = new (eleave) cfbsbitmap ();
Cleanupstack: pushl (iemptybitmapmask );

User: leaveiferror (iemptybitmapmask-> Create (imgtobrighten-> sizeinpixels (), egray256 ));

IgD = cfbsbitmapdevice: newl (iemptybitmapmask );
Cleanupstack: pushl (IGD );
User: leaveiferror (IGD-> createcontext (IGC ));

IGC-> setpenstyle (cgraphicscontext: enullpen );
IGC-> setbrushcolor (krgbgray );
IGC-> setbrushstyle (cgraphicscontext: esolidbrush );
IGC-> drawrect (trect (tpoint (0, 0), iemptybitmap-> sizeinpixels ()));
IGC-> setbrushstyle (cgraphicscontext: enullbrush );

Delete IGC;
Cleanupstack: popanddestroy (IGD );

GC. bitbltmasked (tpoint (0, 0), iemptybitmap, trect (tpoint (0, 0), iemptybitmapmask-> sizeinpixels (), iemptybitmapmask, efalse );

Cleanupstack: popanddestroy (iemptybitmapmask );
Cleanupstack: popanddestroy (iemptybitmap );

}

Note that you must add the file to the. MMP file.

Library bitgdi. Lib
Library ws32.lib
Library fbscli. Lib

The effect is as follows:

The original image is

The converted image is

 

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.