I am using JGraphX to diagram workflows of varying size. I am encountering a problem that once I hit a certain number of cells, the mxCellRenderer method createBufferedImage() fails with an OutOfMemoryError. JGraphX renders the diagram properly in the Swing JFrame, regardless of whether it saves properly or not.
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
Any help would be appreciated!