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

ReturnPixel function alwyas returns false

Status
Not open for further replies.

Roboticguy2

Programmer
Feb 21, 2004
2
US
I have a function which, when called, is supposed to return TRUE if the pixel in the filename specified is black, of FALSE if white. The problem if that the function always returns false. Here's the code.

BOOL returnpixel(char* fileName,int x, int y, HWND hwnd)
{
BOOL returnValue = TRUE;
HBITMAP letterTest = NULL;
HDC hdc;
letterTest = LoadImage(GetModuleHandle(NULL),fileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
if(letterTest=NULL)
MessageBox(NULL, "Unable to load file!", "Error", MB_OK);
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbmOld=SelectObject(hdcMem,letterTest);
COLORREF letterColor = GetPixel(hdcMem,x,y);
if(GetRValue(letterColor) == 0 && GetGValue(letterColor) == 0 && GetBValue(letterColor) == 0)
returnValue = TRUE;
if(GetRValue(letterColor) == 255 && GetGValue(letterColor) == 255 && GetBValue(letterColor) == 255)
returnValue = FALSE;
SelectObject(hdcMem,hbmOld);
DeleteObject(letterTest);
DeleteDC(hdc);
return returnValue;
}
 
it meane this piece of code:
(GetRValue(letterColor) == 255 && GetGValue(letterColor) == 255 && GetBValue(letterColor) == 255)
always is evaluted as true. All you should do is to see why...

Ion Filipski
1c.bmp
 
Exactly, I thought that was the problem, but I don't know how to fix it. I've already checked to see if the image was loading correctly, but that wasn't the case. The image also has some black in it, so it can't be that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top