[英]Apache POI pptx to image take too much time for processing
I have code to convert pptx slide into image and display the image in swing panel. 我有将pptx幻灯片转换为图像并在摆动面板中显示图像的代码。
When i run my code in eclipse, it takes 10 Sec to display the panel whereas same code run via jar, it takes more than one minute to open the panel. 当我在eclipse中运行代码时,显示面板需要10秒,而通过jar运行相同的代码,则需要花费一分钟以上的时间才能打开面板。
It happens only when user open it first time, Later it loads faster. 仅当用户第一次打开它时,它才会发生,之后它加载会更快。
Any help would be appreciated and thanks in advance. 任何帮助将不胜感激,并在此先感谢。
Here i included the code 我在这里包括了代码
// currentPage - Slide number to display
// source - pptx file path
public void Display(int currentPage, String source) {
try {
FileInputStream is = new FileInputStream(source);
XMLSlideShow ppt = new XMLSlideShow(is);
is.close();
double zoom = 1; // magnify it by 2
AffineTransform at = new AffineTransform();
at.setToScale(zoom, zoom);
Dimension pgsize = ppt.getPageSize();
XSLFSlide[] slides = ppt.getSlides();
all = slides.length;
lblPage.setText(currentPage + " / " + all);
current = currentPage;
BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = img.createGraphics();
graphics.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
graphics.transform(at);
graphics.setColor(Color.white);
graphics.clearRect(0, 0, pgsize.width, pgsize.height);
graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
System.out.println("Before draw: " + new Date());
slides[currentPage - 1].draw(graphics);
System.out.println("After draw: " + new Date());
// save the output
Image newImg = img.getScaledInstance(lblPresentasi.getWidth(), lblPresentasi.getHeight(), Image.SCALE_SMOOTH);
final ImageIcon icon = new ImageIcon(newImg);
lblPresentasi.setIcon(icon);
lblPresentasi.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
JLabel label = (JLabel) e.getComponent();
Dimension size = label.getSize();
Image resized = icon.getImage().getScaledInstance(size.width-10, size.height-10, Image.SCALE_FAST);
label.setIcon(new ImageIcon(resized));
}
});
graphics.dispose();
newImg.flush();
} catch (Exception e) {
e.printStackTrace();
}
}// end of method Display()
This delay was caused by One-Jar custom class loader. 此延迟是由One-Jar自定义类加载器引起的。 At first time, it takes more time to load the dependency libraries and load it classes.
第一次,需要花费更多时间来加载依赖库并加载其类。
So, I removed one-jar and using JarSplice to load the dependency libraries classes , it works great. 因此,我删除了一个jar,并使用JarSplice加载依赖项库类,它很好用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.