List of usage examples for java.awt Graphics2D clearRect
public abstract void clearRect(int x, int y, int width, int height);
From source file:ubic.basecode.graphics.MatrixDisplay.java
/** * @param matrix//from w w w .ja v a 2 s. c o m * @param stream * @param showLabels * @param showScalebar */ public void writeToPng(ColorMatrix<R, C> matrix, OutputStream stream, boolean showLabels, boolean showScalebar) throws IOException { // Draw the image to a buffer boolean oldLabelSate = this.m_isShowLabels; if (!oldLabelSate) { this.setLabelsVisible(true); } Dimension d = computeSize(showLabels, showScalebar); BufferedImage m_image = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB); Graphics2D g = m_image.createGraphics(); g.setBackground(Color.white); g.clearRect(0, 0, d.width, d.height); drawMatrix(matrix, g, showLabels, showScalebar); if (showLabels) { drawRowNames(g, showScalebar); drawColumnNames(g, showScalebar); } if (showScalebar) { drawScaleBar(g, d, matrix.getDisplayMin(), matrix.getDisplayMax()); } // Write the buffered image to the output steam. ImageIO.write(m_image, "png", stream); this.setLabelsVisible(oldLabelSate); }