【问题标题】:JRViewer freezing when displaying full page images显示整页图像时 JRViewer 冻结
【发布时间】:2012-01-22 01:52:46
【问题描述】:

我正在使用 JasperViewer 在 Java 桌面应用程序中显示报告。 该报告由 2 页组成 - 每页代表一张图片。

问题是,当用户在查看器中滚动页面时,会出现巨大的冻结。 图像的大小不是很大,大约 1000x1000。

图像是这样生成的:

private BufferedImage createImage(Component panel) {
    int w = (int) panel.getSize().getWidth();
    int h = (int) panel.getSize().getHeight();
    BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = bi.createGraphics();
    panel.paint(g);
    g.dispose();
    return bi;
}

【问题讨论】:

    标签: java image swing jasper-reports graphics2d


    【解决方案1】:

    你有两个选择

    1) 将您的图片作为Icon 转为JLabel

    2) 对于Swing JComponetspaintComponent() 而不是paint()

    • 请阅读关于Graphics的教程

    • 本论坛上有大量示例(Swing 标记),

    【讨论】:

    • 图像的生成方式与 Jasper Viewer 冻结的原因之间有什么关系吗?
    • 第一名是使用paint() 方法,第二名是使用方法从/到数据库的连接(如果存在),第三名是如何从报告生成图像,尝试将其拆分为这些三个区域并分别进行测试,如果您使用的是某些 IDE,则使用 JProfiler(我将其用作 NetBeans 中的内置)或 JMeter 或 ... 分析此代码
    • 作为参考,这个example 滚动更大的图像没有任何问题。
    • 图像和报告只生成一次。不需要太多时间。所以问题不在于图像生成。当报表显示在 内部 JasperViewer 组件时,就会看到冻结。
    • @Andrei Podoprigora 1) 您必须检查 JasperViewer 是基于 AWT 还是 Swing,2) 您是否尝试过 JProfiler,您必须在那里捕获内存或处理器问题
    【解决方案2】:

    问题已解决。 JRViewer里面有个参数:

    //Maximum size (in pixels) of a buffered image that would be used by {@link JRViewer JRViewer} to render a report page.
    //If rendering a report page would require an image larger than this threshold
    //(i.e. image width x image height > maximum size), the report page will be rendered directly on the viewer component.
    //If this property is zero or negative, buffered images will never be user to render a report page.
    //By default, this property is set to 0.
    public static final String VIEWER_RENDER_BUFFER_MAX_SIZE
    

    因此,如果设置了此参数,则报告将在JLabel 上绘制为ImageIcon。否则,它使用JRGraphics2DExporter 绘制,在处理大图像时会慢得多。

    所以解决方法是在属性文件中设置指定的属性或者使用这样的方式:

     /**
     * This number represents maximum size of an image ( x*y )
     * So this value cover up to 300% zoom for an image 1000x1000 pixels
     */
    public static final String MAX_PIXELS_NUMBER = "10000000";   
    
    static {
            try {
                JRProperties.setProperty(JRViewer.VIEWER_RENDER_BUFFER_MAX_SIZE, MAX_PIXELS_NUMBER);
            } catch (Exception e) {
                System.err.println("Cannot set the VIEWER_RENDER_BUFFER_MAX_SIZE property. Reports will be rendered slowly.");
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2017-05-24
      • 1970-01-01
      • 2020-02-26
      • 2013-08-09
      • 2011-08-07
      • 2018-11-28
      • 2018-11-23
      • 1970-01-01
      • 2011-08-21
      相关资源
      最近更新 更多