Skip to main content
GameDev.net gamedev.net
🔒 Locked

CBitmap and CImage help

Started by Kranar Jun 13, 2005 at 10:56 AM 0 replies 2.6k views
Original Post
Kranar
Kranar
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.
ApochPiQ
ApochPiQ
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.