List of usage examples for org.jfree.chart.encoders EncoderUtil writeBufferedImage
public static void writeBufferedImage(BufferedImage image, String format, OutputStream outputStream, boolean encodeAlpha) throws IOException
From source file:net.sf.mzmine.chartbasics.graphicsexport.ChartExportUtil.java
public static void writeChartToJPEG(JFreeChart chart, ChartRenderingInfo info, int width, int height, File fileName, int resolution) throws IOException { // Background color Paint saved = chart.getBackgroundPaint(); if (((Color) saved).getAlpha() == 0) { chart.setBackgroundPaint(Color.WHITE); chart.setBackgroundImageAlpha(255); if (chart.getLegend() != null) chart.getLegend().setBackgroundPaint(Color.WHITE); // legends and stuff for (int i = 0; i < chart.getSubtitleCount(); i++) if (PaintScaleLegend.class.isAssignableFrom(chart.getSubtitle(i).getClass())) ((PaintScaleLegend) chart.getSubtitle(i)).setBackgroundPaint(Color.WHITE); // apply bg chart.getPlot().setBackgroundPaint(Color.WHITE); }/*w w w . jav a 2s . co m*/ // if (resolution == 72) writeChartToJPEG(chart, width, height, fileName); else { OutputStream out = new BufferedOutputStream(new FileOutputStream(fileName)); try { BufferedImage image = paintScaledChartToBufferedImage(chart, info, out, width, height, resolution, BufferedImage.TYPE_INT_RGB); EncoderUtil.writeBufferedImage(image, ImageFormat.JPEG, out, 1.f); } finally { out.close(); } } }