Screen capture example
Thursday, August 25th, 2011
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
class ScreenCapture {
public static void main(String args[]) throws AWTException, IOException {
// Captures the image from the screen
BufferedImage screencapture = new Robot().createScreenCapture(
new Rectangle(Toolkit.getDefaultToolkit().getScreenSize())); //Gets the size of the screen
// Writes the File as a PNG
File file = new File("screencapture.png");//Saves your file in the project folder
ImageIO.write(screencapture, "png", file);
}
}
