Aero: How to draw solid (opaque) colors on glass?

前端 未结 6 820
孤独总比滥情好
孤独总比滥情好 2020-11-30 03:02

Using GDI+ to draw various colors:

brush = new SolidBrush(color);
graphics.FillRectangle(brush, x, y, width, height);

You\'ll notice that n

6条回答
  •  庸人自扰
    2020-11-30 04:02

    I met the same issue with GDI.
    GDI uses zero alpha channel value, so the simpliest solution is to fix alpha channel like this code does:

    void fix_alpha_channel()
    {
        std::vector pixels(cx * cy);
    
        BITMAPINFOHEADER bmpInfo = {0};
        bmpInfo.biSize = sizeof(bmpInfo);
        bmpInfo.biWidth = cx;
        bmpInfo.biHeight = -int(cy);
        bmpInfo.biPlanes = 1;
        bmpInfo.biBitCount = 32;
        bmpInfo.biCompression = BI_RGB;
    
        GetDIBits(memDc, hBmp, 0, cy, &pixels[0], (LPBITMAPINFO)&bmpInfo, DIB_RGB_COLORS);
    
        std::for_each(pixels.begin(), pixels.end(), [](COLORREF& pixel){
            if(pixel != 0) // black pixels stay transparent
                pixel |= 0xFF000000; // set alpha channel to 100%
        });
    
        SetDIBits(memDc, hBmp, 0, cy, &pixels[0], (LPBITMAPINFO)&bmpInfo, DIB_RGB_COLORS);
    }
    

提交回复
热议问题