iReport資料緊俏,整理好就趕緊傳上來:
工具類:JpgExport
public class JpgExportUtil { public static String Export(Map<String, Object> params,String jasperPath,String jpgPath) { String info = ""; if(!"".equals(jasperPath)&&!"".equals(jpgPath)) { try { JasperPrint jasperPrint = JasperFillManager.fillReport(jasperPath, params, new JREmptyDataSource()); // 創建graphics輸出器 JRGraphics2DExporter exporter = new JRGraphics2DExporter(); // 創建一個影像對象 BufferedImage bufferedImage = new BufferedImage(jasperPrint.getPageWidth() * 4, jasperPrint.getPageHeight() * 4, BufferedImage.TYPE_INT_RGB); // 取graphics Graphics2D g = (Graphics2D) bufferedImage.getGraphics(); // 設置相應參數信息 exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, g); exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, Float.valueOf(4)); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.exportReport(); g.dispose();// 釋放資源信息 // 這里的bufferedImage就是最終的影像圖像信息,可以通過這個對象導入. ImageIO.write(bufferedImage, "JPEG", new File(jpgPath)); info="success"; } catch(JRException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }else { info="null"; } return info; } }