Example usage for org.jfree.chart.encoders KeypointPNGEncoderAdapter setEncodingAlpha

List of usage examples for org.jfree.chart.encoders KeypointPNGEncoderAdapter setEncodingAlpha

Introduction

In this page you can find the example usage for org.jfree.chart.encoders KeypointPNGEncoderAdapter setEncodingAlpha.

Prototype

@Override
public void setEncodingAlpha(boolean encodingAlpha) 

Source Link

Document

Set whether the encoder should encode alpha transparency (supported).

Usage

From source file:edu.jhuapl.graphs.jfreechart.JFreeChartBaseSource.java

private static ImageEncoder getEncoder(Encoding encoding) throws GraphException {
    switch (encoding) {
    case JPEG://from  w  ww.j a va2s.  c o m
        return ImageEncoderFactory.newInstance("jpeg");
    case PNG:
        return ImageEncoderFactory.newInstance("png");
    case PNG_WITH_TRANSPARENCY:
        //this is noted as being slower for big graphs
        KeypointPNGEncoderAdapter keypointPNGEncoderAdapter = new KeypointPNGEncoderAdapter();
        keypointPNGEncoderAdapter.setEncodingAlpha(true);
        return keypointPNGEncoderAdapter;
    default:
        throw new GraphException("Unrecognized encoding \"" + encoding.toString() + "\"");
    }
}

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

public void exportChartAsPNG(OutputStream out) throws IOException {
    KeypointPNGEncoderAdapter encoder = new KeypointPNGEncoderAdapter();
    encoder.setEncodingAlpha(true);
    encoder.encode(getChartImage(), out);
}

From source file:org.sonar.server.charts.ChartsServlet.java

private void exportAsPNG(BufferedImage image, OutputStream out) throws IOException {
    KeypointPNGEncoderAdapter encoder = new KeypointPNGEncoderAdapter();
    encoder.setEncodingAlpha(true);
    encoder.encode(image, out);/*from  w w  w .ja  va2 s .c o m*/
}

From source file:org.jivesoftware.openfire.reporting.graph.GraphEngine.java

/**
 * Creates a graph in PNG format.  The PNG graph is encoded by the KeypointPNGEncoderAdapter
 * so that the resulting PNG is encoded with alpha transparency.
 *
 * @param key//from   www. j  a  v a2 s.  co  m
 * @param width
 * @param height
 * @param startTime
 * @param endTime
 * @param dataPoints
 * @return
 * @throws IOException
 */
public byte[] generateGraph(String key, int width, int height, String color, long startTime, long endTime,
        int dataPoints) throws IOException {

    JFreeChart chart = generateChart(key, width, height, color, startTime, endTime, dataPoints);
    KeypointPNGEncoderAdapter encoder = new KeypointPNGEncoderAdapter();
    encoder.setEncodingAlpha(true);
    return encoder.encode(chart.createBufferedImage(width, height, BufferedImage.BITMASK, null));
}

From source file:org.jivesoftware.openfire.reporting.graph.GraphEngine.java

/**
 * Generates a Sparkline type graph. Sparkline graphs
 * are "intense, simple, wordlike graphics" so named by Edward Tufte. The big
 * difference between the graph produced by this method compared to the
 * graph produced by the <code>generateGraph</code> method is that this one
 * produces graphs with no x-axis and no y-axis and is usually smaller in size.
 * @param key//from  w w  w  .  j a  v  a 2 s  .  com
 * @param width
 * @param height
 * @param startTime
 * @param endTime
 * @param dataPoints
 * @return
 * @throws IOException
 */
public byte[] generateSparklinesGraph(String key, int width, int height, String color, long startTime,
        long endTime, int dataPoints) throws IOException {
    Statistic[] def = statsViewer.getStatistic(key);
    if (def == null) {
        return null;
    }

    JFreeChart chart;
    switch (def[0].getStatType()) {
    case count:
        chart = generateSparklineBarGraph(key, color, def, startTime, endTime, dataPoints);
        break;
    default:
        chart = generateSparklineAreaChart(key, color, def, startTime, endTime, dataPoints);
    }

    KeypointPNGEncoderAdapter encoder = new KeypointPNGEncoderAdapter();
    encoder.setEncodingAlpha(true);
    return encoder.encode(chart.createBufferedImage(width, height, BufferedImage.BITMASK, null));
}

From source file:userinterface.graph.Graph.java

/**
 * Renders the current graph to a JPEG file.
 * //w  ww  .  ja  va2  s  . co m
 * @param file
 *             The file to export the JPEG data to.
 * @throws GraphException, IOException
 *             If file cannot be written to.
 */
public void exportToPNG(File file, int width, int height, boolean alpha) throws GraphException, IOException {

    FileOutputStream fileOutputStream = new FileOutputStream(file);

    KeypointPNGEncoderAdapter encoder = new KeypointPNGEncoderAdapter();
    encoder.setEncodingAlpha(alpha);

    Paint bgPaint = chart.getBackgroundPaint();

    if (alpha) {
        chart.setBackgroundPaint(null);
    }

    BufferedImage bufferedImage = chart.createBufferedImage(width, height,
            alpha ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB, null);

    if (alpha) {
        chart.setBackgroundPaint(bgPaint);
    }

    encoder.encode(bufferedImage, fileOutputStream);

    fileOutputStream.flush();
    fileOutputStream.close();

    //ChartUtilities.saveChartAsPNG(file, this.chart, width, height, null, alpha, 9);
}