/* * Main.java * * Created on March 2, 2007, 5:10 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package lfc; import javax.imageio.*; import com.sun.media.jai.operator.*; import com.sun.media.imageio.plugins.pnm.*; import com.sun.media.imageioimpl.common.*; import java.io.*; import java.awt.*; import java.awt.image.*; /** * * @author ... */ public class Main { public static void main(String[] args) throws Exception { String outFileName = "/home/lou/image.pnm"; Toolkit toolkit = Toolkit.getDefaultToolkit(); Point shotpt = new Point(30, 25); Dimension screenSize = new Dimension(250, 400); Rectangle screenRect = new Rectangle(shotpt, screenSize); // create screen shot Robot robot = new Robot(); BufferedImage image = robot.createScreenCapture(screenRect); // save captured image to PNG file ImageIO.write(image, "pnm", new File(outFileName)); // give feedback System.out.println("Saved screen shot (" + image.getWidth() + " x " + image.getHeight() + " pixels) to file \"" + outFileName + "\"."); // use System.exit if the program hangs after writing the file; // that's an old bug which got fixed only recently // System.exit(0); } }