CBitmap and CImage help

Started by
0 comments, last by ApochPiQ 18 years, 10 months ago
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.
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.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

This topic is closed to new replies.

Advertisement