【问题标题】:Why does MS Example of GetDIBits create a new BITMAPINFOHEADER?为什么 GetDIBits 的 MS 示例会创建一个新的 BITMAPINFOHEADER?
【发布时间】:2020-11-27 12:39:56
【问题描述】:

使用 GetDIBits here 的 Microsoft 示例必须在下面编写代码。我的问题是他们为什么要创建一个新的 bi 项目,而不是在调用 GetDIBits 时仅使用 bmpScreen ?:

    // Get the BITMAP from the HBITMAP
    GetObject(hbmScreen,sizeof(BITMAP),&bmpScreen);
     
    BITMAPFILEHEADER   bmfHeader;    
    BITMAPINFOHEADER   bi;
     
    bi.biSize = sizeof(BITMAPINFOHEADER);    
    bi.biWidth = bmpScreen.bmWidth;    
    bi.biHeight = bmpScreen.bmHeight;  
    bi.biPlanes = 1;    
    bi.biBitCount = 32;    
    bi.biCompression = BI_RGB;    
    bi.biSizeImage = 0;  
    bi.biXPelsPerMeter = 0;    
    bi.biYPelsPerMeter = 0;    
    bi.biClrUsed = 0;    
    bi.biClrImportant = 0;

    DWORD dwBmpSize = ((bmpScreen.bmWidth * bi.biBitCount + 31) / 32) * 4 * bmpScreen.bmHeight;

    // Starting with 32-bit Windows, GlobalAlloc and LocalAlloc are implemented as wrapper functions that 
    // call HeapAlloc using a handle to the process's default heap. Therefore, GlobalAlloc and LocalAlloc 
    // have greater overhead than HeapAlloc.
    HANDLE hDIB = GlobalAlloc(GHND,dwBmpSize); 
    char *lpbitmap = (char *)GlobalLock(hDIB);    

    // Gets the "bits" from the bitmap and copies them into a buffer 
    // which is pointed to by lpbitmap.
    GetDIBits(hdcWindow, hbmScreen, 0,
        (UINT)bmpScreen.bmHeight,
        lpbitmap,
        (BITMAPINFO *)&bi, DIB_RGB_COLORS);

【问题讨论】:

  • 这是BITMAP bmpScreenBITMAPINFOHEADER bi,两者都需要。

标签: winapi gdi


【解决方案1】:

GetDIBits:

如果lpvBits参数是一个有效的指针,前六个成员 BITMAPINFOHEADER 结构必须初始化以指定大小 和DIB 的格式。扫描线必须在DWORD 上对齐 RLE 压缩位图除外。

【讨论】:

    猜你喜欢
    • 2016-12-24
    • 2011-11-21
    • 2021-09-13
    • 1970-01-01
    • 1970-01-01
    • 2018-08-26
    • 1970-01-01
    • 1970-01-01
    • 2012-11-23
    相关资源
    最近更新 更多