How to draw ARGB bitmap using GDI+?

前端 未结 4 1217
醉梦人生
醉梦人生 2021-01-20 01:02

I have valid HBITMAP handle of ARGB type. How to draw it using GDI+?

I\'ve tried method: graphics.DrawImage(Bitmap::FromHBITMAP(m_hBitmap, NULL), 0, 0); But it doesn

4条回答
  •  悲哀的现实
    2021-01-20 01:39

    I've got working sample:

    // 1. Get info using bitmap handle: image size, bits
    BITMAP bmpInfo;
    ::GetObject(m_hBitmap, sizeof(BITMAP), &bmpInfo);
    int cxBitmap = bmpInfo.bmWidth;
    int cyBitmap = bmpInfo.bmHeight;
    void* bits = bmpInfo.bmBits;

    // 2. Create & draw new GDI+ bitmap using bits with pixel format PixelFormat32bppARGB
    Gdiplus::Graphics graphics(dcMemory);
    Gdiplus::Bitmap bitmap(cxBitmap, cyBitmap, cxBitmap*4, PixelFormat32bppARGB, (BYTE*)bits);
    graphics.DrawImage(&bitmap, 0, 0);

提交回复
热议问题