public class PrtSc {
public static void main(String[] args) {
PrtSc.run();
}
public static void run() {
// 获取截图的大小
Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
try {
// java自动化类
Robot robot = new Robot();
// 创建输出
OutputStream out = new FileOutputStream(new File("image.gif"));
// 截图
BufferedImage image = robot.createScreenCapture(screenRect);
// 保存为gif
ImageIO.write(image, "gif", out);
System.out.println("ok...");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}