3

If I run this code:

BufferedImage image = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
ImageIO.write(image, "png", new File("takenwithrobot.png"));

It yields the following PNG: http://davzy.com/screenshots/takenwithrobot.png

If I take a screenshot using the built in OS X screen capture utility I get the following: http://davzy.com/screenshots/takenwithOSXscreenshotutility.png

As you can see the colours in both are completely different. After several experiments I determined that the colours in the above screenshot taken with the built in OS X utility have the correct colours, and the screenshot taken with robot have the complete wrong colours.

I am writing a script which compares pixel by pixel of screenshots, and so if robot is producing screenshots with wrong colours, it will not work. Interestingly enough if I run the above on a Windows machine it works just fine and gets the correct colours. I was thinking maybe the colour depth of robot was the cause of all the wrong colours, but I don't know if that's the problem and I don't know how to change it.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
David Zorychta
  • 13,039
  • 6
  • 45
  • 81
  • This is probably something to do with PNG gamma correction -- or the lack thereof. See http://hsivonen.iki.fi/png-gamma/, for example. That's probably why it's only borked on the Mac, because Macs have... unique.. gamma properties. How to reliably fix it though, I'm afraid I don't know. – Boann Dec 23 '11 at 16:58
  • 1
    @Boann is right, Mac always tried to give a better gamma (1.8); on Windows (2.2) everything below RGB(100, 100, 100) is black. An approximating conversion should be possible. – Joop Eggen Dec 24 '11 at 00:33
  • So far my research is showing that on OSX, `RobotPeer.getRGBPixels` (which `Robot.createScreenCapture` uses) is returning the wrong values. My guess so far is that `RobotPeer` implementations are platform-specific and there's something up with the OSX implementation. – Roman Nurik Feb 09 '12 at 22:24
  • See also http://stackoverflow.com/questions/6519523 – Roman Nurik Feb 09 '12 at 22:24

1 Answers1

1

If the robot takes all screen shots, there should be no problem (two equally false pixels of two screenshots are evidently the same).

First I saw a difference between application window having focus, and one having not. Maybe that is one explanation. For the different gray on the status line of NetBeans.

Furthermore the standard screen capture might correct gamma and do anti-aliasing. Maybe that is the case here.

(Unfortunately my non-Mac monitor does not show other differences.)

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • I think Joop's right about focus; I saw no difference when comparing a sample of pixels using `/Developer/Applications/Graphics Tools/Pixie.app` and [`Zoom`](http://stackoverflow.com/a/3742841/230513). – trashgod Dec 23 '11 at 17:02
  • My apologies you are correct about window focus. I have updated the screenshots in my initial question. The problem still stands, I am afraid. (PS: I don't use robot to take all the screenshots, which why the problem exists. I do not wish to use one set of images to compare on Windows, and another set on OS X). – David Zorychta Dec 23 '11 at 17:05