[英]Is it possible to programmatically take a screenshot while the computer is locked?
[英]Why is this Robot code to take a screenshot not working when the computer is locked?
我正在使用Robot類拍攝桌面截圖:
Robot objRobot = null;
try {
objRobot = new Robot();
} catch(Exception ex) {
}
BufferedImage objBufferedImage = objRobot.createScreenCapture(objRectArea);
問題是,當我的計算機被鎖定時,圖像顯示為黑色。 即,不會捕獲桌面上顯示的內容。 我希望屏幕截圖即使在計算機鎖定時也能顯示桌面。 我怎樣才能做到這一點? 我希望仍然使用機器人的解決方案。
嘗試這個
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.