使用机器人类的 Java 屏幕捕获
我使用机器人类来捕获并将文件保存在 xp 中的 C: 驱动器上。它工作正常,但是当与 Windows 7 一起使用时,我收到异常,说访问被拒绝,使用本机方法访问文件。
是因为我使用的是 C: 驱动器而不是系统 tmp 目录还是其他什么? 我没有 Windows 7 来测试它,这就是为什么问。
代码是这样的:
Dimension screenSize;
Rectangle screenRectangle;
BufferedImage image;
for (int i=0; i<j; i++){
img[i] = "C:\\"+(i+1)+".jpg"; //e.g 1.jpg saved in C: drive on 1st itr.
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
screenRectangle = new Rectangle(screenSize);
image = robot.createScreenCapture(screenRectangle);
ImageIO.write(image, "jpg", new File(img[i]));
}
I use robot class to take capture and save the file on C: drive in xp. It works fine, but when used with windows 7 i get exception saying access denied, accessing file using native method.
Is it because i am using C: drive and not the system tmp directory or something else?
I do not have windows 7 to test it here, thats why asking.
Code is something like this:
Dimension screenSize;
Rectangle screenRectangle;
BufferedImage image;
for (int i=0; i<j; i++){
img[i] = "C:\\"+(i+1)+".jpg"; //e.g 1.jpg saved in C: drive on 1st itr.
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
screenRectangle = new Rectangle(screenSize);
image = robot.createScreenCapture(screenRectangle);
ImageIO.write(image, "jpg", new File(img[i]));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Windows 7 中根目录的写入权限默认处于关闭状态。您可以将代码更改为
img[i] = (i+1)+".jpg";
以便写入屏幕 -将图像捕获到启动 jvm 的同一目录中。
Write permissions for the root directory are by default off in Windows 7. You can change your code to
img[i] = (i+1)+".jpg";
in order to write your screen-capture images to the same directory from which you launched the jvm.