java实现截图功能
java实现截图/录屏
public static void main(String[] args) throws InterruptedException {
//截取整个屏幕 保存在H盘下,名字为当前时间毫秒值 格式为png
Test().screenShotAsFile(0,0,1920,1080, "H:\\", String.valueOf(System.currentTimeMillis()), "png");
}
/**
* 指定屏幕区域截图,保存到指定目录
* @param x
* @param y
* @param width
* @param height
* @param savePath - 文件保存路径
* @param fileName - 文件保存名称
* @param format - 文件格式
*/
public static void screenShotAsFile(int x, int y, int width, int height, String savePath, String fileName, String format) {
try {
Robot robot = new Robot();
BufferedImage bfImage = robot.createScreenCapture(new Rectangle(x, y, width, height));
File path = new File(savePath);
File file = new File(path, fileName+ "." + format);
ImageIO.write(bfImage, format, file);
} catch (AWTException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
https://www.xp.cn/b.php/53844.html 参考链接