2009年5月20日 星期三

Screen Capture in Java

通過java.awt.Robot的createScreenCapture截屏.

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

沒有留言: