Created
October 29, 2013 14:46
-
-
Save madan712/7216016 to your computer and use it in GitHub Desktop.
Java program to take screen shot of your desktop after an interval of every 5 second
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.awt.Dimension; | |
| import java.awt.Rectangle; | |
| import java.awt.Robot; | |
| import java.awt.Toolkit; | |
| import java.awt.image.BufferedImage; | |
| import javax.imageio.ImageIO; | |
| import java.io.File; | |
| public class CaptureScreen { | |
| public void saveScreenshot(String fileName) { | |
| try { | |
| 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)); | |
| System.out.println("saved.."+fileName); | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| public static void main(String[] args) { | |
| CaptureScreen cs = new CaptureScreen(); | |
| int count = 1; | |
| while (true) { | |
| cs.saveScreenshot("C:/screenshots/screen_"+count+".png"); | |
| count++; | |
| try { | |
| Thread.sleep(5000); | |
| } catch (InterruptedException e) { | |
| e.printStackTrace(); | |
| } | |
| }//while | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment