JRViewer 显示整页图像时冻结
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您有两种选择
1) 将图像作为 Icon 放置到 < a href="http://docs.oracle.com/javase/tutorial/uiswing/components/label.html" rel="nofollow">JLabel
2) 对于 Swing JComponets 是
paintComponent()
paint()
,请阅读有关图形
此论坛上有大量示例(Swing 标记),
You have two choices
1) put your image as Icon to JLabel
2) for Swing JComponets is there
paintComponent()
instead ofpaint()
,please read tutorial about Graphics
tons of examples on this forum (Swing tagged),
问题已解决。 JRViewer 中有一个参数:
因此,如果设置了此参数,则报告将在
JLabel
上绘制为ImageIcon
。否则,它是使用 JRGraphics2DExporter 绘制的,在处理大图像时速度要慢得多。所以解决方案是在属性文件中设置指定的属性或使用如下方式:
The issue is resolved. There is a parameter in the JRViewer:
So, if this parameter is set, the reports is drawn as an
ImageIcon
on aJLabel
. Otherwise, it's drawn usingJRGraphics2DExporter
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: