【问题标题】:Missing image in Jasper ReportsJasper 报告中缺少图像
【发布时间】:2014-12-15 07:42:53
【问题描述】:

我正在尝试从我的 Java 代码生成 Jasper 报告,我的 Java 应用程序是 Swing。我使用TIBCO Jaspersoft Studio 6.0.0 final 设计了 ​​Jasper 报告。但是,在我的报告中,有一个徽标图像。图像位置是动态传递的,在 Jaspersoft Studio 上预览时效果很好。以下是在 JasperSoft studio 中设置图像的方式。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,但结果相同...

【问题讨论】:

    标签: java swing io jasper-reports report


    【解决方案1】:

    我认为您的图像不应该通过系统类加载器加载。换个试试

    ClassLoader.getSystemResourceAsStream(
    

    PrintClientListBtnAction.class.getResourceAsStream(
    

    【讨论】:

      猜你喜欢
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多