java - 截图机器人在 Debian 上仅捕获黑屏

标签 java linux debian openjdk-11

我正在 Linux 下使用 OpenJDK 11 使用 java.awt.Robot 创建屏幕截图。Linux 上的结果是全黑图像。相同的代码适用于 Ubuntu 和 Windows(当然使用另一个文件路径)。

有什么线索吗?

public void captureScreen() throws AWTException {
    Robot robot = new Robot(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice());
    BufferedImage screen = robot.createScreenCapture(new Rectangle(getDefaultToolkit().getScreenSize()));
    try {
        ImageIO.write(screen, "jpg", new File("/tmp/screenshot.jpg"));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

UPDATE: The the cause of the problem lies in the combination of OpenJDK and Wayland. With Oracle JDK/JRE (13.0.1) everything works fine.

最佳答案

如果您使用 wayland 而不是 XOrg,这可能会导致问题,因为它对于图形操作的 Java 接口(interface)不太稳定。

编辑:此错误现已修复(请参阅OP)

关于java - 截图机器人在 Debian 上仅捕获黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59008567/

相关文章:

java - MeCab 路径参数在 Windows 上不接受空格

java - JCMD 的代码/内部部分包含什么?

linux - 运行 Docker 镜像

C++ apt-get 处理 popen 的标准输出

ruby - 无法使用 rvm 安装 nokogiri,收到 "nokogiri requires Ruby version >= 1.9.2"

java - java中通过传递参数实现多线程

java.io.FileNotFoundException 没有此类文件或目录错误,但目录存在

linux - ARM/Linux内存泄漏: Can a user program retain memory after terminating?

linux - linux 中接口(interface)的特定接口(interface)名称

linux - Docker 在构建时无法找到包 (wkhtmltopdf)