A simple program to demonstrate capturing of pixel colors of screen in Java
Output of the program :
package com.hubberspot.example; import java.awt.AWTException; import java.awt.Color; import java.awt.Robot; public class RobotColorDemo { public static void main(String[] args) { try { // Create a Robot object Robot robot = new Robot(); // Robot class has method getPixelColor which takes // two parameters as (x,y) x for X position of pixel // and y for Y position of pixel and it returns back // refernce to object of Color which is stored in color Color color = robot.getPixelColor(100, 100); // Color class has methods such as getRed() , getGreen() // and getGreen() and getBlue() method which prints RGB // information of the pixel color System.out.println("Red color of pixel = " + color.getRed()); System.out.println("Green color of pixel = " + color.getGreen()); System.out.println("Blue color of pixel = " + color.getBlue()); } catch (AWTException e) { e.printStackTrace(); } } }
Output of the program :