Why does GetObject return an BITMAP with null bmBits?

后端 未结 4 2219
南笙
南笙 2021-02-14 02:09

Context: I\'m trying to take a screenshot of another window to feed it into OpenCV. I found some code on the web that should be able to convert a BITMAP to something OpenCV can

4条回答
  •  暖寄归人
    2021-02-14 02:16

    Just for information. When loading bitmap from file and want to use BITMAP .bmBits (for glTexImage2D, glDrawPixels):

    LoadImage(NULL, "path_to.bmp", IMAGE_BITMAP, 0, 0,
                                           LR_LOADFROMFILE);
    

    u must specify flag LR_CREATEDIBSECTION

    HBITMAP hBmp = NULL;
    BITMAP BMp;
    hBmp = (HBITMAP) LoadImage(NULL, "bitmap.bmp", IMAGE_BITMAP, 0, 0,
                                           LR_LOADFROMFILE | LR_CREATEDIBSECTION);
    GetObject(hBmp, sizeof(BMp), &BMp);
    //BMp.bmBits now points to data
    

提交回复
热议问题