Java截取屏幕

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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, "png", new File(fileName));
}
public static void main(String[] args) {
try {
captureScreen("F:\\Test22.png");
} catch (Exception e) {
// TODO Auto-generated catch block
}
}