Jump to content
  • Advertisement
Sign in to follow this  
Kranar

CBitmap and CImage help

This topic is 4847 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

Hello, I am trying to write a program that takes a screen capture of a video game and analyzes the contents. To do this, the bitmap of the capture is saved into a GDI CBitmap. The problem I'm having is in extracting the pixel data from the CBitmap. It seems that since the bitmap is not device independent, I can not wrap attach the bitmap to a CImage in order to use CImage::GetPixel method. I am very stumped on this problem, the only way around it, is that I use CImage::Save method to save the screenshot into a .bmp file, then load the .bmp file. When the bitmap is saved, it's saved as a device independent bitmap, so when it's reloaded I am able to use CImage::GetPixel. It works, but it's really slow and it's probably a very terrible method to use. If anyone who is familiar with device dependent bitmaps and knows how I can extract individual pixels at exact coordinates from a CBitmap object, I'd appreciate all the help and info you can share.

Share this post


Link to post
Share on other sites
Advertisement
You can directly access the image data with CBitmap::GetBitmapBits but this is ugly and requires a lot of manual data conversion to get into a recognizable format. A more useful approach would be to select the bitmap into a device context with CDC::SelectObject() and then use CDC::GetPixel() and possibly CDC::BitBlt() on the device context itself. Note that you will have to paint a region of the device context with the selected bitmap first - just selecting it won't do anything. Be sure to CDC::CreateCompatibleDC() the new device context with the context the original bitmap was obtained from.

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!