2013-08-25 119 views
4

有誰知道如何將JGraphx導出爲任何格式的圖像?如果沒有,那麼有沒有人知道任何其他的Java庫,可以讓我創建簡單的圖表,然後將其保存爲圖像?java JGraphx保存爲圖像

回答

8

這應該PNG格式做到這一點:

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

  • 是你mxGraph對象。 (注意mxCellRenderer是對類的引用而不是變量,所以mxCellRenderer.createBufferedImage是一個靜態方法調用)。
  • "PNG"是格式,可以是開箱即用的JPEG,PNG,GIF,BMP和WBMP。有關更多詳細信息,請參見here