0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

すべてのモニターのスクリーンショットを1つのファイルに保存したい

Posted at

マルチモニター環境で、すべてのモニターのスクリーンショットを取得し、1つのファイルscreenshot.pngに保存するサンプルです。

public void screenShot() throws AWTException, IOException {
    Rectangle rectangle = new Rectangle();
    for (GraphicsDevice graphicsDevice : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
        for (GraphicsConfiguration graphicsConfiguration : graphicsDevice.getConfigurations()) {
            rectangle = rectangle.union(graphicsConfiguration.getBounds());
        }
    }
    
    Robot robot = new Robot();
    ImageIO.write(robot.createScreenCapture(rectangle), "png", new File("screenshot.png"));
}

環境情報

D:\>java -version
openjdk version "21.0.3" 2024-04-16 LTS
OpenJDK Runtime Environment Temurin-21.0.3+9 (build 21.0.3+9-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.3+9 (build 21.0.3+9-LTS, mixed mode, sharing)

D:\>javac -version
javac 21.0.3

D:\>ver

Microsoft Windows [Version 10.0.22631.3880]
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?