Page 1 of 1

How use GetObject()  to access bits

PostPosted: Sep 4, 2001 @ 8:58am
by roadkilldave
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.<br><br>Need some help, please?

Re: How use GetObject()  to access bits

PostPosted: Sep 4, 2001 @ 12:02pm
by Dan East
Something like this:<br>[fixed]<br>HBITMAP hMyBitmap; <br><br>//Load your bitmap, etc.....<br><br>BITMAP bmp;<br>if (GetObject(hMyBitmap, sizeof(BITMAP), &bmp)) {<br>  //You can now directly access the bits through bmp.bmBits<br>} //else GetObject failed<br>[/fixed]<br><br>Dan East

Re: How use GetObject()  to access bits

PostPosted: Sep 4, 2001 @ 12:27pm
by Digby
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.

Re: How use GetObject()  to access bits

PostPosted: Sep 4, 2001 @ 12:40pm
by Dan East
That's true for CE.<br><br>Dan East

Re: How use GetObject()  to access bits

PostPosted: Sep 4, 2001 @ 1:05pm
by Digby
What I ended up doing was writing special case code that if bmBits were NULL:<br><br>- Create a temp DIB section of the same dimensions and color depth as the source bitmap.<br><br>- Create a memory DC via CreateCompatibleDC and select the source bitmap into the DC.<br><br>- Create another memory DC via CreateCompatibleDC and select the DIB section's HBITMAP into the DC.<br><br>- Use BitBlt and copy the source to the DIB section bitmap.<br><br>Since the DIB section has a pointer to the bits, you don't need to call GetObject at this point to retrieve the bits.<br><br>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.<br><br>