JUNG:将整个图形(不仅仅是可见部分)保存为图像 [英] JUNG: save whole graph (not only visible part) as image

查看:150
本文介绍了JUNG:将整个图形(不仅仅是可见部分)保存为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找我的问题的解决方案,但没有什么是我想要的。

I've been looking around for solutions to my question, but nothing does exactly what I want.

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

What I want to do is save a whole JUNG graph (with custom vertex and edge rendering) to an image (PNG or JPEG). When I save the VisualizationViewer to a BufferedImage, it only takes the visible part. I want to save the whole graph, so that's not an option.

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

Does anyone have an idea on how to render my whole graph to an image?

提前致谢!

推荐答案

我终于找到了我的问题的解决方案,使用了 VisualizationImageServer
以下是一个如何从整个JUNG图形创建图像的示例,以及其他与之相关的图像:

I finally found the solution to my problem, using a VisualizationImageServer. Here is an example of how to create an image from a whole JUNG graph, for others struggling with it:

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
}

这篇关于JUNG:将整个图形(不仅仅是可见部分)保存为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆