Jump to content

Passing an image by parameter...


Recommended Posts

Im with problems passing an image (java.awt.Image)

in my JRXML the code is:


<image hAlign="Center" scaleImage="RetainShape" vAlign="Middle">
<reportElement height="80" width="149" x="10" y="0"/>
<graphicElement stretchType="RelativeToTallestObject"/>
<imageExpression class="java.awt.Image"><![CDATA[$P{Logomarca}]]></imageExpression>


then in java i do:


Map<String, Object> parametros = new HashMap<String, Object>();
parametros.put("Logomarca", logomarca);


but this error message is show:

Report design not valid :

1. Parameter not found : Logomarca



Post edited by: andre2k2, at: 2007/06/28 13:45

Link to comment
Share on other sites

  • Replies 13
  • Created
  • Last Reply

Top Posters In This Topic

that is cause it is not an parameter, it is an element, do this, leave everything the way it is but add this, first make a parameter called, Logomarca and check the prompt for string box, to make parameter right click on parameters >> add >> parameter
Link to comment
Share on other sites

  • 2 months later...

I'm sorry,

but I've a very similar problem and I don't understand the solution. :pinch:


I'm trying to import in a Java program a report create with ireport, and this report has subreports and one image.


With subreports it's all fine, but the image (in the master report) doesn't want to appear.


In my JRDesignExpression I've put this:



Before of filling my report I've put the image (a ByteArrayInputstream) in the map:


[code]mapParameters.put("IMAGE0", image);


It's the same procedure I've used for subreports, but for the subreports it'ok. :S


Thanks in advance,


Link to comment
Share on other sites

The image is one, a logo near the title. I need to store it in the db (in which I store also the reports) as bytea and extract them when I need.


No problem with subreports, only with the image.


I've attached my jrxml as required.

Thank a lot again.




Ps. Don't know if it can be relevant but: when I get the object from the db I get the report as JasperReport and the image as ByteArrayInputStream. [file name=report.jrxml size=9457]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/report.jrxml[/file]

Link to comment
Share on other sites

you need to put the image in the same directory as the subreport .jasper files NOT in a database, if the image doesnt change just keep it in the subreport directory, then change image expression to:
$P{SUBREPORT_DIR} + "IMAGE0.jpg" and image expression class to: 
that should do it, remember to put it in same folder as .jasper files NOT database or .jrxml files.
Link to comment
Share on other sites

Unfortunately, my reports and subreports are in the db and I fill them after extracting from their table. They give no problem to me.

As I said, the image is one and doesn't change.

Surely your solution will work, but don't fit to me, because I can't/wan't use the filesystem.


Forgive me, but I don't understand why I can't store also the image in the db. It's impossible to load the image, or simply your method is more easy?


Thank you again, Lisa.

Link to comment
Share on other sites

I have never used this method, because my images are normally files, but you could take images from the db.


If you want to catch more information you could search about java.io.InputStream


I hope that this post will guide you :




I hope that this help.





Link to comment
Share on other sites

you can use the picture from the database, less efficent since there is only one picture, but here is the way, your picture will actually be stored as a string in your database, so change "IMAGE0.jpg" to $F{PicField}, in the very off chance it is actually storing the whole picture in the database, Image Expression = $F{PicField} and Image Expression Class = java.awt.image
Link to comment
Share on other sites

  • 5 years later...

To pass an Image as parameter to a jasper report this is how i did it. I'm using ireports to design the jasper report.

First open your jasper report in ireports, then under ireport Report Insepector which is usually on the left, right click Parameters and select Add Parameter. 

Select the added parameter then go to the properties panel on the right, and change it's name to what you want it to be e.g. Logo1,

then set it's Parameter class to Object. Next add the image control from the Palette to where you want it to be e..g. page Header, resize as needed,

then select the image control, go to the properties selection, scroll to Image Properties, and under Image Expression put $P{Logo1} which points to your

parameter created above. Then select java.awt.Image under Expression Class. Save you are ready to code


In code run query to get object containing the byte [], The image field in the database table can be of data type blob, medium blob or long blob.

Or it can be a string column, and you save image as a Base64 encoded image which you then decode to get the byte[] back. Note that the image that will be sent to the report will be a type of java.awt.image, nd we take advantage of the ImageIcon object in java to give us the image using ImageIconObj.getImage(). see code snippet below. more info is at http://gilbertadjin.wordpress.com/tag/passing-parameter-to-ireport/


Facility facilityObj = (Facility)query.list().get(0);

ImageIcon ImageIconObj = null;
   ImageIconObj = new javax.swing.ImageIcon(facilityObj.getSitelogo());
 catch(Exception e)


    Map parameters = new HashMap();
    parameters.put("Logo1", ImageIconObj == null?null:ImageIconObj.getImage());

    InputStream reportStream = new FileInputStream("reports/Report.jrxml");
    JasperDesign jasperDesign = JRXmlLoader.load(reportStream);
    JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);

    JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(results);
    JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,

    JasperExportManager.exportReportToPdfFile(jasperPrint, reportsdirectoryfile + "\VisitsReport.pdf");

     try {
    File f = new File(reportsdirectoryfile + "\VisitsReport.pdf");
    Desktop dt = Desktop.getDesktop();
      } catch (Exception he) {


Hope it helps





Link to comment
Share on other sites

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