Jump to content
We've recently updated our Privacy Statement, available here ×

printing byte images


divsen

Recommended Posts

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

Link to comment
Share on other sites

  • Replies 9
  • Created
  • Last Reply

Top Posters In This Topic

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

Link to comment
Share on other sites

You can either

  • add
    Code:
    <import value="net.sf.jasperreports.engine.util.JRImageLoader"/> to your report, or

  • Code:
    [code]<imageExpression class="java.awt.Image">
    net.sf.jasperreports.engine.util.JRImageLoader.loadImage(..your image data..)
    </imageExpression>
    [/ul]

 

HTH,

Lucian

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:

net.sf.jasperreports.engine.util.JRImageLoader.loadImage((byte[]) $F{logo})

 

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.

Link to comment
Share on other sites

  • 1 year later...

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.

 

Link to comment
Share on other sites

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!!!!

 

Link to comment
Share on other sites

  • 4 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...