一、前言
整理笔记的时候看到个抓屏的代码,当时也不知道用到哪里,分享给大家
一、相关代码
public static void captureScreen(String fileName) throws Exception {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle screenRectangle = new Rectangle(screenSize);
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(screenRectangle);
ImageIO.write(image, "jpeg", new File(fileName));
}
二、测试示例
public static void main(String... args) throws Exception{
String filename="D:\\test.jpeg";
captureScreen(filename);
}