BufferedImage是个好类,和ImageIO和Graphic可以对图片进行很多处理;至于把BufferedImage打到窗口上就是八仙过海,各显神通罗。

import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ImageUtil{

public static BufferedImage captureScreen(Rectangle screenRect)
throws AWTException{
Robot robot = new Robot();
return robot.createScreenCapture(screenRect);
}

public static void saveImage(BufferedImage srcImage, String saveImagePath) throws IOException{
File file = new File(saveImagePath);
String suffix = saveImagePath.substring(saveImagePath.lastIndexOf('.')+1);
ImageIO.write(srcImage, suffix, file);
}
}