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