if (cells.length > 0) {
Rectangle2D rectangle = graph.getCellBounds(cells);
graph.setGridVisible(false);
graph.toScreen(rectangle);
// Create a Buffered Image
Dimension dimension = rectangle.getBounds().getSize();
image = new BufferedImage(dimension.width, dimension.height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = image.createGraphics();