Question

I'm making a color picker on C#, and I want that the GetPixel function, capture all my windows, so I can use to capture any color on my windows, no matters what window is it, (E-mail, image or anything else).

How can I do that?

I have a pictureBox to put the color in.

Was it helpful?

Solution

This blog post seems to offer a solution. In essence you run the following code to get the color from wherever the mouse is on the screen:

IntPtr hdc = GetDC(IntPtr.Zero);
uint pixel = GetPixel(hdc, currentPoint.X, currentPoint.Y);
ReleaseDC(IntPtr.Zero, hdc);
Color color = Color.FromArgb((int)(pixel & 0x000000FF),
    (int)(pixel & 0x0000FF00) >> 8,
    (int)(pixel & 0x00FF0000) >> 16);

I'm not sure how much I should copy up here, but if you download the source code from that page, it should answer a bunch of your questions.

And, if that does not work, take a look at this answer: https://stackoverflow.com/a/1483963/1043380

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top