zoukankan      html  css  js  c++  java
  • java通过jasper文件生成jpg图片

    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;
        }
    }
  • 相关阅读:
    27、springboot整合RabbitMQ(1)
    26、springboot与消息
    25、springboot与缓存整合Redis
    24、springboot与缓存(2)
    linux之参数实用讲解
    linux之创建临时文件的方法
    【转】linux之shfit
    linux之stat
    Shell 环境中的输入输出重定向
    Linux下samba的安装与配置
  • 原文地址:https://www.cnblogs.com/steveshao/p/12030933.html
Copyright © 2011-2022 走看看