2

I have an image and I want to see if the pixel that the mouse is on it is red or not to decide to do something in the following function, how can I find out that the pixel is red or not ?

$('#picture').mousemove(function(e) {} ;)
Navid777
  • 3,591
  • 8
  • 41
  • 69

1 Answers1

3

You can do this with canvas. Draw the image on a canvas, after that using getImageData method you can get the image's pixels. As last step calculate the right pixel where the mouse is located and check it's red value (you'll have the RGBA for the pixel).

Probably the most tricky part will be to find the right pixel but this shouldn't be a big issue. Use the relative mouse position for the canvas. You'll already know how big is the image so it'll be easy to find the pixel.

Minko Gechev
  • 25,304
  • 9
  • 61
  • 68