栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/454336.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号