【发布时间】:2015-02-05 02:42:15
【问题描述】:
我正在尝试截取屏幕截图,然后通过它查看具有特定颜色的像素。首先,我尝试在某个 xy 坐标处打印图像的颜色,但我什至无法做到这一点。我做错了什么?
static int ScreenWidth;
static int ScreenHeight;
static Robot robot;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic
callibrateScreenSize();
findSquares();
//takeScreenShot();
try {
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void callibrateScreenSize() {
try {
Rectangle captureSize = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
ScreenWidth = captureSize.width;
ScreenHeight = captureSize.height;
System.out.println("Width is " + ScreenWidth);
System.out.println("Height is " + ScreenHeight);
} catch (Exception e) {
e.printStackTrace();
}
//return null;
}
public static BufferedImage takeScreenShot() {
Rectangle captureSize = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage image = robot.createScreenCapture(captureSize);
return image;
}
public static void findSquares() {
System.out.println(takeScreenShot().getRGB(5,5));
}
谢谢!
【问题讨论】:
-
你当前的代码有什么问题?
-
你得到什么输出?
-
对于输出,我得到了图片的尺寸,然后出现了错误
标签: java image pixel bufferedimage