JRViewer 显示整页图像时冻结

发布于 2024-12-21 11:39:41 字数 487 浏览 0 评论 0原文

我正在使用 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;
}

I am using a JasperViewer to display the report inside of a Java desktop application.
The report consists of 2 pages - each of them represents an image.

The problem is, when user scrolls the page inside the viewer, there are huge freezes.
The size of image isn't so big, about 1000x1000.

The image is generated in this way:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

妳是的陽光 2024-12-28 11:39:41

您有两种选择

1) 将图像作为 Icon 放置到 < a href="http://docs.oracle.com/javase/tutorial/uiswing/components/label.html" rel="nofollow">JLabel

2) 对于 Swing JComponetspaintComponent() paint()

  • 请阅读有关图形

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

You have two choices

1) put your image as Icon to JLabel

2) for Swing JComponets is there paintComponent() instead of paint(),

  • please read tutorial about Graphics

  • tons of examples on this forum (Swing tagged),

唯憾梦倾城 2024-12-28 11:39:41

问题已解决。 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.");
        }
    }

The issue is resolved. There is a parameter in the 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

So, if this parameter is set, the reports is drawn as an ImageIcon on a JLabel. Otherwise, it's drawn using JRGraphics2DExporter that is much more slower when working with big images.

So the solution is to set the specified property in the property file or using way like this:

 /**
 * 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.");
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文