所以在我的java项目中,我为截图功能做了一些代码
现在这是我制作的代码
public void takeScreenshot() {
try {
Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
Point point = window.getLocationOnScreen();
int x = (int)point.getX();
int y = (int)point.getY();
int w = window.getWidth();
int h = window.getHeight();
Robot robot = new Robot(window.getGraphicsConfiguration().getDevice());
Rectangle captureSize = new Rectangle(x, y, w, h);
java.awt.image.BufferedImage bufferedimage = robot.createScreenCapture(captureSize);
int picNumber = random(100);
String fileExtension = "The Iron Door";
File file = new File((new StringBuilder()).append(SignLink.getCacheDirectory() + "Screenshots/" + fileExtension + " ").append(picNumber).append(".png").toString());
ImageIO.write(bufferedimage, "png", file);
} catch(Exception e) {
e.printStackTrace();
}
}
现在代码完美运行我已经将它设置为对热键执行操作现在我有两个问题
1)我将如何在它周围添加某种由我预先制作的边框,当用户截取屏幕截图时,它会将边框放在图像上
2)我将如何做到这一点,以便用户可以输入他们想要调用屏幕截图的名称