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();
	}
}

}

posted on 2017-11-05 20:10  喝一杯茶  阅读(1425)  评论(0编辑  收藏  举报