Roboticguy2
Programmer
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;
}
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;
}