How to get the color of a pixel on the screen in JAVA 2D game?

Asked

Viewed 551 times

2

Was there any way How to get the color of a Pixel on the x and y coordinates of the screen I specify?

  • Swing? Android? Browser?

  • Ops It’s with Jframe for Desktop

1 answer

0


A little vague your question, but try to use:

       package teste2;

       import java.awt.Color;
       import java.awt.Robot;

       public class teste {

      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());
      }



            }
  • But how can I print this? I tried System.out.println(getPixelColor(100,100)); but of error

  • I’m going to do a test here. Wait!

  • See if that’s what you need??

  • I believe that by putting the colors with the Color function you will achieve through the RGB;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.