0

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

4

1 回答 1

0

下面的示例显示了如何在 Swing 中导出为 jpeg 文件。可以本机使用流而不是使用“文件”。

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();
}

如果您正在使用 SWT,请随时告诉我们。

于 2012-09-04T12:07:17.283 回答