java 截取屏幕

package com.zzst.application.meeting.dwr.control;
/**
 *
 * @author ryan
 * @since Feb 21, 2010 2:19:46 PM
 * @version Feb 21, 2010 2:19:46 PM
 */

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;

public class S {
    /**
    * @param args
    */
    public static void captureScreen(String fileName) throws Exception {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Rectangle screenRectangle = new Rectangle(screenSize);
        Robot robot = new Robot();
        BufferedImage image = robot.createScreenCapture(screenRectangle);
        ImageIO.write(image, "jpg", new File(fileName));
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        
        try {
         String str = "D:\\aa.jpg";
            captureScreen(str);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println("----------截屏成功----------------");
    }
}

你可能感兴趣的:(java,DWR)