Java如何获取屏幕像素的颜色?
此处的示例向我们展示了如何获取屏幕上像素的颜色。我们使用该Robot.getPixelColor(intx,inty)方法获得Color像素的。
package org.nhooo.example.awt; import java.awt.Color; import java.awt.Robot; import java.awt.AWTException; public class ColorPickerDemo { public static void main(String[] args) { try { Robot robot = new Robot(); //20、20处的像素颜色信息 Color color = robot.getPixelColor(20, 20); //打印像素颜色的RGB信息 System.out.println("Red = " + color.getRed()); System.out.println("Green = " + color.getGreen()); System.out.println("Blue = " + color.getBlue()); } catch (AWTException e) { e.printStackTrace(); } } }