使用许多连续图像时如何修复 java 堆 space 内存不足
How to fix java heap space out of memory when using many successive images
正在尝试使用 JasperReport 执行一些打印。
JasperReport 提供了将文档打印到 BufferedImage 的功能,我将其转换为 WritableImage 以将其显示在 ImageView 对象上(如下面的代码所示)。
我在 getImage(int pageNumber) 函数中得到 Java 堆 space 内存不足异常。我的猜测是没有释放对图像的旧引用。
可以解决这个问题吗?
private void viewPage(int pageNumber) throws JRException {
this.resultViewer.setFitHeight(this.imageHeight * this.zoomFactor);
this.resultViewer.setFitWidth(this.imageWidth * this.zoomFactor);
this.resultViewer.setImage(this.getImage(pageNumber));
}
@FXML
private ImageView resultViewer;
private WritableImage getImage(int pageNumber) throws JRException {
return SwingFXUtils
.toFXImage((BufferedImage) JasperPrintManager.printPageToImage(this.jasperPrint, pageNumber, 2), null);
}
我通过在显示下一个之前在上一个显示的 BufferedImage 上调用 flush() 函数解决了这个问题
正在尝试使用 JasperReport 执行一些打印。
JasperReport 提供了将文档打印到 BufferedImage 的功能,我将其转换为 WritableImage 以将其显示在 ImageView 对象上(如下面的代码所示)。
我在 getImage(int pageNumber) 函数中得到 Java 堆 space 内存不足异常。我的猜测是没有释放对图像的旧引用。
可以解决这个问题吗?
private void viewPage(int pageNumber) throws JRException {
this.resultViewer.setFitHeight(this.imageHeight * this.zoomFactor);
this.resultViewer.setFitWidth(this.imageWidth * this.zoomFactor);
this.resultViewer.setImage(this.getImage(pageNumber));
}
@FXML
private ImageView resultViewer;
private WritableImage getImage(int pageNumber) throws JRException {
return SwingFXUtils
.toFXImage((BufferedImage) JasperPrintManager.printPageToImage(this.jasperPrint, pageNumber, 2), null);
}
我通过在显示下一个之前在上一个显示的 BufferedImage 上调用 flush() 函数解决了这个问题