3

I want to get a lot of screenshots from java in headless server. To do this, my plan is below.

  1. Use Xvfb for virtual screen.
  2. To reduce tasks in queue fast, open multiple xvfb.
  3. To get screenshots from java, use java.awt.Robot#createScreenCapture. (A constructor of java.awt.Robot require target java.awt.GraphicsDevice)

A problem is that xvfb screen devices aren't listed by java.awt.GraphicsEnvironment#getScreenDevices().

Code is something like this. http://www.java2s.com/Code/JavaAPI/java.awt/GraphicsEnvironmentgetScreenDevices.htm

import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;

public class MainClass {

  public static void main(String[] a) throws Exception {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] screenDevices = ge.getScreenDevices();
    for (int i = 0; i < screenDevices.length; i++)
      System.out.println(screenDevices[i].getIDstring());
  }
}

Terminal:

% Xvfb :1 -screen 0 1024x768x24 &
% Xvfb :2 -screen 0 1024x768x24 &

Actually, I tested above equivalent code from Clojure's repl on MBA(Mac OSX 10.6.8) and HP2140 (Ubuntu 10.04).

(seq (.getScreenDevices (java.awt.GraphicsEnvironment/getLocalGraphicsEnvironment))
;=> (#<CGraphicsDevice CGraphicsDevice[screen=0]>)

I think two xvfb devices should be listed. Is there a way to get xvfb GraphicsDevice?

Thanks.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.