List of usage examples for org.jfree.chart.encoders ImageFormat JPEG
String JPEG
To view the source code for org.jfree.chart.encoders ImageFormat JPEG.
Click Source Link
From source file:edu.cudenver.bios.chartsvc.representation.LegendImageRepresentation.java
/** * Called internally by Restlet library to write the image as the HTTP * response.//from w ww . j av a 2 s . c o m * @param out output stream */ @Override public void write(OutputStream out) throws IOException { // build the legend from the plot, and write it to a jpeg image if (plot != null) { LegendTitle legend = new LegendTitle(plot, new ColumnArrangement(), new ColumnArrangement()); legend.setFrame(BlockBorder.NONE); //legend.setMargin(new RectangleInsets(2.0, 2.0, 2.0, 2.0)); legend.setBackgroundPaint(Color.white); legend.setPosition(RectangleEdge.BOTTOM); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); Rectangle2D.Double legendArea = new Rectangle2D.Double(0, 0, width, height); g.clip(legendArea); legend.arrange(g, new RectangleConstraint(width, height)); legend.draw(g, legendArea); g.dispose(); EncoderUtil.writeBufferedImage(image, ImageFormat.JPEG, out); } }
From source file:org.efs.openreports.engine.ChartReportEngine.java
private static ChartEngineOutput createChartOutput(ReportChart reportChart, ChartValue[] values) { JFreeChart chart = null;// w w w . j a va 2s . co m switch (reportChart.getChartType()) { case ReportChart.BAR_CHART: chart = createBarChart(reportChart, values); break; case ReportChart.PIE_CHART: chart = createPieChart(reportChart, values); break; case ReportChart.XY_CHART: chart = createXYChart(reportChart, values); break; case ReportChart.TIME_CHART: chart = createTimeChart(reportChart, values); break; case ReportChart.RING_CHART: chart = createRingChart(reportChart, values); break; } if (chart == null) return null; chart.setBackgroundPaint(Color.WHITE); ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); BufferedImage bufferedImage = chart.createBufferedImage(reportChart.getWidth(), reportChart.getHeight(), info); byte[] image = null; try { image = EncoderUtil.encode(bufferedImage, ImageFormat.JPEG); } catch (IOException ioe) { log.warn(ioe); } ChartEngineOutput chartOutput = new ChartEngineOutput(); chartOutput.setContent(image); chartOutput.setContentType(ReportEngineOutput.CONTENT_TYPE_JPEG); chartOutput.setChartRenderingInfo(info); chartOutput.setChartValues(values); return chartOutput; }
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 ww. ja v a2 s .c o 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(); } } }
From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java
/** * Writes a chart to an output stream in JPEG format. This method allows * you to pass in a {@link ChartRenderingInfo} object, to collect * information about the chart dimensions/entities. You will need this * info if you want to create an HTML image map. * * @param out the output stream (<code>null</code> not permitted). * @param chart the chart (<code>null</code> not permitted). * @param width the image width.//from ww w. j a va 2s . co m * @param height the image height. * @param info the chart rendering info (<code>null</code> permitted). * @param shapeMap * * @throws IOException if there are any I/O errors. */ public static void writeChartAsJPEG(File file, JFreeChart chart, int width, int height, ChartRenderingInfo info, Rectangle2D imageArea, LinkedHashMap<AbstractMask, Color> maskList, LinkedHashMap<Shape, Color> shapeMap, LinkedHashMap<Rectangle2D, String> textContentMap) throws IOException { if (file == null) { throw new IllegalArgumentException("Null 'file' argument."); } if (chart == null) { throw new IllegalArgumentException("Null 'chart' argument."); } OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); BufferedImage image = chart.createBufferedImage(width, height, BufferedImage.TYPE_INT_RGB, info); Graphics2D g2 = image.createGraphics(); drawMasks(g2, imageArea, maskList, null, chart); drawShapes(g2, imageArea, shapeMap, chart); drawText(g2, imageArea, textContentMap, chart); g2.dispose(); try { EncoderUtil.writeBufferedImage(image, ImageFormat.JPEG, out); } finally { out.close(); } }