Convert HBITMAP to byte array

I am working with some scanning api that returns a HANDLE to a BMP image (as the documentation says). I am trying to somehow get BITMAP from this descriptor, but for example this code does not work:

HANDLE handle = getHandleFromScanner();
BITMAP bitmap;
int u = GetObject(handle, sizeof(BITMAP), &bitmap);

u is 0, and getLastError () returns 6, which means that the handle is invalid. But I can not get any other descriptor than a function getHandleFromScanner().

Could there be some conversions with this descriptor? any ideas? What is the correct way to work with raster handles? Or does any simple api exist? Samples found with google did not help me.

Many thanks.

+3
source share
2

, .

, :

char* pImage = NULL;
HANDLE hImage= getHandleFromScanner();
pImage = (char *)GlobalLock(hImage);
// pImage now contains the bytes of the image

- , - Olivetti PR2 plus.

+1

GetDIBits()? , . GetObjectType() , , HBITMAP.

+2

Source: https://habr.com/ru/post/1773866/


All Articles