Question

Today, I ran into weird issue: java.awt.Robot captures black areas, instead of image content. I'm using Ubuntu 12.04 and OpenJDK6/7.

java.awt.Robot on Unix is supported by the sun.awt.X11.XRobotPeer, which, following the corresponding OpenJDK sources, uses image grabbing functions similar to those, used by xwd utililty (lines 92-162).

So, I ran the following command:

xwd -root -out test.screen.root.xwd

and then opened this file with gimp. Here's what I get:

enter image description here

Then I tried:

xwd -root | xwdtopnm | pnmtopng > Screenshot.root.png

And I got the following result: Console output:

xwdtopnm: writing PPM file
libpng warning: Invalid sBIT depth specified

And the image itself: enter image description here

What can cause this? How can I fix it?

Was it helpful?

Solution

Seems like the only way to fix this is to use your own native implementation of screen shotting.

Here's the detailed description of the problem at the launchpad from unity devs: launchpad conversation.

The problem is in the way unity-2d draws itself and in the use of XShaping.

OTHER TIPS

I had the same error message. Apparently, it is linked to xwdtopnm not handling well the color depth of your screen - causing the resulting png file to be corrupted.

An alternative solution is to use the import command from the imagemagick package to take the screenshot.

So you can just replace:

xwd -root | xwdtopnm | pnmtopng > Screenshot.root.png

with:

import -window root Screenshot.root.png

NB: if it is not installed, you can get imagemagick on Ubuntu with the following command:

sudo apt install imagemagick
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top