1BufferedImage image = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
2ImageIO.write(image, "png", new File("/screenshot.png"));
3
1public void captureScreen(String fileName) throws Exception {
2 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
3 Rectangle screenRectangle = new Rectangle(screenSize);
4 Robot robot = new Robot();
5 BufferedImage image = robot.createScreenCapture(screenRectangle);
6 ImageIO.write(image, "png", new File(fileName));
7}
8
1Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
2BufferedImage capture = new Robot().createScreenCapture(screenRect);
3ImageIO.write(capture, "bmp", new File(args[0]));
4