This should be done for PNG format:
BufferedImage image = mxCellRenderer.createBufferedImage(graph, null, 1, Color.WHITE, true, null); ImageIO.write(image, "PNG", new File("C:\\Temp\\graph.png"));
Where
graph is your mxGraph object. (Note mxCellRenderer is a reference to a class, not a variable, so mxCellRenderer.createBufferedImage is a call to a static method)."PNG" is a format and can be JPEG, PNG, GIF, BMP and WBMP out of the box. See here for more details.
source share