[英]Headless environment error in java.awt.Robot class with MAC OS
I am trying to capture screen shots in my JavaFX application using Robot
class,我正在尝试使用
Robot
类在我的 JavaFX 应用程序中捕获屏幕截图,
this is the code which I used in my application:这是我在我的应用程序中使用的代码:
Rectangle screenBounds = new Rectangle(Screen.getPrimary().getBounds().getWidth(),
Screen.getPrimary().getBounds().getHeight());
Robot robot = new Robot();
BufferedImage img = robot.createScreenCapture(new java.awt.Rectangle(
(int) screenBounds.getX(), (int) screenBounds.getY(), (int)
screenBounds.getWidth(), (int) screenBounds.getHeight()));
It is working perfectly in windows operating system , but showing an error of headless environment
in MAC OS at Robot robot = new Robot();
它在windows 操作系统中运行良好,但在
Robot robot = new Robot();
处显示MAC OS中headless environment
的错误Robot robot = new Robot();
This is to answer my own question, after searching many resources. 这是在搜索了许多资源后回答我自己的问题。
I have used following code to disable headless environment, and the problem is solved. 我使用以下代码来禁用无头环境,问题解决了。
static {
System.setProperty("java.awt.headless", "false");
}
Thanks. 谢谢。
From their API I can see the following: 从他们的API我可以看到以下内容:
So you need to check your hardware and their drivers. 因此,您需要检查硬件及其驱动程序。
You can simply add this line of code System.setProperty("java.awt.headless", "false");
您可以简单地添加这行代码
System.setProperty("java.awt.headless", "false");
before the Robot robot = new Robot();
在
Robot robot = new Robot();
. .
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.