If you want to insert images from the file system (e.g. C:\images folder) into jasper reports at runtime, for example changing a logo depending on user selection or simply allowing the user to browse for his or her image to be displayed in the report then here is a simple process of doing that.

Let start with the report design using ireport. In this instance the picture will be passed to the report as a parameter.

So let’s create a parameter in our report and call it “photo”

As shown in the picture above, the data type of our parameter should be “java.lang.Object”

After this, drag the image , from the tool bar, on to your report.Right click on the image and choose “Properties” from the menu

Under the image tab of the dialog box, make sure you select “java.awt.image” for the Image Expression Class. Once this is done, you are done with the report design

Lets go to netbeans , do some coding and connect our designed report to a java application.

First we need to declare a variable of type image,

Image photo;

Also we create a method , which on click of a button, loads a picture from the file system and initializes the “photo: variable.

Hi Mister Gilbert
I worked with your exercise LOAD IMAGES DYNAMICALLY INTO JASPER REPORTS, very good.
But I have the follow error:
reportErrorjava.lang.IllegalArgumentException: Width (-1) and height (-1) cannot be <= 0
I hope you can give me a hand.
Thanks

Hi Mister Gilbert
Thank you ver much, definitly you are the men!!.
The problem are the .jar files.
I was working with the jar file itext 1.0.3, so I download a recent version of itext jar file (itext 2.0.3).
Now I can view the report, the image and I can save the document.

Hi Mister Gilbert
I hope you are ok!.
I’m doing a desktop application that generate a report file (.pdf) , I’m using Netbeans IDE 6.8.
I can run the application and I can view and save the report (inside the IDE).
When I want to make the executable(I want to run the application outside The IDE) of the aplication and test it (double click to.jar file) the aplication runs ok, but the report doesn’t appear (I can’t view and save it).
I hope you can help me like in other ocassions.
Thank a lot for your important help.
MAURICIO

Hi Mister Gilbert,
Thank you very much, your article is nice.
I have some problem, i want to make “Id card” application.
In detail jasper report, i want to show image one by one depend on id_member in mysql.

can u help me?

illustration :

id_member name_member
1 Gilbert
2 Aliong
3 Jonathan

I want to design in my report like this :

ID : 1 [PHOTO HERE C:\image\1.jpg]
NAME : GILBERT [ ]

ID : 2 [PHOTO HERE C:\image\2.jpg]
NAME : ALIONG [ ]

ID : 3 [PHOTO HERE C:\image\3.jpg]
NAME : JONATHAN [ ]

Photo is taken from image in folder consist of the photos.
Example photo of id_member : 1 will be taken from C:\image\1.jpg, etc.. => C:\image\[id_member].jpg

Error:
net.sf.jasperreports.engine.JRException: Byte data not found at location : java.io.ByteArrayInputStream@1a7ffb3
at net.sf.jasperreports.engine.util.JRLoader.loadBytesFromLocation(JRLoader.java:467)
at net.sf.jasperreports.engine.JRImageRenderer.getInstance(JRImageRenderer.java:175)
at net.sf.jasperreports.engine.fill.JRFillImage.evaluateImage(JRFillImage.java:921)
at net.sf.jasperreports.engine.fill.JRFillImage.evaluate(JRFillImage.java:870)
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:891)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:795)
at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:63)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:402)
at dho.management.system.StudentRegistration.btn_viewActionPerformed(StudentRegistration.java:2047)
at dho.management.system.StudentRegistration.access$7900(StudentRegistration.java:49)
at dho.management.system.StudentRegistration$80.actionPerformed(StudentRegistration.java:1892)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6267)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6032)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)