#5, First Floor, 4th Street , Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to capture the screen for certain duration using java?

Description

PrintScreen.java file enables the print screen option in java using Robot object that captures the screen periodically (1 sec) and store it as image.

Sample Code
  • Filename:PrintScreen.java

import java.awt.image.BufferedImage;
import java.awt.Rectangle;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.Robot;
import java.io.File;
import javax.imageio.ImageIO;

class PrintScreen {
PrintScreen(int i) {
try {
Toolkit tool = Toolkit.getDefaultToolkit();
Dimension d = tool.getScreenSize();
Rectangle rect = new Rectangle(d.width,d.height);
Robot robot = new Robot();
File f = new File("image"+i+".jpg");
BufferedImage img = robot.createScreenCapture(rect);
ImageIO.write(img,"jpeg",f);
tool.beep();

}
catch(Exception e) {
System.out.println(e);
}
}
public static void main(String args[]) {
try {
Thread.sleep(5000);
for (int n=0;n<3;n++) {
Thread.sleep(1000);
PrintScreen sr = new PrintScreen(n);
}
}
catch(Exception e) {
System.out.println(e);
}
}

}


Screenshots