Example usage for org.jfree.chart.encoders ImageEncoderFactory newInstance

List of usage examples for org.jfree.chart.encoders ImageEncoderFactory newInstance

Introduction

In this page you can find the example usage for org.jfree.chart.encoders ImageEncoderFactory newInstance.

Prototype

public static ImageEncoder newInstance(String format) 

Source Link

Document

Used to retrieve an ImageEncoder for a specific image format.

Usage

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
 * //from  w  w w  .  ja  v a  2s . co 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:edu.jhuapl.graphs.jfreechart.JFreeChartBaseSource.java

private static ImageEncoder getEncoder(Encoding encoding) throws GraphException {
    switch (encoding) {
    case JPEG://from www. ja  v a2  s .  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:piramide.interaction.reasoner.FuzzyReasonerWizardFacade.java

@Override
public void generateMembershipFunctionGraph(boolean isInput, boolean isDevices, String variableName,
        RegionDistributionInfo[] linguisticTerms, OutputStream destination, int width, int height,
        Geolocation geo, DecayFunctions decayFunction, Calendar when) {
    BufferedImage img;/*  w w  w . ja v  a2  s  .c  om*/
    if (variableName == null) {
        img = createErrorMessagesImage("Error generating graph: variableName not provided");
    } else if (linguisticTerms == null) {
        img = createErrorMessagesImage("Error generating graph: linguisticTerms not provided");
    } else if (isInput && isDevices && !isValidDeviceVariableName(variableName)) {
        img = createErrorMessagesImage("Error generating graph: invalid device variable name: " + variableName);
    } else if (isInput && !isDevices && !isValidUserVariableName(variableName)) {
        img = createErrorMessagesImage("Error generating graph: invalid user variable name: " + variableName);
    } else {
        try {
            final WarningStore warningStore = new WarningStore();
            final net.sourceforge.jFuzzyLogic.rule.Variable variable = processVariable(isInput, isDevices,
                    variableName, linguisticTerms, geo, decayFunction, when, warningStore);

            final JFreeChart theChart = variable.chart(false);

            final String[] messages = warningStore.getMessages();
            if (messages.length > 0) {
                final Font font = TextTitle.DEFAULT_FONT;
                final Font bigBold = new Font(font.getName(), Font.BOLD, font.getSize() + 2);
                final Font bold = new Font(font.getName(), Font.BOLD, font.getSize());

                theChart.addSubtitle(new TextTitle("WARNINGS:", bigBold, Color.RED, Title.DEFAULT_POSITION,
                        Title.DEFAULT_HORIZONTAL_ALIGNMENT, Title.DEFAULT_VERTICAL_ALIGNMENT,
                        Title.DEFAULT_PADDING));
                for (String message : messages)
                    theChart.addSubtitle(new TextTitle(message, bold, Color.RED, Title.DEFAULT_POSITION,
                            Title.DEFAULT_HORIZONTAL_ALIGNMENT, Title.DEFAULT_VERTICAL_ALIGNMENT,
                            Title.DEFAULT_PADDING));
            }
            img = theChart.createBufferedImage(width, height);

        } catch (FuzzyReasonerException e) {
            e.printStackTrace();
            img = createErrorMessagesImage("Error generating graph: " + e.getMessage());
        }
    }

    try {
        final ImageEncoder myEncoder = ImageEncoderFactory.newInstance("png");
        myEncoder.encode(img, destination);
        destination.flush();
        destination.close();
    } catch (IOException e) {
        // Cry
        e.printStackTrace();
        return;
    }
}

From source file:ch.agent.crnickl.demo.stox.Chart.java

private void saveChartAsPNG(JFreeChart chart, String fileName, int width, int height) throws KeyedException {
    OutputStream out = null;//from   ww  w .  j  a  va  2 s.  co m
    try {
        out = new BufferedOutputStream(new FileOutputStream(fileName));
        BufferedImage bufferedImage = chart.createBufferedImage(width, height, null);
        ImageEncoder imageEncoder = ImageEncoderFactory.newInstance("png");
        imageEncoder.encode(bufferedImage, out);
    } catch (Exception e) {
        throw K.JFC_OUTPUT_ERR.exception(e, fileName);
    } finally {
        try {
            if (out != null)
                out.close();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}