如何从java获取多个xvfb GraphicsDevice
我想从无头服务器中的java获取大量屏幕截图。 为此,我的计划如下。
- 使用 Xvfb 进行虚拟屏幕。
- 要快速减少队列中的任务,请打开多个 xvfb。
- 要从 java 获取屏幕截图,请使用 java.awt.Robot#createScreenCapture。 (java.awt.Robot 的构造函数需要目标 java.awt.GraphicsDevice)
问题是 java.awt.GraphicsEnvironment#getScreenDevices() 未列出 xvfb 屏幕设备。
代码是这样的。 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());
}
}
终端:
% Xvfb :1 -screen 0 1024x768x24 &
% Xvfb :2 -screen 0 1024x768x24 &
实际上,我在 MBA(Mac OSX 10.6.8) 上测试了 Clojure 的 repl 中的上述等效代码,并且HP2140(Ubuntu 10.04)。
(seq (.getScreenDevices (java.awt.GraphicsEnvironment/getLocalGraphicsEnvironment))
;=> (#<CGraphicsDevice CGraphicsDevice[screen=0]>)
我认为应该列出两个 xvfb 设备。 有没有办法获得 xvfb GraphicsDevice?
谢谢。
I want to get a lot of screenshots from java in headless server.
To do this, my plan is below.
- Use Xvfb for virtual screen.
- To reduce tasks in queue fast, open multiple xvfb.
- 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论