java.awt.Robot
createScreenCapture
public BufferedImage createScreenCapture(Rectangle screenRect)
Creates an image containing pixels read from the screen. Parameters:
screenRect - Rect to capture in screen coordinates
Returns:
The captured image
Throws:
IllegalArgumentException - if screenRect width and height are not greater than zero
SecurityException - if readDisplayPixels permission is not granted
See Also:
SecurityManager.checkPermission(java.security.Permission), AWTPermission
createScreenCapture
public BufferedImage createScreenCapture(Rectangle screenRect)
Creates an image containing pixels read from the screen. Parameters:
screenRect - Rect to capture in screen coordinates
Returns:
The captured image
Throws:
IllegalArgumentException - if screenRect width and height are not greater than zero
SecurityException - if readDisplayPixels permission is not granted
See Also:
SecurityManager.checkPermission(java.security.Permission), AWTPermission
Dimension screenSize = toolkit.getScreenSize();
Rectangle screenRect = new Rectangle(screenSize); try {
File fileout = new File(docroot.getPath() + "/screen.jpg"); if (fileout.exists()) {
fileout.delete();
} Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(screenRect);
ImageIO.write(image, "jpg", fileout);
}
catch(AWTException e) {
System.err.println(e.toString());
}
catch(IOException e) {
System.err.println(e.toString());
}