PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

How use GetObject()  to access bits

roadkilldave · 04 Sep 2001, 07:58 UTC
Does anyone know how to take a bitmap handle and use getobject() to get to the bits of the bitmap. I am trying to use the bitblt code that Larry has in his GAPI demo, but he was passing a memory pointer to a resource to the bitblt. I emailed him and he said to use getobject with the HBITMAP but I can't figure it out.

Need some help, please?
Something like this:
[fixed]
HBITMAP hMyBitmap;

//Load your bitmap, etc.....

BITMAP bmp;
if (GetObject(hMyBitmap, sizeof(BITMAP), &bmp)) {
 //You can now directly access the bits through bmp.bmBits
} //else GetObject failed
[/fixed]

Dan East
Something you might want to look out for:  bmp.bmBits might be NULL.  I don't know if CE has this limitation but GetObject won't return a pointer to the bits on the Desktop unless the bitmap was created as a DIB section.  On the Desktop OS's you can use GetDIBits instead and get around this limitation.
That's true for CE.

Dan East
What I ended up doing was writing special case code that if bmBits were NULL:

- Create a temp DIB section of the same dimensions and color depth as the source bitmap.

- Create a memory DC via CreateCompatibleDC and select the source bitmap into the DC.

- Create another memory DC via CreateCompatibleDC and select the DIB section's HBITMAP into the DC.

- Use BitBlt and copy the source to the DIB section bitmap.

Since the DIB section has a pointer to the bits, you don't need to call GetObject at this point to retrieve the bits.

All of this is a pain in the butt and I've learned to keep my images in DIB form rather than bitmaps.  If you have the DIB you can always create a bitmap from them.  As you can see it's not so easy going the other way.