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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LoadImage then SelectObject doesn't give correct GetPixel values.

Status
Not open for further replies.

whojoedaddy

Programmer
Jun 10, 2005
4
US
Hi All, the simple code below doesn't seem to work. I'm trying to load a bitmap into a HDC and then check the pixel values in the HDC. It seem no matter where I do GetPixel it always comes back with 255. The image has varying colors, none of them 255, 255, 255. Any thoughts? I am not trying to load the values into the display (not yet anyway).

HDC hMemDC = CreateCompatibleDC(NULL);
HBITMAP hbmNewBitMap = (HBITMAP) LoadImage(NULL, "c:\\1.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
SelectObject(hMemDC, hbmNewBitMap);

COLORREF Color = GetPixel(hMemDC, 100, 100);
unsigned int R = GetRValue(Color);
unsigned int G = GetGValue(Color);
unsigned int B = GetBValue(Color);
 
I'm an idiot. Turns out I was using a hardcoded value of GetPixel instead of the dynamic parameter.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top