zoukankan      html  css  js  c++  java
  • 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 )为对象时,会创建单色位图。

  • 相关阅读:
    小白安装使用Redis
    Mysql的Sql语句优化
    maximo入门----用户使用提要
    时不时刷刷BOSS 看看技术需求
    2019.7.10整理
    docker使用入门
    docker之windows安装&centOS安装
    HashTable学习
    Hashmap学习
    红黑树学习
  • 原文地址:https://www.cnblogs.com/strive-sun/p/13037974.html
Copyright © 2011-2022 走看看