Get Pixel Color on screen Java?

允我心安 提交于 2019-12-01 23:50:24
D.Kastier

The problem is the way you are getting the coordinates - e.getX() and e.getY() -, because they are relative to the JFrame (the up-left corner of the JFrame is (0,0)).

To get the coordinates of the pixel, use:

public void mouseClicked(MouseEvent e) {
    Point p = e.getLocationOnScreen();

    System.out.println("Pixel:" + p.x + "," + p.y);
    try {
        System.out.println(getPixel(p.x, p.y));
    } catch (AWTException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

}

[Extra] read this to improve other things: Why is my mouse lagging when I run this small mouse hook application?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!