printing byte images

Hi

I have many images stored in my database as BLOB.when i get the data they are as bytes. so i have field image which of type byte. how do i print the image on the report. how do i convert it into inputstream or any other format. Is there any way to do it in ireport or can it be done only in code like this:

InputStream in = new ByteArrayInputStream(byte[]);

Thanks
divsen's picture
856
Joined: Aug 22 2006 - 6:02am
Last seen: 17 years 1 month ago

9 Answers:

You can do something like
Code:
<br />
<imageExpression class="java.awt.Image"><br />
  JRImageLoader.loadImage(..your image data..)<br />
</imageExpression><br />
</td></tr></tbody></table><br />
<br />
HTH,<br />
Lucian
lucianc's picture
87341
Joined: Jul 17 2006 - 1:10am
Last seen: 7 hours 3 min ago
I tried that it says


12:36:31,562 INFO [STDOUT] Caused by: net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. JRImageLoader cannot be resolved
value = (java.awt.Image)(JRImageLoader.loadImage(((java.lang.Byte)field_companyLargeLogo.getValue())));
<----------->

Can u plz help me
divsen's picture
856
Joined: Aug 22 2006 - 6:02am
Last seen: 17 years 1 month ago
You can either
  • add
    Code:
    <import value="net.sf.jasperreports.engine.util.JRImageLoader"/></td></tr></tbody></table> to your report, or<br />
    </li><li><br />
    <table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"><tbody><tr><td><b>Code:</b></td></tr><tr><td><pre><imageExpression class="java.awt.Image"><br />
      net.sf.jasperreports.engine.util.JRImageLoader.loadImage(..your image data..)<br />
    </imageExpression></td></tr></tbody></table></li>[/ul]<br />
    <br />
    HTH,<br />
    Lucian
lucianc's picture
87341
Joined: Jul 17 2006 - 1:10am
Last seen: 7 hours 3 min ago
Thanks for your help.

now my problem is

08:36:03,015 INFO [STDOUT] Caused by: net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. The method loadImage(byte[]) in the type JRImageLoader is not applicable for the arguments (Byte)
value = (java.awt.Image)(net.sf.jasperreports.engine.util.JRImageLoader.loadImage(((java.lang.Byte)field_company__companyLargeLogo.getValue())));
<------->


Bcoz the data type i gave for the field is java.lang.Byte

so i tried byteValue() but that also did not help

08:40:22,827 INFO [STDOUT] Caused by: net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. The method loadImage(byte[]) in the type JRImageLoader is not applicable for the arguments (byte)
value = (java.awt.Image)(net.sf.jasperreports.engine.util.JRImageLoader.loadImage(((java.lang.Byte)field_company__companyLargeLogo.getValue()).byteValue()));
<------->


What field type should i give to keep the value as byte[] array.
divsen's picture
856
Joined: Aug 22 2006 - 6:02am
Last seen: 17 years 1 month ago
If your field will have a byte[] as value, you need to declare the field as java.lang.Object and then cast it in your image expression
Code:
<br />
net.sf.jasperreports.engine.util.JRImageLoader.loadImage((byte[]) $F{logo})<br />
</td></tr></tbody></table><br />
<br />
If you have an SQL query in the report to retrieve the data (and you have a fairly recent JR version), you can also try to declare your field as java.awt.Image and directly use it in the image expression.
lucianc's picture
87341
Joined: Jul 17 2006 - 1:10am
Last seen: 7 hours 3 min ago
Thank you very much.

It worked..
divsen's picture
856
Joined: Aug 22 2006 - 6:02am
Last seen: 17 years 1 month ago

Hi,

I am newbie to using iReports tool.

i have to display a BLOB field from my ORACLE Database on a report.

I have declared the field as java.lang.Object Type

and i have an image field : with this expression:net.sf.jasperreports.engine.util.JRImageLoader.loadImage((byte[])$F{LOT_LETTERCONDITION_DTL_CONDIT})

where LOT_LETTERCONDITION_DTL_CONDIT is my BLOB field

and the expression tyep is: java.awt.Image

The report compiles fine - but throws a run-time error giving a CLASSCASTEXCEPTION

the exact error being --> Caused by: java.lang.ClassCastException: oracle.sql.BLOB cannot be cast to [B 

 

Kindly help me in solving this issue.

Thanks in advance!

Shesh.

 

sheshkrish's picture
Joined: Sep 1 2008 - 10:42pm
Last seen: 15 years 1 month ago

The entire log trace is:

Error filling print... Error evaluating expression : 
    Source text : net.sf.jasperreports.engine.util.JRImageLoader.loadImage((byte[])$F{LOT_LETTERCONDITION_DTL_CONDIT})
net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : 
    Source text : net.sf.jasperreports.engine.util.JRImageLoader.loadImage((byte[])$F{LOT_LETTERCONDITION_DTL_CONDIT}) 
    at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:197) 
    at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:537) 
    at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:505) 
    at net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:826) 
    at net.sf.jasperreports.engine.fill.JRFillImage.evaluateImage(JRFillImage.java:890) 
    at net.sf.jasperreports.engine.fill.JRFillImage.evaluate(JRFillImage.java:871) 
    at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:275) 
    at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:426) 
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:1380) 
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:692) 
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:255) 
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:113) 
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:879) 
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:782) 
    at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:63) 
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:402) 
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:234) 
    at it.businesslogic.ireport.IReportCompiler.run(IReportCompiler.java:947) 
    at java.lang.Thread.run(Unknown Source) 
Caused by: java.lang.ClassCastException: oracle.sql.BLOB cannot be cast to [B 
    at BLOB_Test_1220334861077_635142.evaluate(BLOB_Test_1220334861077_635142:164) 
    at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:186) 
    ... 18 more 
Print was not filled. Try using an EmptyDataSource...

 

KINDLY HELP ME - IN SOLVING THIS PROBLEM!!!!

 

sheshkrish's picture
Joined: Sep 1 2008 - 10:42pm
Last seen: 15 years 1 month ago

Hi sheshkrish,hav u found the solution of ur prob??

i do hv the same prob too..

plz tell me the solution of this if u hv.

 

Thanks in advance

 

 



Post Edited by Deepa Jain at 01/24/09 17:12



Post Edited by Deepa Jain at 01/24/09 17:13
deepajain's picture
Joined: Jan 21 2009 - 7:50pm
Last seen: 14 years 8 months ago
Feedback
randomness