import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; public static void main(String[] args) { // 创建JMapViewer实例 // JMapViewer mapViewer = new JMapViewer(); // 获取屏幕截图 Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); try { Robot robot = new Robot(); BufferedImage screenFullImage = robot.createScreenCapture(screenRect); // 截取屏幕区域 BufferedImage mapImage = screenFullImage.getSubimage(0, 0, 1920, 1080); // 保存图片 File outputFile = new File("E:/map.png"); ImageIO.write(mapImage, "png", outputFile); System.out.println("图片已保存至 " + outputFile.getAbsolutePath()); } catch (AWTException | IOException e) { e.printStackTrace(); } }
标签:outputFile,java,截取,BufferedImage,new,import,JMapViewer,电脑屏幕 From: https://www.cnblogs.com/tuxiaoer/p/18360523