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; } }