Issue in Displaying Image

Hi All,

I need to display Images which comes from database and it's a byte array.

I am using Jasper 6.16.0 .

I initially tried to get the Image as InputStream in Japser.

InputStream logo = new ByteArrayInputStream(imagebytes) - here logo is my input variable for image

SInce I am using  JsonQLDataSource in My Java for JasperFillManager.fillReport as below :     

        InputStream inputStream = new ByteArrayInputStream(mapper.writeValueAsBytes(myJsonDto));
        JsonQLDataSource jsonData = new JsonQLDataSource(inputStream);
        final JasperPrint print = JasperFillManager.fillReport(report, parameters, jsonData);

In Japser I gave

<field name="logo" class="java.io.InputStream"/>

<band height="125" splitType="Stretch">
            <image onErrorType="Blank">
                <reportElement x="74" y="33" width="50" height="50" uuid="e93df5ef-176d-436b-a58f-ddcb0d7f6f3c"/>
                <imageExpression><![CDATA[$F{logo}]]></imageExpression>
            </image>
        </band>

But I am not getting my Image Displayed. When I debugged my code I could see that the image variable 'logo' is going empty in Datasource.

So I need a loution for this issue, when inputstream is going in another inputstream!

Also I tried the solution : https://community.jaspersoft.com/questions/541551/loading-byte-array-database-and-displaying-it-image , there also I didn't get Image displayed.

Could anyone please help on this !!

rinsha.mohammed's picture
Joined: Feb 11 2021 - 10:30pm
Last seen: 1 year 1 month ago

1 Answer:

Finallly I myself found the solution. 

When inputstream is going in another inputstream the inner inputstream is getting empty. SO I changed the datasource to JRBeanCollectionDataSource .

Now it is working fine !

 

rinsha.mohammed's picture
Joined: Feb 11 2021 - 10:30pm
Last seen: 1 year 1 month ago
Feedback