public static void main(String[] args) throws AWTException, IOException { // 获取当前显示器屏幕大小 Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); //拷贝屏幕到一个BufferedImage对象screenshot BufferedImage screenshot = (new Robot()).createScreenCapture(new Rectangle(0, 0, (int) d.getWidth(), (int) d.getHeight())); //图片保存路径 File f = new File("D:\Software\blibli\Download\aa.jpg"); //将screenshot对象写入图像文件 ImageIO.write(screenshot, "jpg", f); }
相关的pom文件:
<dependency> <groupId>org.bytedeco</groupId> <artifactId>javacv</artifactId> <version>1.4.1</version> </dependency> <dependency> <groupId>org.bytedeco</groupId> <artifactId>javacpp</artifactId> <version>1.4.1</version> </dependency> <dependency> <groupId>org.bytedeco.javacpp-presets</groupId> <artifactId>opencv-platform</artifactId> <version>3.4.1-1.4.1</version> </dependency> <dependency> <groupId>org.bytedeco.javacpp-presets</groupId> <artifactId>ffmpeg-platform</artifactId> <version>3.4.2-1.4.1</version> </dependency>