java take and save screenshot 1

java take and save screenshot

BufferedImage image = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
ImageIO.write(image, "png", new File("/screenshot.png"));

Here is what the above code is Doing:
1. Create a new Robot object.
2. Create a Rectangle object that represents the entire screen.
3. Call the Robot object’s createScreenCapture() method, passing it the Rectangle object.
4. Write the captured image to a file.

Similar Posts