tstuser Posted October 22, 2018 Share Posted October 22, 2018 How to add dynamic image in jasper report using jasper studioDatabase is postgresqlimage is stored in bytea formathow to display that image in jasper report.i used the following query to retrieve image from db in text formatselect encode(image,'escape') as img,idfrom entity_image where id = 100jasper source code is<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.5.1.final using JasperReports Library version 6.5.1 --><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="image" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c591470d-2796-470b-a5ab-01b50ddf30b9"> <property name="com.jaspersoft.studio.data.sql.tables" value=""/> <property name="com.jaspersoft.studio.data.defaultdataadapter" value="TST"/> <queryString language="SQL"> <![CDATA[select encode(image,'escape') as image from entity_image where id = 100]]> </queryString> <field name="image" class="java.lang.String"> <property name="com.jaspersoft.studio.field.label" value="image"/> </field> <background> <band splitType="Stretch"/> </background> <title> <band height="79" splitType="Stretch"/> </title> <detail> <band height="125" splitType="Stretch"> <image isUsingCache="true"> <reportElement x="240" y="21" width="71" height="51" uuid="65f086cd-ae8e-46c5-ba66-85f3a9b0bc28"/> <imageExpression><![CDATA[new java.io.ByteArrayInputStream(org.apache.commons.codec.binary.Base64.decodeBase64($F{image}.getBytes())) ]]></imageExpression> </image> </band> </detail></jasperReport>it shows net.sf.jasperreports.engine.jrexception: Image read failed .How to solve this?? is there any other method? Link to comment Share on other sites More sharing options...
Solution tstuser Posted October 22, 2018 Author Solution Share Posted October 22, 2018 No need to encode/decode the bytea data. Just do select image as img ..., set the field type to java.awt.Image and use $F{image} as image expression. 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