-2

I was wondering if it was possible to get the color at the position of the mouse cursor (something like a color picker). While the program is running it should get the mouse cursor position and the color at that same position on the screen.

SenaCarbtc
  • 111
  • 1
  • 14
  • Possible duplicate of [How to read the Color of a Screen Pixel](https://stackoverflow.com/questions/1483928/how-to-read-the-color-of-a-screen-pixel) – Jim G. May 11 '18 at 21:28
  • Which client-side technology are you using? – Jim G. May 11 '18 at 21:29
  • @JimG. that actually can be the right solution, i don't have a computer rn to test it but ill check and will get back to you. I'm using c# with a browser for the current example. You know of a good online compiler that can give me an executable ? :) (but not visual studio xD) – SenaCarbtc May 11 '18 at 21:31

2 Answers2

0

To get what you want:

First use:

Mouse.Position

Then use

Bitmap.GetPixel

and give it X and Y from the mouse position.

Here's a question with code examples.

Liquid Core
  • 1
  • 5
  • 20
  • 43
  • 1
    `Bitmap.GetPixel` is completely inappropriate here, unless you are taking a screenshot of the entire screen at some interval, storing it in the bitmap, and getting the pixel color. – Ron Beyer May 11 '18 at 21:20
  • 1
    @RonBeyer You're inappropriate. Try to document yourself if you're going to make a critic. That's how you do it in C#. Screenshot and pixel color. Added some more to help the guy – Liquid Core May 11 '18 at 21:25
0

Say we have a form.

Say we have a pictureBox docked to fill the entire form.

We can use the MouseClick event of the pictureBox Control to get the position of the mouse.

Then cast the image of the pictureBox to Bitmap Then Call GetPixel() on it which returns a color, then .Name on it.

private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
    Bitmap bit = new Bitmap(pictureBox1.Image);
    MessageBox.Show(bit.GetPixel(e.X, e.Y).Name);
}
Zohir Salak
  • 5,738
  • 2
  • 9
  • 23
  • This would work if i had a picturebox, i need my program to run somewhat in the background and get the colors from the screen not from a picturebox – SenaCarbtc May 11 '18 at 21:54
  • Well i used `picturebox` to explain it to you, it's all about the `Bitmap ` – Zohir Salak May 11 '18 at 22:02