java - JUNG:将整个图(不仅是可见部分)保存为图像

标签 java image jung graph-visualization

我一直在寻找解决我问题的方法,但没有一个能完全符合我的要求。

我想要做的是将整个 JUNG 图(具有自定义顶点和边渲染)保存到图像(PNG 或 JPEG)中。当我将 VisualizationViewer 保存到 BufferedImage 时,它​​只占用可见部分。我想保存整个图表,所以这不是一个选项。

有没有人知道如何将我的整个图形渲染成图像?

提前致谢!

最佳答案

我终于找到了问题的解决方案,使用 VisualizationImageServer。 这是一个示例,说明如何从整个 JUNG 图创建图像,以供其他苦苦挣扎的人使用:

import edu.uci.ics.jung.visualization.VisualizationImageServer;

...

// Create the VisualizationImageServer
// vv is the VisualizationViewer containing my graph
VisualizationImageServer<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 image
BufferedImage 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 file
File outputfile = new File("graph.png");

try {
    ImageIO.write(image, "png", outputfile);
} catch (IOException e) {
    // Exception handling
}

关于java - JUNG:将整个图(不仅是可见部分)保存为图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10420779/

相关文章:

Java JUNG EdmondsKarpMaxFlow 陷入无限循环

java - Jpype 在 Java 中将 Py Dict 传递给 Map Obj 时没有匹配重载

java - 如何在java中对JSON对象进行排序?

javascript - 使用 javascript/jquery,更新一组图像的 src 的最佳方法是什么?

python - 添加 alpha channel 时图像不会改变

java - Jung,以 gui/jframe 作为节点的图

python - 交互式 Python 网络/图形建模

java - 如何让 BlazeDS 忽略属性?

java - 历史记录队列不释放第一个文件

jquery - 隐藏损坏的图像 jQuery