Example usage for org.jfree.chart.encoders ImageEncoder encode

List of usage examples for org.jfree.chart.encoders ImageEncoder encode

Introduction

In this page you can find the example usage for org.jfree.chart.encoders ImageEncoder encode.

Prototype

public byte[] encode(BufferedImage bufferedImage) throws IOException;

Source Link

Document

Encodes an image in a particular format.

Usage

From source file:probe.com.model.util.SwingToImageGenerator.java

private String generateEncodedImg(BufferedImage image) {
    String base64 = "";
    try {/*  ww  w  .j  a va  2 s  .c  o m*/
        ImageEncoder in = ImageEncoderFactory.newInstance(ImageFormat.PNG, 0);
        byte[] imageData = in.encode(image);
        base64 = Base64.encodeBase64String(imageData);
        base64 = "data:image/png;base64," + base64;
        System.gc();
    } catch (IOException exp) {
        System.err.println(exp.getLocalizedMessage());
    }
    return base64;
}

From source file:probe.com.model.util.vaadintoimageutil.HeatmapSwingComponent.java

public String generateHeatmap(String[] rows, String[] columns, String[][] data) {

    JPanel heatmapPanelLayout = new JPanel();
    heatmapPanelLayout.setLayout(null);// ww w. j a  v  a  2s.  co  m
    heatmapPanelLayout.setVisible(true);
    heatmapPanelLayout.setBorder(new LineBorder(Color.BLACK));
    int width = (columns.length + 1) * 50;
    int height = (rows.length + 1) * 50;
    heatmapPanelLayout.setSize(width, height);
    JPanel cornerCell = initCell("#ffffff", 0, 0);
    int x = 50;
    int y = 0;
    heatmapPanelLayout.add(cornerCell);

    for (String headerCell : columns) {
        JPanel cell = initCell(headerCell, x, y);
        x += 50;
        heatmapPanelLayout.add(cell);

    }
    y = 50;
    for (String headerCell : rows) {
        JPanel cell = initCell(headerCell, 0, y);
        y += 50;
        heatmapPanelLayout.add(cell);

    }
    x = 50;
    y = 50;
    for (String[] row : data) {
        for (String color : row) {
            JPanel cell = initCell(color, x, y);
            heatmapPanelLayout.add(cell);
            x += 50;
        }
        x = 50;
        y += 50;
    }

    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = image.createGraphics();
    graphics.setPaint(Color.WHITE);
    heatmapPanelLayout.paint(graphics);
    //        super.paint(graphics);
    byte[] imageData = null;

    try {

        ImageEncoder in = ImageEncoderFactory.newInstance(ImageFormat.PNG, new Float(0.084666f));
        imageData = in.encode(image);
    } catch (Exception e) {
        System.out.println(e.getLocalizedMessage());
    }

    String base64 = Base64.encodeBytes(imageData);
    base64 = "data:image/png;base64," + base64;
    return base64;
    //
    //        JFrame frame = new JFrame();
    //        frame.setSize(1000, 1000);
    //        frame.add(heatmapPanelLayout);
    //        frame.setVisible(true);

    //        return "";
}

From source file:org.squale.squaleweb.util.graph.AbstractGraphMaker.java

/**
 * Permet de fabriquer l'image sous forme d'un tableau de byte <b>Attention : </b> la mthode de la classe fille
 * doit vrifier que mChart est initialis
 * //  w  w  w. j  a v a2s  .  c o m
 * @return un tableau de byte contenant une BufferedImage
 * @throws IOException si une erreur a lieu
 */
public byte[] getImageInBytes() throws IOException {
    BufferedImage bufImage = getChart().createBufferedImage(mWidth, mHeight);
    ImageEncoder encoder = ImageEncoderFactory.newInstance(mFormat);

    return encoder.encode(bufImage);
}

From source file:probe.com.view.body.quantdatasetsoverview.diseasegroupsfilters.heatmap.HeatMapImgGenerator.java

public String generateHeatmap(String[] rows, String[] columns, String[][] data) {

    JPanel heatmapPanelLayout = new JPanel();
    heatmapPanelLayout.setLayout(null);/*from  ww  w  .ja  v  a  2 s  .c  o  m*/
    heatmapPanelLayout.setVisible(true);

    int width = (columns.length + 1) * 50;
    int height = (rows.length + 1) * 50;
    heatmapPanelLayout.setSize(width, height);
    JPanel cornerCell = initCell("#ffffff", 0, 0);
    int x = 50;
    int y = 0;
    heatmapPanelLayout.add(cornerCell);

    for (String headerCell : columns) {
        JPanel cell = initCell(headerCell, x, y);
        x += 50;
        heatmapPanelLayout.add(cell);

    }
    y = 50;
    for (String headerCell : rows) {
        JPanel cell = initCell(headerCell, 0, y);
        y += 50;
        heatmapPanelLayout.add(cell);

    }
    x = 50;
    y = 50;
    for (String[] row : data) {
        for (String color : row) {
            JPanel cell = initCell(color, x, y);
            heatmapPanelLayout.add(cell);
            x += 50;
        }
        x = 50;
        y += 50;
    }

    BufferedImage image = new BufferedImage(width + 10, height + 10, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = image.createGraphics();
    graphics.setPaint(Color.WHITE);
    graphics.setBackground(Color.WHITE);
    heatmapPanelLayout.paint(graphics);
    byte[] imageData = null;

    try {

        ImageEncoder in = ImageEncoderFactory.newInstance(ImageFormat.PNG, new Float(0.084666f));
        imageData = in.encode(image);
    } catch (Exception e) {
        System.out.println(e.getLocalizedMessage());
    }

    String base64 = Base64.encodeBytes(imageData);
    base64 = "data:image/png;base64," + base64;
    return base64;

}

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

/**
 * {@inheritDoc}//ww  w  .  jav  a2  s  .c om
 */
@Override
public RenderedGraph renderGraph(int width, int height, Encoding encoding) throws GraphException {
    if (!isInitialized()) {
        throw new GraphException("Not Initialized");
    }

    ImageEncoder encoder = getEncoder(encoding);
    ChartRenderingInfo info = new ChartRenderingInfo();
    byte[] data;
    try {
        data = encoder.encode(renderImage(width, height, info));
    } catch (IOException e) {
        throw new GraphException("Image encoding failed", e);
    }

    return new JFreeChartRenderedGraph(info, data, encoding);
}

From source file:web.diva.server.model.SomClustering.SomClustImgGenerator.java

private String generateEncodedImg(BufferedImage upperTreeBImage) {
    String sideTreeBase64 = "";
    try {//from w  w w.  j av a 2 s  . co  m
        ImageEncoder in = ImageEncoderFactory.newInstance(ImageFormat.PNG, 0);

        byte[] imageData = in.encode(upperTreeBImage);
        sideTreeBase64 = Base64.encodeBase64String(imageData);
        sideTreeBase64 = "data:image/png;base64," + sideTreeBase64;
        System.gc();
    } catch (IOException exp) {
        System.err.println(exp.getLocalizedMessage());
    }
    return sideTreeBase64;
}