Custom RGB bitmap uses alpha channel to process transparency

Source: Internet
Author: User

In RGB mode, the formula for Alpha principle is displaycolor = sourcecolor × alpha/255 + backgroundcolor × (255-alpha)/255.

If a 32-Bit Bitmap without alpha channel is not used, the calculation result is black. Therefore, you only need to ensure that the maximum 8 bits is 1, that is

Newsourcecolor = 0xff000000 | sourcecolor;

The following is a transparent Bitmap Processing function:


Void drawbitmap (qpainter * PDC, int nleft, int ntop,
Int width, int height,
DWORD * bitmap, colorref clrback)
DWORD dwloopy = 0, dwloopx = 0;
Colorref crpixel = 0;
Byte bynewpixel = 0;
Int R, G, B;
Qrect rect (nleft, ntop, width, height );
Qimage imgalpha (const uchar *) bitmap, width, height, qimage: format_argb32 );
R = getrvalue (clrback );
G = getgvalue (clrback );
B = getbvalue (clrback );
For (dwloopy = 0; dwloopy {
For (dwloopx = 0; dwloopx <width; dwloopx ++)
Qrgb RGB = imgalpha. pixel (dwloopx, dwloopy );
Qrgb rgbmask = qrgb (R, G, B );
If (RGB = rgbmask)
Imgalpha. setpixel (dwloopx, dwloopy, QT: transparent );
PDC-> drawimage (rect, imgalpha );

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: 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.