public 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));
}
Screenshots
The captureScreen() method takes a String fileName as its only parameter and prints it to the console. The code creates a new Robot object and uses its createScreenCapture() method to capture the content of the screen into an ImageIO object.
Shortcut: ss
0 Comments
Add Comment
Log in to add a comment