The following program shows how to get the color of a pixel in the screen. It is very simple program. You have to just use Robot.getPixelColor() method to do this. You have to just provide two variable to it for doing this. Just try to understand it.
Code:
package in.java.example.awt;
import java.awt.Color;
import java.awt.Robot;
import java.awt.AWTException;
public class ColorPickerEg {
public static void main(String[] args) {
try {
Robot robos = new Robot();
Color color = robos.getPixelColor(30, 30);
System.out.println("Yellow = " + color.getYellow());
System.out.println("Green = " + color.getGreen());
System.out.println("Red = " + color.getRed());
} catch (AWTException e) {
e.printStackTrace();
}
}
}
Bookmarks