win32-CreateDIBSection的使用

使用CreateDIBSection 可以创建一个设备无关位图

#include <windows.h>
using namespace std;
int main() {
    HDC hdc = GetDC(HWND_DESKTOP);
    HDC MemDC = CreateCompatibleDC(hdc);
//    HBITMAP hBit = CreateCompatibleBitmap(hdc, 1366, 768);
    BITMAPINFO bmi;
    memset(&bmi, 0, sizeof(BITMAPINFO));
    bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth = 1366;
    bmi.bmiHeader.biHeight = 768; // top-down
    bmi.bmiHeader.biPlanes = 1;
    bmi.bmiHeader.biBitCount = 32;
    bmi.bmiHeader.biCompression = BI_RGB;

    PVOID m_pBits;
    HBITMAP  m_hBmp = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&m_pBits, NULL, NULL);
    SelectObject(MemDC, m_hBmp);
    BitBlt(MemDC, 0, 0, 1366, 768, hdc, 0, 0, SRCCOPY); 

    BitBlt(hdc, 0, 0, 1366, 768, MemDC, 0, 0, SRCCOPY); 
 //   DeleteObject(hBit);
    DeleteObject(m_hBmp);
    ReleaseDC(HWND_DESKTOP, hdc);
    ReleaseDC(NULL, MemDC);
    DeleteDC(MemDC);
    DeleteDC(hdc);
}

 

顺便说一下,当使用CreateCompatibleBitmap以内存dc(MemDC )为对象时,会创建单色位图。

win32-CreateDIBSection的使用

上一篇:C#中遇到定时器问题


下一篇:BeanCreationNotAllowedException: Error creating bean with name 'eurekaAutoServiceRegistration' 以及 Windows 找到端口对应pid