2

My aim is to find a specific picture on the screen by taking a screenshot of the whole screen and find the picture (saved in the resources of the app) by comparing the pixels.

The problem I´m facing at the moment is the part where I take a screenshot of a MacBookPro with Retina display. The resolution is 2880*1800. But with the following code (working fine on windows), I only get a screenshot with 1920*1200.

new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize())

Obviously the screen size is wrong but even when I use 2880*1800 hardcoded, the screenshot only is 1920*1200 with black frame around.

Does somebody know how to take the screenshot with the right resolution?

luator
  • 4,769
  • 3
  • 30
  • 51
Punika
  • 354
  • 3
  • 16
  • 2
    Whats the result of `Toolkit.getDefaultToolkit().getScreenSize()`? – XtremeBaumer Jan 09 '19 at 14:12
  • 1
    Since Java 9, there is [`Robot.createMultiResolutionScreenCapture`](https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/java/awt/Robot.html#createMultiResolutionScreenCapture(java.awt.Rectangle)) for the purpose of taking screen captures on displays with scaling transforms. Have you tried that one? – Hulk Jan 09 '19 at 14:13
  • the Toolkit gave 1920*1200 – Punika Jan 09 '19 at 14:43
  • 1
    @Hulk no I will check this. Thx – Punika Jan 09 '19 at 14:45
  • @Hulk `Robot.createMultiResolutionScreenCapture` returns 3840*2400 But that is still not the right resolution. – Punika Jan 11 '19 at 16:59
  • It should be possible to get the "real" resolution from the `GraphicsDevice` - along the lines of [this answer to a related question](https://stackoverflow.com/a/40399909/2513200) – Hulk Jan 14 '19 at 07:56

0 Answers0