I would like, in Java, to scan the screen for a particular color.
Any idea how to do that?
Depending on the configuration of the machine, a scanner can produce images that are black and white or color. In a color scanner the digital color image consists of three gray-scale images. These images are often called layers.
Robot robot = new Robot();
Rectangle captureSize = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage bufferedImage = robot.createScreenCapture(captureSize);
// ...
int color = image.getRGB(x, y);
int red = (color & 0x00ff0000) >> 16;
int green = (color & 0x0000ff00) >> 8;
int blue = color & 0x000000ff;
// ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With