Java Robot Class | Get the pixel Color of a given point Last Updated : 14 Apr, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report Robot is part of java.awt package . Robot class is basically used to generate native system input events for the purposes of self- running demos, test automation, and other application where control over mouse and keyboard is used. Robot class generates events that can be used to control mouse, keyboard and can be used to take screenshot of the screen. In this article we will discuss how to get the pixel color of the point on the screen mentioned by the user.Method used : getPixelColor(int x, int y) This function returns an object of the color class of the given screen coordinates. In the following program we will print a label that will contain the RGB values of the pixel entered and the text of the label will be of the pixel Color Java // Java program to get the pixel color of // given screen coordinates import java.awt.*; import javax.swing.*; import java.awt.event.*; public class color extends JFrame implements ActionListener { // textfield to get x, y coordinates static JTextField x, y; // button static JButton b; // create a frame static JFrame f; // label static JLabel l; public static void main() { // create a frame f = new JFrame("pixel Color"); // label to show the RGB value l = new JLabel("no value"); // create the text field x = new JTextField(16); y = new JTextField(16); // create a button b = new JButton("find"); // create an object of the class color co = new color(); // add ActionListener b.addActionListener(co); // create a panel JPanel p = new JPanel(); // add textfield and button to the panel p.add(x); p.add(y); p.add(b); p.add(l); // add the panel f.add(p); // set the size of the frame f.setSize(500, 500); f.show(); } // if the button is pressed public void actionPerformed(ActionEvent e) { String s = e.getActionCommand(); if (s.equals("find")) { int xp, yp; // get user inputs of x and y position xp = Integer.parseInt(x.getText()); yp = Integer.parseInt(y.getText()); // try and catch block to handle exceptions try { // create an object of robot class Robot r = new Robot(); // get the pixel color c = r.getPixelColor(xp, yp); } catch (Exception evt) { // print error message System.err.println(evt.getMessage()); } Color c; // set the RGB value to the label // and to its foreground l.setForeground(c); l.setText("Red = " + c.getRed() + ", Green = " + c.getGreen() + ", Blue = " + c.getBlue()); } } } Output : Note : the following program might not run in an online compiler please use an offline IDE. Comment More infoAdvertise with us Next Article Image Processing in Java - Read and Write A andrew1234 Follow Improve Article Tags : Java Programming Language Practice Tags : Java Similar Reads Image Processing In Java - Get and Set Pixels Prerequisite - Image Processing in Java - Read and Write In this set, we will learn about the pixels of images, how we can get pixel values of an image and how to set pixel values in an image using Java programming language. Pixels are the smallest unit of an image which consists of four components 3 min read Image Processing in Java - Creating a Random Pixel Image Prerequisites: Image Processing in Java - Read and WriteImage Processing In Java - Get and Set PixelsImage Processing in Java - Colored Image to Grayscale Image ConversionImage Processing in Java - Colored Image to Negative Image ConversionImage Processing in Java - Colored to Red Green Blue Image C 2 min read JavaFX | ColorInput Class ColorInput class is a part of JavaFX. It is used to create an effect which renders a rectangular region, filled with the given Color. It is equivalent to rendering a filled rectangle into an image and using an ImageInput effect, except that it is more convenient and potentially much more efficient. 4 min read Image Processing in Java - Comparison of Two Images Prerequisites: Image Processing in Java - Read and WriteImage Processing In Java - Get and Set PixelsImage Processing in Java - Colored Image to Grayscale Image ConversionImage Processing in Java - Colored Image to Negative Image ConversionImage Processing in Java - Colored to Red Green Blue Image C 4 min read Image Processing in Java - Read and Write Java implements a particular type of object called a BufferedImage for images in Java. A BufferedImage can be read from several distinct image types (i.e., BMP, HEIC, etc.). Not all of these are backed by ImageIO itself, but there are plugins to extend ImageIO and other libraries such as Apache Imag 3 min read How to Fill Background Color of Cells in Excel using Java and Apache POI? Apache POI is an open-source java library to create and manipulate various file formats based on Microsoft Office. Using POI, one should be able to perform create, modify and display/read operations on the following file formats. For Example, Java doesnât provide built-in support for working with ex 3 min read Like