开发者

converting HBITMAP to byte array

I'm working with some scanner api which returns a HANDLE to an image in BMP format(so it is said so in documentation). I'm trying to somehow get BITMAP from this handle, but for example this code doesn't work:

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

u is 0 here and getLastError() returns 6 which means that handle is invalid. But I cannot get any other handle except through getHandleFromScanner() function.

May be some transformations 开发者_StackOverflow社区should be done with this handle? any ideas? What is the proper way to work with bitmap handles? Or any simple api exists? Samples I found via google didn't help me.

Thanks a lot.


Have you tried GetDIBits()? This should work but you'll need the device context as well. You may always want to call GetObjectType() on the handle to see if it is really returning an HBITMAP.


Thanks guys.

The handle appeared to be the image itself, so the following code solved the problem:

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

If someone will ever need it, the Scanner is Olivetti PR2 plus scanner.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜