Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting a bitmap pixel color

Status
Not open for further replies.

cello1000

Programmer
Jul 23, 2003
3
US
I have a CBitmap object that has loaded an image. How can I get or set the color of a specific pixel?
 
There are lots of places to look on the web for file formats; the specs for the MS bmp bitmap can be found at for one. Note that even for something as simple as a bmp you have to do a lot of file decoding before you can get one pixel information; you have to take into account the color depth of the bitmap, whether it's palletized, x/y extents, etc, etc. You may be able to locate code that will do it; I've always just "grown my own".
 
Or, you can blit the bitmap to an offscreen DC and call GetPixel on it.

I REALLY hope that helps.
Will
 
Right after posting this I realized I could do what you suggested apatterno, but the question is, how can I set the color of a pixel? I can use CDC::SetPixel to set it on the DC, but that won't change it on the bitmap itself, will it? It seems like Microsoft would/should have made something like this fairly easy.
 
Oops...cello1000 is a friend of mine and I posted this at his house under his name...but I'm the one who made this topic. Anyway, is there a way to get a DC's image as a bitmap?
 
>is there a way to get a DC's image as a bitmap?

The DC's image is a bitmap.
- Which bitmap?
- The bitmap that is selected into it.

/Per
Nerdy signatures are as lame as the inconsistent stardates of STTNG.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top