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 );
}