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]));
}
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.
精彩评论