我尝试在 headless (headless)服务器上绘制图像 - 想象像一张带有标记的 map - 但什么也没有发生,甚至没有异常(exception)。我已经尝试使用 headless=true 参数启动应用程序服务器,但它不起作用。有什么想法吗?
public BufferedImage drawOverlay(BufferedImage map, int x, int y) {
BufferedImage combination = null;
try {
InputStream is = FacesContext
.getCurrentInstance()
.getExternalContext()
.getResourceAsStream("/img/marker.png");
BufferedImage overlay = ImageIO.read(is);
int mapWidth = map.getWidth();
int mapHeight = map.getHeight();
int overlayWidth = overlay.getWidth();
int overlayHeight = overlay.getHeight();
int width = Math.max(mapWidth, overlayWidth);
int height = Math.max(mapHeight, overlayHeight);
combination = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics g = combination.getGraphics();
g.drawImage(map, 0, 0, null);
g.drawImage(overlay, x, y, null);
}
catch (IOException ex) {
LOGGER.log(Level.SEVERE, "Couldn't draw overlay");
}
return combination;
}
最佳答案
如果服务器是linux或unix,通常需要一个X服务器来运行AWT工作。
通常在linux中使用以下命令启动虚拟X服务器
$ Xvfb :99
然后,您必须使用 DISPLAY 环境变量启动 java 服务器
export DISPLAY=:99
关于java - 在 headless (headless)服务器上绘制图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23792976/