writing JUNG graphs to images: can't reliably render complete graph

前端 未结 2 1147
生来不讨喜
生来不讨喜 2021-02-06 12:58

I\'ve been using JUNG to visualize some simple graphs, and I\'d like to write several of them to a PNG file. Unfortunately, the images often appear to render before the graph is

2条回答
  •  别跟我提以往
    2021-02-06 13:26

    You can also use VisualizationImageServer. It's a subtype of BasicVisualizationServer which adds a getImage method. I have had no trouble with it rendering the graphs properly.

    Your code would then be like:

    public void writeImage(String filename) {
        Layout layout = new CircleLayout(jungGraph);
        layout.setSize(innerSize);
        bvs = new VisualizationImageServer(layout);
        // [...]
        BufferedImage image = (BufferedImage)bvs.getImage();
    }
    

提交回复
热议问题