Archived

This topic is now archived and is closed to further replies.

Alload

[Win 32 API] Problem with GetPixel()

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Why would you think that''s a weird value?

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

alse gives 9856050.

What were you expecting?

-Mike

Share this post


Link to post
Share on other sites