Есть ли способ сделать снимок экрана с помощью Java и сохранить его в какое-то изображение?

Мне никогда не нравилось .java использовать Robot, поэтому picture я создал свой собственный pictures простой метод для создания java-api снимков экрана объектов JFrame:

public static final void makeScreenshot(JFrame argFrame) {
    Rectangle rec = argFrame.getBounds();
    BufferedImage bufferedImage = new BufferedImage(rec.width, rec.height, BufferedImage.TYPE_INT_ARGB);
    argFrame.paint(bufferedImage.getGraphics());

    try {
        // Create temp file
        File temp = File.createTempFile("screenshot", ".png");

        // Use the ImageIO API to write the bufferedImage to a temporary file
        ImageIO.write(bufferedImage, "png", temp);

        // Delete temp file when program exits
        temp.deleteOnExit();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
}

java

image

screenshot

2022-11-15T12:45:01+00:00
Вопросы с похожей тематикой, как у вопроса:

Есть ли способ сделать снимок экрана с помощью Java и сохранить его в какое-то изображение?