Example usage for org.jfree.chart ChartUtilities writeBufferedImageAsPNG

List of usage examples for org.jfree.chart ChartUtilities writeBufferedImageAsPNG

Introduction

In this page you can find the example usage for org.jfree.chart ChartUtilities writeBufferedImageAsPNG.

Prototype

public static void writeBufferedImageAsPNG(OutputStream out, BufferedImage image, boolean encodeAlpha,
        int compression) throws IOException 

Source Link

Document

Writes a BufferedImage to an output stream in PNG format.

Usage

From source file:org.talend.dataprofiler.chart.util.ChartUtils.java

public static ImageDescriptor bufferedToDescriptorOptimized(final BufferedImage image) throws IOException {
    final PipedOutputStream output = new PipedOutputStream();
    final PipedInputStream pipedInputStream = new PipedInputStream();
    output.connect(pipedInputStream);/*www. j a  va2s  .  com*/

    try {
        new Thread() {

            @Override
            public void run() {
                try {
                    ChartUtilities.writeBufferedImageAsPNG(output, image, false, 0);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

        }.start();
    } catch (RuntimeException e) {
        if (e.getCause() instanceof IOException) {
            throw (IOException) e.getCause();
        }
    }

    ImageData img = new ImageData(pipedInputStream);
    ImageDescriptor descriptor = ImageDescriptor.createFromImageData(img);
    return descriptor;
}

From source file:org.sonar.server.charts.deprecated.BaseChartTest.java

protected void assertChartSizeGreaterThan(BufferedImage img, int size) throws IOException {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    ChartUtilities.writeBufferedImageAsPNG(output, img, true, 0);
    assertTrue("PNG size in bits=" + output.size(), output.size() > size);
}

From source file:org.sonar.server.charts.deprecated.BaseChartTest.java

protected void assertChartSizeLesserThan(BufferedImage img, int size) throws IOException {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    ChartUtilities.writeBufferedImageAsPNG(output, img, true, 0);
    assertTrue("PNG size in bits=" + output.size(), output.size() < size);
}

From source file:org.sonar.server.charts.deprecated.BaseChartTest.java

protected void saveChart(BufferedImage img, String name) throws IOException {
    File target = new File("target/test-tmp/chart/");
    FileUtils.forceMkdir(target);//from w w w .java  2 s.co  m
    ByteArrayOutputStream imgOutput = new ByteArrayOutputStream();
    ChartUtilities.writeBufferedImageAsPNG(imgOutput, img, true, 0);
    OutputStream out = new FileOutputStream(new File(target, name));
    out.write(imgOutput.toByteArray());
    out.close();

}