簡體   English   中英

Jasper報告中缺少圖像

[英]Missing image in Jasper Reports

我正在嘗試從Java代碼生成Jasper報告,我的Java應用程序是Swing。 我使用TIBCO Jaspersoft Studio 6.0.0 final設計了Jasper報告。 但是,在我的報告中,有一個徽標圖像。 圖像位置是動態傳遞的,在Jaspersoft Studio上預覽時可以正常工作。 以下是圖像是如何的JasperSoft studio.The設置imagePath變量是String

<image>
    <reportElement x="210" y="0" width="140" height="76" uuid="2c20bfe9-e8af-4ca4-9c06-3c81ebe5f8a1"/>
    <imageExpression><![CDATA[$P{imagePath}]]></imageExpression>
</image> 

這就是我用Java生成報告的方式。

private class PrintClientListBtnAction implements ActionListener
     {

        @Override
        public void actionPerformed(ActionEvent e) 
        {
            ReportConnector r = new ReportHandler();
            try {
                HashMap<String, Object> params = new HashMap<String, Object>();
                params.put("imagePath", ClassLoader.getSystemResourceAsStream("/ReportResources/Logo_Big2i.png"));
                r.printReport(getClass().getResourceAsStream("/ReportResources/Core_Clients.jasper"), params);

            } catch (JRException ex) {
                ex.printStackTrace();
                JOptionPane.showMessageDialog(null, ex.getLocalizedMessage(),"Printing error",JOptionPane.ERROR_MESSAGE);
            }
        }

     }

問題是,由Java代碼生成的報告沒有圖像! 這是怎么了

更新

我也嘗試使用imagePath作為InputStream ,但是這里的結果相同...

我不認為您的圖像應該通過系統類加載器加載。 嘗試更換

ClassLoader.getSystemResourceAsStream(

通過

PrintClientListBtnAction.class.getResourceAsStream(

暫無
暫無

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

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