List of usage examples for org.jfree.chart.encoders ImageFormat PNG
String PNG
To view the source code for org.jfree.chart.encoders ImageFormat PNG.
Click Source Link
From source file:com.pureinfo.srm.common.ImageHelper.java
public static void drawImage(String _sString, OutputStream _os) throws PureException { int nWidth = 200; int nHeight = 50; String sText = _sString;/* ww w .j av a2 s . c om*/ BufferedImage image = new BufferedImage(nWidth, nHeight, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); for (int i = 0; i < sText.length(); i++) { draw(String.valueOf(sText.charAt(i)), g2, i * nWidth / sText.length(), 0, (i + 1) * nWidth / sText.length(), nHeight); } g2.dispose(); try { EncoderUtil.writeBufferedImage(image, ImageFormat.PNG, _os); } catch (Exception ex) { throw new PureException(PureException.UNKNOWN, "", ex); } }
From source file:probe.com.model.util.SwingToImageGenerator.java
private String generateEncodedImg(BufferedImage image) { String base64 = ""; try {// w ww . ja va2 s .c o m ImageEncoder in = ImageEncoderFactory.newInstance(ImageFormat.PNG, 0); byte[] imageData = in.encode(image); base64 = Base64.encodeBase64String(imageData); base64 = "data:image/png;base64," + base64; System.gc(); } catch (IOException exp) { System.err.println(exp.getLocalizedMessage()); } return base64; }
From source file:probe.com.view.body.quantdatasetsoverview.diseasegroupsfilters.heatmap.HeatMapImgGenerator.java
public String generateHeatmap(String[] rows, String[] columns, String[][] data) { JPanel heatmapPanelLayout = new JPanel(); heatmapPanelLayout.setLayout(null);//www . j av a 2 s .c o m heatmapPanelLayout.setVisible(true); int width = (columns.length + 1) * 50; int height = (rows.length + 1) * 50; heatmapPanelLayout.setSize(width, height); JPanel cornerCell = initCell("#ffffff", 0, 0); int x = 50; int y = 0; heatmapPanelLayout.add(cornerCell); for (String headerCell : columns) { JPanel cell = initCell(headerCell, x, y); x += 50; heatmapPanelLayout.add(cell); } y = 50; for (String headerCell : rows) { JPanel cell = initCell(headerCell, 0, y); y += 50; heatmapPanelLayout.add(cell); } x = 50; y = 50; for (String[] row : data) { for (String color : row) { JPanel cell = initCell(color, x, y); heatmapPanelLayout.add(cell); x += 50; } x = 50; y += 50; } BufferedImage image = new BufferedImage(width + 10, height + 10, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = image.createGraphics(); graphics.setPaint(Color.WHITE); graphics.setBackground(Color.WHITE); heatmapPanelLayout.paint(graphics); byte[] imageData = null; try { ImageEncoder in = ImageEncoderFactory.newInstance(ImageFormat.PNG, new Float(0.084666f)); imageData = in.encode(image); } catch (Exception e) { System.out.println(e.getLocalizedMessage()); } String base64 = Base64.encodeBytes(imageData); base64 = "data:image/png;base64," + base64; return base64; }
From source file:probe.com.model.util.vaadintoimageutil.HeatmapSwingComponent.java
public String generateHeatmap(String[] rows, String[] columns, String[][] data) { JPanel heatmapPanelLayout = new JPanel(); heatmapPanelLayout.setLayout(null);//from w w w . j a v a 2 s . co m heatmapPanelLayout.setVisible(true); heatmapPanelLayout.setBorder(new LineBorder(Color.BLACK)); int width = (columns.length + 1) * 50; int height = (rows.length + 1) * 50; heatmapPanelLayout.setSize(width, height); JPanel cornerCell = initCell("#ffffff", 0, 0); int x = 50; int y = 0; heatmapPanelLayout.add(cornerCell); for (String headerCell : columns) { JPanel cell = initCell(headerCell, x, y); x += 50; heatmapPanelLayout.add(cell); } y = 50; for (String headerCell : rows) { JPanel cell = initCell(headerCell, 0, y); y += 50; heatmapPanelLayout.add(cell); } x = 50; y = 50; for (String[] row : data) { for (String color : row) { JPanel cell = initCell(color, x, y); heatmapPanelLayout.add(cell); x += 50; } x = 50; y += 50; } BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = image.createGraphics(); graphics.setPaint(Color.WHITE); heatmapPanelLayout.paint(graphics); // super.paint(graphics); byte[] imageData = null; try { ImageEncoder in = ImageEncoderFactory.newInstance(ImageFormat.PNG, new Float(0.084666f)); imageData = in.encode(image); } catch (Exception e) { System.out.println(e.getLocalizedMessage()); } String base64 = Base64.encodeBytes(imageData); base64 = "data:image/png;base64," + base64; return base64; // // JFrame frame = new JFrame(); // frame.setSize(1000, 1000); // frame.add(heatmapPanelLayout); // frame.setVisible(true); // return ""; }
From source file:com.pureinfo.srm.common.ImageHelper.java
public static void drawRectangle(Paint _color, Point _point, OutputStream _os) throws PureException { int nWidth = _point.x; int nHeight = _point.y; BufferedImage image = new BufferedImage(nWidth, nHeight, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.setPaint(_color);/*from ww w.jav a 2 s. c o m*/ g2.fillRect(0, 0, nWidth, nHeight); g2.dispose(); try { EncoderUtil.writeBufferedImage(image, ImageFormat.PNG, _os); } catch (Exception ex) { throw new PureException(PureException.UNKNOWN, "", ex); } }
From source file:org.adempiere.webui.apps.graph.jfreegraph.ChartRendererServiceImpl.java
@Override public boolean renderPerformanceIndicator(Component parent, int chartWidth, int chartHeight, IndicatorModel model) {/*from w w w . j a va 2s .co m*/ PerformanceGraphBuilder builder = new PerformanceGraphBuilder(); JFreeChart chart = builder.createIndicatorChart(model); chart.setBackgroundPaint(model.chartBackground); chart.setAntiAlias(true); BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, null); try { byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage image = new AImage("", bytes); Image myImage = new Image(); myImage.setContent(image); parent.appendChild(myImage); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
From source file:org.adempiere.webui.editor.WChartEditor.java
private void render(JFreeChart chart) { ChartRenderingInfo info = new ChartRenderingInfo(); int width = 400; int height = chartModel.getWinHeight(); BufferedImage bi = chart.createBufferedImage(width, height, BufferedImage.TRANSLUCENT, info); try {/*from w w w .ja v a 2 s.com*/ byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage image = new AImage("", bytes); Imagemap myImage = new Imagemap(); Panel panel = getComponent(); myImage.setContent(image); if (panel.getPanelchildren() != null) { panel.getPanelchildren().getChildren().clear(); panel.getPanelchildren().appendChild(myImage); } else { Panelchildren pc = new Panelchildren(); panel.appendChild(pc); pc.appendChild(myImage); } int count = 0; for (Iterator<?> it = info.getEntityCollection().getEntities().iterator(); it.hasNext();) { ChartEntity entity = (ChartEntity) it.next(); String key = null; String seriesName = null; if (entity instanceof CategoryItemEntity) { CategoryItemEntity item = ((CategoryItemEntity) entity); Comparable<?> colKey = item.getColumnKey(); Comparable<?> rowKey = item.getRowKey(); if (colKey != null && rowKey != null) { key = colKey.toString(); seriesName = rowKey.toString(); } } else if (entity instanceof PieSectionEntity) { Comparable<?> sectionKey = ((PieSectionEntity) entity).getSectionKey(); if (sectionKey != null) { key = sectionKey.toString(); } } if (entity instanceof XYItemEntity) { XYItemEntity item = ((XYItemEntity) entity); if (item.getDataset() instanceof TimeSeriesCollection) { TimeSeriesCollection data = (TimeSeriesCollection) item.getDataset(); TimeSeries series = data.getSeries(item.getSeriesIndex()); TimeSeriesDataItem dataitem = series.getDataItem(item.getItem()); seriesName = series.getKey().toString(); key = dataitem.getPeriod().toString(); } } if (key == null) continue; Area area = new Area(); myImage.appendChild(area); area.setCoords(entity.getShapeCoords()); area.setShape(entity.getShapeType()); area.setTooltiptext(entity.getToolTipText()); area.setId(count + "_WG__" + seriesName + "__" + key); count++; } myImage.addEventListener(Events.ON_CLICK, new EventListener() { public void onEvent(Event event) throws Exception { MouseEvent me = (MouseEvent) event; String areaId = me.getArea(); if (areaId != null) { String[] strs = areaId.split("__"); if (strs.length == 3) { chartMouseClicked(strs[2], strs[1]); } } } }); } catch (Exception e) { log.log(Level.SEVERE, "", e); } }
From source file:com.swordlord.gozer.components.fop.graph.GFopAreaChart.java
@Override public String toString() { try {//from ww w. j a v a 2s .co m StringBuilder sb = new StringBuilder(); sb.append( "<fo:block text-align=\"center\"><fo:external-graphic content-width=\"600\" src=\"data:image/png;base64,"); byte[] arr = EncoderUtil.encode(_image.createBufferedImage(), ImageFormat.PNG, 1, true); sb.append(new BASE64Encoder().encode(arr)); sb.append("\" /></fo:block>"); return sb.toString(); } catch (Exception e) { e.printStackTrace(); System.out.println(e); return ""; } }
From source file:org.adempiere.webui.apps.graph.jfreegraph.ChartRendererServiceImpl.java
@Override public boolean renderPerformanceGraph(Component parent, int chartWidth, int chartHeight, final GoalModel goalModel) { GraphBuilder builder = new GraphBuilder(); builder.setMGoal(goalModel.goal);// ww w. j a va 2 s . c o m builder.setXAxisLabel(goalModel.xAxisLabel); builder.setYAxisLabel(goalModel.yAxisLabel); builder.loadDataSet(goalModel.columnList); JFreeChart chart = builder.createChart(goalModel.chartType); ChartRenderingInfo info = new ChartRenderingInfo(); chart.getPlot().setForegroundAlpha(0.6f); if (goalModel.zoomFactor > 0) { chartWidth = chartWidth * goalModel.zoomFactor / 100; chartHeight = chartHeight * goalModel.zoomFactor / 100; } if (!goalModel.showTitle) { chart.setTitle(""); } BufferedImage bi = chart.createBufferedImage(chartWidth, chartHeight, BufferedImage.TRANSLUCENT, info); try { byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage image = new AImage("", bytes); Imagemap myImage = new Imagemap(); myImage.setContent(image); parent.appendChild(myImage); int count = 0; for (Iterator<?> it = info.getEntityCollection().getEntities().iterator(); it.hasNext();) { ChartEntity entity = (ChartEntity) it.next(); String key = null; if (entity instanceof CategoryItemEntity) { Comparable<?> colKey = ((CategoryItemEntity) entity).getColumnKey(); if (colKey != null) { key = colKey.toString(); } } else if (entity instanceof PieSectionEntity) { Comparable<?> sectionKey = ((PieSectionEntity) entity).getSectionKey(); if (sectionKey != null) { key = sectionKey.toString(); } } if (key == null) { continue; } Area area = new Area(); myImage.appendChild(area); area.setCoords(entity.getShapeCoords()); area.setShape(entity.getShapeType()); area.setTooltiptext(entity.getToolTipText()); area.setId(count + "_WG_" + key); count++; } myImage.addEventListener(Events.ON_CLICK, new EventListener<Event>() { public void onEvent(Event event) throws Exception { MouseEvent me = (MouseEvent) event; String areaId = me.getArea(); if (areaId != null) { List<GraphColumn> list = goalModel.columnList; for (int i = 0; i < list.size(); i++) { String s = "_WG_" + list.get(i).getLabel(); if (areaId.endsWith(s)) { chartMouseClicked(goalModel.goal, list.get(i)); return; } } } } }); } catch (Exception e) { log.log(Level.SEVERE, "", e); return false; } return true; }
From source file:table.FrequencyTablePanel.java
private void writeTableAsPNG(OutputStream out, JTable table, int width, int height) throws IOException { BufferedImage bufferedImage = createImage(table); EncoderUtil.writeBufferedImage(bufferedImage, ImageFormat.PNG, out); }