[Win 32 API] Problem with GetPixel()

Started by
1 comment, last by Alload 22 years, 9 months ago
I have writen a small program which write on the screen the RGB value of a chosen pixel, but the program gives me an odd value. For exemple, if the pixel color is RGB(50, 100, 150) the program gives me 9856050. How can I get an RGB value? Here''s my code: #include #include using namespace std; /////////////////////////////////////////////////////////////////// int main() { HDC hdcImage; HBITMAP hbm; char szBitmap[] = "bitmap.bmp"; int x = 1024; int y = 768; long pixelvalue = 0; hbm = (HBITMAP) LoadImage(GetModuleHandle(NULL), szBitmap, IMAGE_BITMAP, x, y, LR_CREATEDIBSECTION); if (hbm == NULL) hbm = (HBITMAP) LoadImage(NULL, szBitmap, IMAGE_BITMAP, x, y, LR_LOADFROMFILE | LR_CREATEDIBSECTION); hdcImage = CreateCompatibleDC(NULL); SelectObject(hdcImage, hbm); pixelvalue = GetPixel(hdcImage, 1, 1); cout << pixelvalue << endl; while (1) { } return 0; }
Advertisement
After you use GetPixel you need to use GetRValue, GetBValue, and GetGValue to extract the individual color components. You could always mask it to get the values too, but that's a bit of a pain .

Edited by - The Senshi on June 20, 2001 4:55:10 PM
Why would you think that''s a weird value?

cout << RGB(50, 100, 150) << endl;

alse gives 9856050.

What were you expecting?

-Mike
-Mike

This topic is closed to new replies.

Advertisement