Wednesday, August 14, 2013

ScreenShot Using Java Program


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

import javax.imageio.ImageIO;

/**
 * @Babu
 */
public class ScreenShot {
public static void main(String args[]) {
ScreenShot.capture();
}

public static void capture() {
try {
Robot robot = new Robot();
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
BufferedImage img = robot.createScreenCapture(new Rectangle(size));
File save_path = new File(
"C:/Users/ESREVER/Pictures/screenshot.jpg");
// The image will be stored in the above mentioned location
ImageIO.write(img, "JPG", save_path);

} catch (Exception e) {
e.printStackTrace();
}
}

}


Note: You can create a batch file to run this program like below.






To create this batch file open text document and type the command
"java yourprogramname" save this file with an extension  .bat then your file will looks like a setup icon, by just clicking on this you can run the program.

OUTPUT:
The corresponding console will be capture by the program and saved in preferred location.






No comments:

Post a Comment