开发者

Why is this Robot code to take a screenshot not working when the computer is locked?

I am using the Robot class to take a screenshot of the desktop:

Robot objRobot = null;
try {
    objRobot = new Robot();
} catch(Exception ex) {
}
BufferedImage objBufferedImage =  objRobot.createScreenCapture(objRectArea);  

The problem is that when my computer is locked the image comes up as black. That is, what is displayed on the desktop is not captured. I wa开发者_如何转开发nt the screenshot to display the desktop even when my computer is locked. How can I do this? I would prefer a solution that still uses Robot.


Try this

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


    }

Makes file.png in project too

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜