JUNG:将整个图形(不仅是可见部分)另存为图像

JUNG:将整个图形(不仅是可见部分)另存为图像,第1张

JUNG:将整个图形(不仅是可见部分)另存为图像

我终于使用找到了解决我问题的方法

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}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5429862.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-11
下一篇2022-12-11

发表评论

登录后才能评论

评论列表(0条)

    保存