简体   繁体   English

如何从 JGraphX (mxGraph) 方法创建一个大的 BufferedImage?

[英]How do I create a large BufferedImage from JGraphX (mxGraph) method?

I am using JGraphX to diagram workflows of varying size.我正在使用 JGraphX 来绘制不同大小的工作流。 I am encountering a problem that once I hit a certain number of cells, the mxCellRenderer method createBufferedImage() fails with an OutOfMemoryError.我遇到了一个问题,一旦我点击了一定数量的单元格,mxCellRenderer 方法 createBufferedImage() 就会失败并出现 OutOfMemoryError。 JGraphX renders the diagram properly in the Swing JFrame, regardless of whether it saves properly or not. JGraphX 在 Swing JFrame 中正确呈现图表,不管它是否正确保存。

Is there a known work-around or modification to the class and/or methods to allow for large images?是否有已知的解决方法或修改类和/或方法以允许使用大图像?

Example code:示例代码:

public void generatePNG() throws IOException {
    BufferedImage image = mxCellRenderer.createBufferedImage(graph, null, 1, Color.WHITE, true, null);
    ImageIO.write(image, "PNG", new File(path + "-" + name + ".png"));
}

Resulting stacktrace:结果堆栈跟踪:

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferInt.<init>(Unknown Source)
at java.awt.image.Raster.createPackedRaster(Unknown Source)
at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source)
at java.awt.image.BufferedImage.<init>(Unknown Source)
at com.mxgraph.util.mxUtils.createBufferedImage(Unknown Source)
at com.mxgraph.util.mxUtils.createBufferedImage(Unknown Source)
at com.mxgraph.canvas.mxImageCanvas.<init>(Unknown Source)
at com.mxgraph.canvas.mxImageCanvas.<init>(Unknown Source)
at com.mxgraph.util.mxCellRenderer$1.createCanvas(Unknown Source)
at com.mxgraph.util.mxCellRenderer.drawCells(Unknown Source)
at com.mxgraph.util.mxCellRenderer.createBufferedImage(Unknown Source)
at com.mxgraph.util.mxCellRenderer.createBufferedImage(Unknown Source)

This same method functions perfectly fine for "smaller" diagrams (including some rather large ones) but once it reaches a certain limit no amount of increasing heap space appears to help.同样的方法对于“较小”的图(包括一些相当大的图)来说效果很好,但是一旦达到某个限制,增加堆空间的数量似乎没有帮助。

The only other question I've found related to this is an older one which didn't really have a satisfactory answer: Jgraphx out of memory - Java我发现与此相关的唯一另一个问题是一个较旧的问题,它并没有真正得到令人满意的答案: Jgraphx out of memory - Java

Any help would be appreciated!任何帮助,将不胜感激!

Maybe you could try to set antialias to false .也许您可以尝试将antialias设置为false That works for me.这对我行得通。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM