PixM Posted August 19, 2008 Share Posted August 19, 2008 Hi, We are working with complex jasperreports using xml as a datasource and we are including images. Currently we are using a parameter map for inserting the images, but we wish to use base64 images from the xml datasource. Is there any chance that this functionality will be supported by jasper/ireport in the future?Or is there a way to construct some sort of scriptlet so that the image field can be set to retrieve the xml data and convert it into an image object? Tnx & Regards,pixm Link to comment Share on other sites More sharing options...
PixM Posted August 27, 2008 Author Share Posted August 27, 2008 T MWrote: Hi, We are working with complex jasperreports using xml as a datasource and we are including images. Currently we are using a parameter map for inserting the images, but we wish to use base64 images from the xml datasource. Is there any chance that this functionality will be supported by jasper/ireport in the future? Or is there a way to construct some sort of scriptlet so that the image field can be set to retrieve the xml data and convert it into an image object? Tnx & Regards, pixm Well, Found a solution to this:Insert the following import directive in the report you want to use the images in:- org.apache.commons.codec.binary.Base64Next declare a variable (to be fancy) new ByteArrayInputStream(new Base64().decodeBase64($F{image}.getBytes("UTF-8"))) This puts the string in a byte array, decodes it from base64 and puts it in an inputstream.Where the $F{image} represents the value of the image tag in a base64 string.Now use this variable in a picture object a inputstream and voila, image appear in your report. Regards,pixm Link to comment Share on other sites More sharing options...
shrije Posted March 4, 2009 Share Posted March 4, 2009 This works in all the report bands but not on the title band. I need on the title band too. Link to comment Share on other sites More sharing options...
dsg Posted December 10, 2010 Share Posted December 10, 2010 if you change the EcaluationTime of the image, it works in title toJRDesignImage img = getMyImg();img.setEvaluationTime(EvaluationTimeEnum.REPORT); Link to comment Share on other sites More sharing options...
bschipper Posted December 11, 2012 Share Posted December 11, 2012 In regards to this;I've been having trouble with adding multiple images encoded as base64, and have managed to work out that all image data must be loaded first before any reading is done, otherwise ireport simply shows a blank image. I've acheived this by ordering the jrxml to have all base64 data before any variable operations to load the data from it.It seems quite straightforward now i think of it, but it may help someone hopefully. Link to comment Share on other sites More sharing options...
ozmarbs Posted July 25, 2014 Share Posted July 25, 2014 For a purely static image (repeated throughout the report on say the title and page headers)I declared a variable of type String and set it to the Base64 encoded image data.I added the commons-codec-1.9.jar to the project's build path as an external jar.Then for the image Expression - I set it to new ByteArrayInputStream(new org.apache.commons.codec.binary.Base64().decodeBase64($V{ImageVariable}.getBytes("UTF-8")))Note that I had to fully qualify the apache commons Base64 class.I set the evaluation time to 'Report' and 'Using Cache' to true. Link to comment Share on other sites More sharing options...
harshalsonar777 Posted July 20, 2020 Share Posted July 20, 2020 If you want decode image from string.First you should drag "Image" from Palette, then go to the properties of Image paste this expression (new java.io.ByteArrayInputStream(org.apache.commons.codec.binary.Base64.decodeBase64($F{String}.getBytes()))) in the Image expression editor.Note: In my case Field name is "$F{String}". Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now