/**
* 截图函数,并返回最终截图文件
* @param fileName
* @param format
*/
public static File screenShotAsFile( String fileName, String format) {
String savePath = "C:\\watch_pic"; //文件保存路径
File resultPath = null;
try {
Robot robot = new Robot();
BufferedImage bfImage = robot.createScreenCapture(new Rectangle(0, 0, 1920, 1024)); //获得截图
File path = new File(savePath);
path.mkdirs(); //创建保存的文件夹
File file = new File(path, fileName+ "." + format);
resultPath = file;
ImageIO.write(bfImage, format, file);
} catch (AWTException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return resultPath;
}
java中截图功能
最新推荐文章于 2023-08-10 17:49:19 发布