0
votes

I want to save a image to file and the documentation mentions ImageExportFormat method: Chart1.getExport().getImage().getJPEG().save(javax.imageio.stream.ImageOutputStream ios)

Doco: http://www.steema.com/files/public/teechart/java/v1/docs/JavaDoc/com/steema/teechart/exports/ImageExportFormat.html

This method is not recognised by my code. Has this been removed ? Is there an alternate way I can do this via a stream?

Regards, Clayton

1

1 Answers

0
votes

The example below shows how to export to a jpeg file in Swing. A stream could be used natively instead of using ‘File’.

public void save() throws IOException {

    Image img = chart1.image(chart1.getWidth(), chart1.getHeight());
    RenderedImage rendImage = (RenderedImage) img;
    Iterator iter = ImageIO.getImageWritersByFormatName("jpg");

    File outfile = new File("c:\\output\\testjavaChart.jpg");
    ImageOutputStream ios = ImageIO.createImageOutputStream(outfile);

    ImageWriter writer = (ImageWriter) iter.next();

    ImageWriteParam format = new javax.imageio.plugins.jpeg.JPEGImageWriteParam(java.util.Locale.getDefault());

    writer.setOutput(ios);
    // Write the image
    writer.write(null, new IIOImage(rendImage, null, null), format);

    // Cleanup
    ios.flush();
    ios.close();
    writer.dispose();
}

If you are using SWT, don't hesitate to let us know.