问题
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