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;
        }
    }
  • 相关阅读:
    Python使用pymysql模块插入数据报错
    layui的select标签样式没有加载出来
    Python计算平均数
    Django获取小时内的数据
    mysql5.0忘记登录密码
    数据库介绍
    Linux基础
    测试理论
    计算机基础
    chrome 70 一下载文件就卡死
  • 原文地址:https://www.cnblogs.com/steveshao/p/12030933.html
Copyright © 2011-2022 走看看