Gdiplus位图没有Alpha通道

时间:2018-07-26 12:37:06

标签: c++ bitmap gdi+

我正在尝试通过BITMAPINFO(缩短的代码示例)创建Gdiplus :: Bitmap:

    BITMAPINFO bmi;
    HDC hdc;
    void* pvBits;

    ZeroMemory(&bmi, sizeof(BITMAPINFO));
    bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth = some_width;
    bmi.bmiHeader.biHeight = some_height;
    bmi.bmiHeader.biPlanes = 1;
    bmi.bmiHeader.biBitCount = 24;
    bmi.bmiHeader.biCompression = BI_RGB;
    bmi.bmiHeader.biSizeImage = ((((bmi.bmiHeader.biWidth * bmi.bmiHeader.biBitCount) + 31) & ~31) >> 3) * bmi.bmiHeader.biHeight;

    HBITMAP hBM = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS, &pvBits, NULL, 0x0);
    FillMemory(pvBits, bmi.bmiHeader.biSizeImage, 255);

    HGDIOBJ oldObj = SelectObject(hDC, hBM);
    ReleaseDC(NULL, hDC);

    GdiFlush();

    GdiPlusBitmap* bitmap = new Gdiplus::Bitmap(&bmi, pvBits);

我的问题是创建的位图没有Alpha通道(PixelFormat24bppRGB)。我想念什么?

1 个答案:

答案 0 :(得分:2)

bmi.bmiHeader.biBitCount = 32;
hDC = CreateCompatibleDC(someOtherDc);

您可以看到一个示例here