Skip to content

Instantly share code, notes, and snippets.

@64lines
Created December 23, 2013 05:19
Show Gist options
  • Save 64lines/8092042 to your computer and use it in GitHub Desktop.
Save 64lines/8092042 to your computer and use it in GitHub Desktop.
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.ImageIO;
public class Capture {
public static void captureScreen(String fileName) throws Exception {
Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
Rectangle screenRectangle = new Rectangle(screenSize);
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(screenRectangle);
ImageIO.write(image, "png", new File(fileName));
}
public static void main(String[] args) {
try {
JFileChooser fc = new JFileChooser();
int i = 0;
while(true){
System.out.println("[ Captura " + (i+1) + "]");
Thread.currentThread().sleep(5 * 1000);
String FILENAME = "D:/captura" + i + ".png";
Capture.captureScreen(FILENAME);
System.out.println("[ Captura finalizada ]");
i++;
}
}
catch(Exception e){
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment