java.awt.Robot.createScreenCapture not working on multiple screens configuration with last JRE (8)

StackOverflow https://stackoverflow.com/questions/22866985

  •  27-06-2023
  •  | 
  •  

문제

I have two screens plugged on my computer. I try to make a screen capture on each screen. I'm using the following code :

GraphicsDevice[] screens = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();  //same screens[] with JRE7 and JRE8

Robot rbt0 = new Robot(screens[0]);
BufferedImage image0 = rbt0.createScreenCapture(new Rectangle(0,0,1024,1024));

Robot rbt1 = new Robot(screens[1]);
BufferedImage image1 = rbt1.createScreenCapture(new Rectangle(0,0,1024,1024));
  • On JRE7, each capture is performed on the right screen : image0 and image1 are different.
  • On JRE8, the capture is the same for both screens : image0 and image1 is the same visual image (they are both images of the screen 0).

The javadoc doesn't mention there is a new feature about Robot class on JRE8. Is this a bug of the JRE8 ? Is anyone having the same problem ? If this bug is confirmed, how could I communicate this problem to Oracle ?

Thanks everyone,

Regards,

도움이 되었습니까?

해결책

It appears the way screen coordinates are calculated by the Robot have changed.

The following bug has been raised against the javadoc of Java 8 which may explain your problem.

http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8033128

It looks like the change was made deliberately and is not a bug.

To capture your second screen you may have to offset the location by the size of the first screen.

Robot rbt1 = new Robot(screens[1]);
BufferedImage image1 = rbt1.createScreenCapture(new Rectangle(1024,0,1024,1024));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top