Java: Create screen capture

Опубликовано: 11 Июль 2026
на канале: Zoric
5,311
36

In this small tutorial I am making a very simple program that captures the screen and saves it into a image file.
More below

Does not capture curser...
Recorded with Bandicam

Code:
Robot robot = new Robot();
Rectangle screenSize = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage image = robot.createScreenCapture(screenSize);
ImageIO.write(image, "png", new File(System.getProperty(" user.home ") + "/Desktop/ScreenCapture.png"));

Make sure to throw AWTException and IOException or add try and catch :P
System.getProperty("user.home") means: C:/Users/John (for example)