MAC OS的java.awt.Robot类中的Headless环境错误 [英] Headless environment error in java.awt.Robot class with MAC OS

查看:440
本文介绍了MAC OS的java.awt.Robot类中的Headless环境错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Robot类在JavaFX应用程序中捕获屏幕截图,

I am trying to capture screen shots in my JavaFX application using Robot class,

这是我在应用程序中使用的代码:

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()));

它在 windows操作系统中运行正常,但是在>的 MAC OS 中显示headless environment错误.

It is working perfectly in windows operating system, but showing an error of headless environment in MAC OS at 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");
}

谢谢.

这篇关于MAC OS的java.awt.Robot类中的Headless环境错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆