簡體   English   中英

Apache POI pptx到圖像處理需要太多時間

[英]Apache POI pptx to image take too much time for processing

我有將pptx幻燈片轉換為圖像並在擺動面板中顯示圖像的代碼。

當我在eclipse中運行代碼時,顯示面板需要10秒,而通過jar運行相同的代碼,則需要花費一分鍾以上的時間才能打開面板。

僅當用戶第一次打開它時,它才會發生,之后它加載會更快。

任何幫助將不勝感激,並在此先感謝。

我在這里包括了代碼

 // 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()

此延遲是由One-Jar自定義類加載器引起的。 第一次,需要花費更多時間來加載依賴庫並加載其類。

因此,我刪除了一個jar,並使用JarSplice加載依賴項庫類,它很好用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM