In this program we will see how we can take screenshots using a java program and save the screenshot in desired folder.
We use java.awt.Robot class to capture pixels of screen. It provides method like createScreenCapture which captures the current screen. This method returns captured image as BufferedImage object which can be saved as a file. It also uses ImageIO to save it as PNG image format. Toolkit.getDefaultToolkit().getSize() method is used to get the size of screen.
The serialVersionUID is universal version identifier for Serializable class. Thread is used so that after executing the program we can switch to the screen we want to take screenshot of. 120s is the time in seconds i.e. 2 mins.
NOTE : Please keep note of UpperCase and LowerCase in name of methods. A slight change of Case may cause errors.
How to use the program to capture Screenshot :
- Write program in Notepad.
- Save it as Screenshot.java and run it on CommandPrompt.
- Refer to the screenshots at end in case of any problem.
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- ArrayBlockingQueue take() method in Java
- LinkedBlockingQueue take() Method in Java with Examples
- PriorityBlockingQueue take() method in Java
- LinkedTransferQueue take() method in Java
- LinkedBlockingDeque take() method in Java
- DelayQueue take() method in Java with Examples
- BlockingDeque take() method in Java with Examples
- BlockingQueue take() method in Java with examples
- Java Program for Program to calculate area of a Tetrahedron
- Java Program for Program to find area of a circle
- Java Program for Program for array rotation
- Hello World Program : First program while learning Programming
- Output of Java Program | Set 1
- Output of Java Program | Set 2
- Output of Java Program | Set 3
- Output of Java Program | Set 4
- Output of Java program | Set 5
- Output of Java Program | Set 6
- Output of Java Program | Set 7
- Output of Java Program | Set 8
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.