我正在使用Robot类来截取桌面的截图:
Robot objRobot = null;
try {
objRobot = new Robot();
} catch(Exception ex) {
}
BufferedImage objBufferedImage = objRobot.createScreenCapture(objRectArea);
问题是当我的电脑被锁定时,图像会显示为黑色。也就是说,不捕获桌面上显示的内容。即使我的电脑被锁定,我也希望屏幕截图能够显示桌面。我怎样才能做到这一点?我更喜欢仍然使用机器人的解决方案。
答案 0 :(得分:0)
试试这个
public class Main {
private Robot robot = new Robot();
public Main() throws AWTException, IOException {
int x = 800;
int y = 800;
int width = 200;
int height = 200;
imageCapture(x, y, width, height);
}
private void imageCapture(int x, int y, int width, int height) throws IOException {
Rectangle area = new Rectangle(x, y, width, height);
BufferedImage bufferedImage = robot.createScreenCapture(area);
//remove next line if u do not want file.png saved
ImageIO.write(bufferedImage, "png", new File("file.png"));
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws AWTException, IOException {
new Main();
}/**
* @return the robot
*/
public Robot getRobot() {
return robot;
}
/**
* @param robot the robot to set
*/
public void setRobot(Robot robot) {
this.robot = robot;
}
}
使项目中的file.png也