andre2k2 Posted June 28, 2007 Share Posted June 28, 2007 Im with problems passing an image (java.awt.Image)in my JRXML the code is:Code: <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> </image> then in java i do: Code:[code]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 More sharing options...
mshoe Posted June 29, 2007 Share Posted June 29, 2007 You need to make sure your report contains a parameter named "Logomarca". Link to comment Share on other sites More sharing options...
Case1182 Posted June 29, 2007 Share Posted June 29, 2007 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 More sharing options...
l.pedrazzi Posted September 4, 2007 Share Posted September 4, 2007 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: Code:$P{REPORT_PARAMETERS_MAP}.get("IMAGE0"«») Before of filling my report I've put the image (a ByteArrayInputstream) in the map: Code:[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, Lisa Link to comment Share on other sites More sharing options...
Case1182 Posted September 4, 2007 Share Posted September 4, 2007 is it a single image or a database of different images??? what type of field are you trying to display it in??? if you post your .jrxml file it would be easy to see ur problem. :) Link to comment Share on other sites More sharing options...
l.pedrazzi Posted September 5, 2007 Share Posted September 5, 2007 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. Lisa 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 More sharing options...
Case1182 Posted September 5, 2007 Share Posted September 5, 2007 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:Code:$P{SUBREPORT_DIR} + "IMAGE0.jpg" and image expression class to: Code:[code]java.lang.String 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 More sharing options...
l.pedrazzi Posted September 5, 2007 Share Posted September 5, 2007 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 More sharing options...
dpinfo Posted September 5, 2007 Share Posted September 5, 2007 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 : http://www.jasperforge.org/index.php?option=com_joomlaboard&Itemid=&func=view&catid=9&id=14215#14215 I hope that this help. Bye dpinfo Link to comment Share on other sites More sharing options...
Case1182 Posted September 5, 2007 Share Posted September 5, 2007 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 More sharing options...
dpinfo Posted September 5, 2007 Share Posted September 5, 2007 I have tried your way but I can't reach the result.So I have tried the road of the posthttp://www.jasperforge.org/index.php?option=com_joomlaboard&Itemid=&func=view&catid=9&id=14215#14215but I haven't reach the point too.So, now I post a little access db with the report on it. I have tried also in oracle db , but it doesn't work.Please help me Dpinfo Link to comment Share on other sites More sharing options...
dpinfo Posted September 5, 2007 Share Posted September 5, 2007 I have tried your way but I can't reach the result.So I have tried the road of the posthttp://www.jasperforge.org/index.php?option=com_joomlaboard&Itemid=&func=view&catid=9&id=14215#14215but I haven't reach the point too.So, now I post a little access db with the report on it. I have tried also in oracle db , but it doesn't work.Please help meDpinfo Link to comment Share on other sites More sharing options...
dpinfo Posted September 5, 2007 Share Posted September 5, 2007 I hope that now the file will be uploaded.Dpinfo [file name=IMMAGINE_PROVA.gz size=142310]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/IMMAGINE_PROVA.gz[/file] Link to comment Share on other sites More sharing options...
ngonidan2 Posted June 15, 2013 Share Posted June 15, 2013 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 yourparameter 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;try { 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, parameters, ds); JasperExportManager.exportReportToPdfFile(jasperPrint, reportsdirectoryfile + "\VisitsReport.pdf"); try { File f = new File(reportsdirectoryfile + "\VisitsReport.pdf"); Desktop dt = Desktop.getDesktop(); dt.open(f); } catch (Exception he) { he.printStackTrace(); } Hope it helpsNgoni 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