Jump to content
  • Advertisement

Archived

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

Alload

[Win 32 API] Problem with GetPixel()

This topic is 6300 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!