Pin It

How to get color of a Screen through Robot class in Java ?

A simple program to demonstrate capturing of pixel colors of screen in Java

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) {



Output of the program :

Please Give Us Your 1 Minute In Sharing This Post!
Related Posts Plugin for WordPress, Blogger...
© 2012 Learn Java by Examples Template by Hubber Spot