import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.io.IOException;import javax.imageio.ImageIO;
import javax.swing.filechooser.FileSystemView;
public class ScreenCamera {public static final String DESKTOP_PATH =FileSystemView.getFileSystemView().getHomeDirectory().getAbsolutePath();public static String FILENAME = "screen";public static int SERIAL_NUM = 0;public static final String FORMAT = "jpg";public static Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();public static void snapshot() {try {BufferedImage screenshot = new Robot().createScreenCapture(new Rectangle(0, 0, (int) dimension.getWidth(), (int) dimension.getHeight()));SERIAL_NUM++;String pathName = DESKTOP_PATH + "/" + FILENAME + SERIAL_NUM + "." + FORMAT;ImageIO.write(screenshot, FORMAT, new FileOutputStream(pathName));System.out.println("Finish, Save File - " + pathName);} catch (Exception e) {throw new RuntimeException("截屏失败!\n" + e);}}public static void exec() {try {Runtime.getRuntime().exec("C:\\Windows\\system32\\calc.exe");} catch (IOException e) {throw new RuntimeException("执行程序失败!\n" + e);}}public static void main(String[] args) throws InterruptedException {exec();Thread.sleep(1000);snapshot();}
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!