[Pin to top] [wxWidgets] _ [use a native image drawn by wxrenderernative to generate a wxbitmap with an Alpha transparent area]

Source: Internet
Author: User
Tags wxwidgets

Native checkbox image generated by wx:

Scenario:

1. if you want to develop custom checkbox and radiobutton, the background color of the native control cannot be replaced with the background of the parent control. In this case, you can only develop your own custom radiobutton. if it is a custom radiobutton, there is no need for radiobutton images. At this time, the simplest thing is to make a texture by the artist, but there are also ways to avoid the need for the artist to make images, because wxrenderernative of Wx comes with it.

Okay. Check the Code:

 

wxRendererNative &render = wxRendererNative::Get();    const wxSize sizeCheck = render.GetCheckBoxSize(panel_);    wxBitmap bitmap(sizeCheck.x, sizeCheck.y);    wxMask *mask = new wxMask(bitmap, *wxBLACK);    bitmap.SetMask(mask);    wxImage image = bitmap.ConvertToImage();    image.InitAlpha();    wxBitmap bt(image);    wxMemoryDC mDc;    mDc.SelectObject(bt);    render.DrawCheckBox(panel_, mDc, wxRect(0, 0, sizeCheck.x, sizeCheck.y));    //render.DrawRadioBitmap(panel_, mDc, wxRect(0, 0, sizeCheck.x, sizeCheck.y));    mDc.SelectObject(wxNullBitmap);    bt.SaveFile(wxT("E:/bt.png"),wxBITMAP_TYPE_PNG);

 

 

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.