package com.topcheer;
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 CreateImageDemo {
public void CreateImage() {
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
Rectangle screenRect = new Rectangle(screenSize);
Robot robot;
try {
robot = new Robot();
BufferedImage image = robot.createScreenCapture(screenRect);
ImageIO.write(image, "jpg", new File("图片名称.jpg"));
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
CreateImageDemo image = new CreateImageDemo();
image.CreateImage();
}
}