Example usage for java.awt Graphics2D clearRect

List of usage examples for java.awt Graphics2D clearRect

Introduction

In this page you can find the example usage for java.awt Graphics2D clearRect.

Prototype

public abstract void clearRect(int x, int y, int width, int height);

Source Link

Document

Clears the specified rectangle by filling it with the background color of the current drawing surface.

Usage

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);
}