Java 获取鼠标所在位置的像素颜色?
因此,我的程序的一部分要求我获取鼠标在JFRAME中的任何位置的RGB值。但它不起作用,我也不完全确定我用于getPixelColor的x,y坐标是否为我提供了屏幕中这些坐标的颜色,而不是jframe。获取Jframe中鼠标所在位置的颜色的最佳方法是什么Java 获取鼠标所在位置的像素颜色?,java,swing,jframe,mouseevent,Java,Swing,Jframe,Mouseevent,因此,我的程序的一部分要求我获取鼠标在JFRAME中的任何位置的RGB值。但它不起作用,我也不完全确定我用于getPixelColor的x,y坐标是否为我提供了屏幕中这些坐标的颜色,而不是jframe。获取Jframe中鼠标所在位置的颜色的最佳方法是什么 public void mouseMoved(MouseEvent e) { // check the color of the pixel the the mouse is over, and
public void mouseMoved(MouseEvent e) {
// check the color of the pixel the the mouse is over, and
// go to the next level, or show the game over screen
Robot robot = null;
try {
robot = new Robot();
} catch (AWTException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
int xcord = e.getX();
int ycord = e.getY();
Color color = robot.getPixelColor(xcord, ycord);
System.out.println(color);
}
为了更快地获得更好的帮助,请发布一个(最简单的完整且可验证的示例)。顺便说一句-这的最终目的是什么?是将颜色显示为工具提示的示例。