//************************************************************************************ // // // ScreenCapture // // Function: Creates a JPEG image of that portion of the screen (defined as a Rectangle) // passed as coordinates to this application // // Parameters: Top - Top portion of the screen area to be captured // TopLeft - Top Left portion of the screen area to be captured // Width - Width of the screen area to be captured // Height - Height of the screen area to be captured // //************************************************************************************ import java.io.*; import java.awt.*; import java.awt.Robot; import java.awt.image.*; import com.sun.image.codec.jpeg.*; public class ScreenCapture { ScreenCapture (int intop, int inleft, int inwidth, int inheight, String imageName) { try { BufferedImage capture = null; Rectangle area = new Rectangle(intop, inleft, inwidth, inheight); Robot robot = new Robot(); capture = robot.createScreenCapture(area); String imgFile = "c:\\" + imageName + ".jpeg"; FileOutputStream out = new FileOutputStream(imgFile); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); encoder.encode(capture); out.flush(); out.close(); System.exit(0); } catch (Exception exc) { System.out.println("errors "); exc.printStackTrace(); } finally { System.out.println("Error Creating Image"); System.exit(0); } } //******************************************************* public static void main(String args[]) { int inputtop = Integer.parseInt(args[0]); int inputleft = Integer.parseInt(args[1]); int inputwidth = Integer.parseInt(args[2]); int inputheight = Integer.parseInt(args[3]); String inImage = args[4]; new ScreenCapture(inputtop, inputleft, inputwidth, inputheight, inImage); } }