为什么当计算机锁定时,用于截取屏幕截图的机器人代码不起作用?

发布于 2024-11-09 03:06:06 字数 318 浏览 3 评论 0原文

我正在使用 Robot 类来截取桌面屏幕截图:

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

问题是当我的计算机锁定时,图像显示为黑色。也就是说,桌面上显示的内容不会被捕获。即使我的计算机被锁定,我也希望屏幕截图显示桌面。我该怎么做?我更喜欢仍然使用 Robot 的解决方案。

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 want 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帅哥哥的热头脑 2024-11-16 03:06:06

试试这个

    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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文