import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.p_w_picpath.BufferedImage;
import javax.p_w_picpathio.ImageIO;
import java.io.File;
...
public void captureScreen(String fileName) throws Exception {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle screenRectangle = new Rectangle(screenSize);
Robot robot = new Robot();
BufferedImage p_w_picpath = robot.createScreenCapture(screenRectangle);
ImageIO.write(p_w_picpath, "png", new File(fileName));
}
...
转载于:https://blog.51cto.com/6230217/1223215