List of usage examples for org.jfree.chart.encoders ImageEncoderFactory newInstance
public static ImageEncoder newInstance(String format, boolean encodingAlpha)
From source file:probe.com.model.util.SwingToImageGenerator.java
private String generateEncodedImg(BufferedImage image) { String base64 = ""; try {//from w ww. ja v a2 s .com 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);//w w w . ja v 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 ww . j a va 2s. 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:web.diva.server.model.SomClustering.SomClustImgGenerator.java
private String generateEncodedImg(BufferedImage upperTreeBImage) { String sideTreeBase64 = ""; try {// w w w .j a v a 2s . c om ImageEncoder in = ImageEncoderFactory.newInstance(ImageFormat.PNG, 0); byte[] imageData = in.encode(upperTreeBImage); sideTreeBase64 = Base64.encodeBase64String(imageData); sideTreeBase64 = "data:image/png;base64," + sideTreeBase64; System.gc(); } catch (IOException exp) { System.err.println(exp.getLocalizedMessage()); } return sideTreeBase64; }