Get the colour of a screen pixel in Java

Description

The following code shows how to get the colour of a screen pixel.

Example


//from  w w w .  ja  va2  s . c o  m
import java.awt.Color;
import java.awt.Robot;

public class Main {
  public static void main(String[] args) throws Exception{
    Robot robot = new Robot();

    Color color = robot.getPixelColor(20, 20);

    System.out.println("Red   = " + color.getRed());
    System.out.println("Green = " + color.getGreen());
    System.out.println("Blue  = " + color.getBlue());
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Development »




Java Algorithms
Java Clipboard
Java Compiler
Java Desktop
Java Virtual Machine
Java Math
OS
Random
Java Robot
Java RuntimeMXBean
Java Timer
Java UUID
Java Internationalization