awtrobot reads incorrect colors

萝らか妹 提交于 2019-12-07 16:10:16

问题


I'm looking for a platform-independent way to read colors from the screen and simulate user input through mouse and keyboard actions. I have previously been using java.awt.robot, however some time in the past 2 years it has started reporting incorrect colors in OSX (other operating systems appear to get accurate colors) as noted in this question.

I'm looking for either a workaround for this bug or any other library/language which will provide this functionality.

Using the fairly simple code below can demonstrate the issue.

public void printColorAtCoordinate(int x, int y)
{
    Color color;
    color = robot.getPixelColor(x, y);
    System.out.println("RGB: " + Integer.toHexString(color.getRGB()));
}

It appears to get some colors correct, such as 0x000000, 0xffffff, 0x0000ff, 0xff0000 but not others such as 0x00ff00, which it reports as ff22ff00 (instead of ff00ff00). Most colors are off by at least a small amount.

来源:https://stackoverflow.com/questions/8479548/awtrobot-reads-incorrect-colors

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