tags:

views:

132

answers:

2

Hey,

I would like java to scan screen for particular color.

Any ideas if how to do that?

Thanks

+2  A: 

Use Java.awt.Robot to take a screenshot as an Image and proceess that.

Thorbjørn Ravn Andersen
+11  A: 
    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;
    // ...
Romain Hippeau
color or colour?
Reuben Mallaby
@Reuben Mallaby The joys of cut and paste. color, you are finding the r g and b values from the color. I updated my post
Romain Hippeau
You should tell _why_ the doctor should be called...
Thorbjørn Ravn Andersen
@Thorbjørn Ravn Andersen - To fix the Robot
Romain Hippeau
Romain, "_why_" refers to you swallowing the exception instead of doing an `e.printStackTrace()`.
Thorbjørn Ravn Andersen