java JGraphx save as an image

房东的猫 提交于 2019-12-23 09:26:35

问题


Does anyone know how to export JGraphx as an image in any format? If not, then does anyone know any other java library that will let me create simple diagrams and then save it as an image?


回答1:


This should do it for PNG format:

BufferedImage image = mxCellRenderer.createBufferedImage(graph, null, 1, Color.WHITE, true, null);
ImageIO.write(image, "PNG", new File("C:\\Temp\\graph.png"));

Where

  • graph is your mxGraph object. (Note mxCellRenderer is a reference to a class not a variable, so mxCellRenderer.createBufferedImage is a static method call).
  • "PNG" is the format, and can be JPEG, PNG, GIF, BMP and WBMP out of the box. See here for more details.


来源:https://stackoverflow.com/questions/18432160/java-jgraphx-save-as-an-image

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!