gpt4 book ai didi

java - 如何停止 BufferedImage.getGraphics() 打开 X11 设备?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:20:31 26 4
gpt4 key购买 nike

我有以下用于创建光栅图像的代码。

    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
Graphics g = img.getGraphics();
g.setColor(backgroundColour);
g.fillRect(0, 0, width, height);

这在我的 Windows 机器和本地 Ubuntu 机器上运行,但是当传输到服务器时会尝试调用 X11 服务器,并显示堆栈跟踪。我怎样才能避免这种情况?

    Exception in thread "main" java.lang.InternalError: Can't connect to X11
window server using 'localhost:10.0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at
sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:62)
at
sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:178)
at java.security.AccessController.doPrivileged(Native Method)
at
sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:142)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82)
at
java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1164)
at java.awt.image.BufferedImage.getGraphics(BufferedImage.java:1154)
at
org.xmlcml.cml.converters.molecule.fragments.Cml2PngTool.renderMolecule(Cml2PngTool.java:94)
at
org.xmlcml.cml.converters.molecule.fragments.Cml2PngTool.renderMolecule(Cml2PngTool.java:61)
at
org.xmlcml.cml.converters.molecule.fragments.FragmentGenerator.add2DCoordsAndRender(FragmentGenerator.java:180)
at
org.xmlcml.cml.converters.molecule.fragments.FragmentGenerator.write2dImage(FragmentGenerator.java:169)
at
org.xmlcml.cml.converters.molecule.fragments.FragmentGenerator.output2dImages(FragmentGenerator.java:486)
at
org.xmlcml.cml.converters.molecule.fragments.FragmentGenerator.generateMoieties(FragmentGenerator.java:443)
at
org.xmlcml.cml.converters.molecule.fragments.FragmentGenerator.createMoietiesAndFragments(FragmentGenerator.java:125)
at
org.xmlcml.cml.converters.molecule.fragments.CML2FragmentConverter.convert(CML2FragmentConverter.java:47)
at
org.xmlcml.cml.converters.AbstractConverter.process(AbstractConverter.java:1067)
at
org.xmlcml.cml.converters.AbstractConverter.processInputFile(AbstractConverter.java:1060)
at
org.xmlcml.cml.converters.AbstractConverter.runArgs(AbstractConverter.java:1016)
at
org.xmlcml.cml.converters.molecule.fragments.CML2FragmentConverter.main(CML2FragmentConverter.java:74)

最佳答案

从命令行指定 headless :

-Djava.awt.headless=true

或来自代码:

System.setProperty("java.awt.headless", "true"); 

参见 http://www.oracle.com/technetwork/articles/javase/headless-136834.html了解更多信息。

关于java - 如何停止 BufferedImage.getGraphics() 打开 X11 设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21302611/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com