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
9 Answers:
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
- 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
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.
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. |
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.
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!!!!