
我终于使用找到了解决我问题的方法
VisualizationImageServer。这是一个如何为整个JUNG图创建图像的示例,供其他苦苦挣扎的人使用:
import edu.uci.ics.jung.visualization.VisualizationImageServer;...// Create the VisualizationImageServer// vv is the VisualizationViewer containing my graphVisualizationImageServer<Node, Edge> vis = new VisualizationImageServer<Node, Edge>(vv.getGraphLayout(), vv.getGraphLayout().getSize());// Configure the VisualizationImageServer the same way// you did your VisualizationViewer. In my case e.g.vis.setBackground(Color.WHITE);vis.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<Edge>());vis.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<Node, Edge>());vis.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Node>());vis.getRenderer().getVertexLabelRenderer() .setPosition(Renderer.VertexLabel.Position.CNTR);// Create the buffered imageBufferedImage image = (BufferedImage) vis.getImage( new Point2D.Double(vv.getGraphLayout().getSize().getWidth() / 2, vv.getGraphLayout().getSize().getHeight() / 2), new Dimension(vv.getGraphLayout().getSize()));// Write image to a png fileFile outputfile = new File("graph.png");try { ImageIO.write(image, "png", outputfile);} catch (IOException e) { // Exception handling}欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)