Jump to content
  • Advertisement
Sign in to follow this  
Verg

Get Screen bits using GDI (Win32)

This topic is 4617 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm currently using GetPixel to read a piece of the screen (actually, the background of a button) so it can be used for alpha-blending. GetPixel returns a COLORREF (DWORD)... but I suppose it would fail if the screen res were set to 16, 15, or 8. What would be a better way of capturing the screen bits, using GDI? I'd rather not use DirectX, to keep the app as backwardly compatible as possible. -------------- I've tried this sequence...
CreateCompatibleDC             // Create the compatible DC
CreateCompatibleBitmap         // Create a DDB
SelectObject                   // Select the DDB into the compatible DC
BitBlt                         // BitBlt the original DC to the compatible
GetBitmapBits                  // Get the bits from the DDB
...but there was no Bitmap selected into the original DC when the button's background was drawn. Should there be? Or is there a still better way (using GDI)? Thank you for your help and suggestions, and Greetings Chad

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
If a pixel's there, a pixel's there. Don't see why GetPixel shouldn't work for all situations provided that you're passing the right coordinates.

Share this post


Link to post
Share on other sites
GetPixel will do any necessary conversions. You'll get back a valid COLORREF regardless of the color depth of the screen.

I don't understand what you're asking in the second half of you post. That's the right sequence to blt to a local bitmap.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anon Mike
GetPixel will do any necessary conversions. You'll get back a valid COLORREF regardless of the color depth of the screen.

I don't understand what you're asking in the second half of you post. That's the right sequence to blt to a local bitmap.


Good to know. MSDN does say "GetPixel" may not be supported by all devices, and then it goes on about checking "GetDeviceCaps" ... but the docs on GetDeviceCaps don't say anything about GetPixel.

The second part was a different approach to getting the screen bits.

If a DDB is selected into a Device Context before drawing a button, would that DDB contain the screen bits?

Thanks for your reply... & ++rate.


Chad

Share this post


Link to post
Share on other sites
Not necessarily, no. The representation of a compatible bitmap is up to the device, mostly. Color depth, type of device, and the alignment of the planets (i.e. developer whims) may all contribute to the format of a DDB. Since a device context is only guaranteed to be compatible with a particular device, it may not be compatible with the screen at all. So it isn't guaranteed that an arbitrary DC will hold screen-compatible device bitmaps, in general.

A device independent bitmap (DIB), however, should hold what you want. There's a family of API calls for mucking around with DIBs, and converting them from device-compatible bitmaps. Most notably, GetDIBits. GetDIBits will probably be a hair more efficient than batch operations with GetPixel if you're working with more than a handful of pixels.

Share this post


Link to post
Share on other sites
Quote:
Original post by ApochPiQ
Not necessarily, no. The representation of a compatible bitmap is up to the device, mostly. Color depth, type of device, and the alignment of the planets (i.e. developer whims) may all contribute to the format of a DDB. Since a device context is only guaranteed to be compatible with a particular device, it may not be compatible with the screen at all. So it isn't guaranteed that an arbitrary DC will hold screen-compatible device bitmaps, in general.

A device independent bitmap (DIB), however, should hold what you want. There's a family of API calls for mucking around with DIBs, and converting them from device-compatible bitmaps. Most notably, GetDIBits. GetDIBits will probably be a hair more efficient than batch operations with GetPixel if you're working with more than a handful of pixels.


Thank you for that thorough explanation...

And this looks like it answers questions about "GetPixel"
Google

Apparently, then, GetPixel always works on display devices...

And it really is just a handful of pixels... 256 at a time (16x16)


Chad

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!