-1

I'm trying to display the position of the cursor and get the red, blue and green colors of each pixel of an image. My image is on a JPanel. Below is part of my code

imagePanel.addMouseMotionListener(handler);

And then further :

public void mouseMoved(MouseEvent arg0){
System.out.println("cursor at : "+arg0.getX()+" , "+arg0.getY());
}

How can I get the RGB values by adding code in the previous function ?

  • possible duplicate of [Need Faster way to get RGB value for each Pixel of a Buffered Image](http://stackoverflow.com/questions/10088465/need-faster-way-to-get-rgb-value-for-each-pixel-of-a-buffered-image) – ug_ Jan 08 '15 at 23:46
  • Consider providing a [runnable example](https://stackoverflow.com/help/mcve) which demonstrates your problem. This will result in less confusion and better responses – MadProgrammer Jan 09 '15 at 00:03
  • Depending on what you are trying to do and how you've set it up, you could use something like [this](http://stackoverflow.com/questions/13061122/getting-rgb-value-from-under-mouse-cursor/13061320#13061320) or [this](http://stackoverflow.com/questions/21444587/getting-pixel-rgb-from-a-bufferedimage-from-the-mouses-x-and-y-possition/21445320#21445320) – MadProgrammer Jan 09 '15 at 00:04

1 Answers1

0

Why you cannot translate getX() and getY() to image coordinates and get the pixel value?

darkled
  • 257
  • 2
  • 11