Unable to display byte[] image on Report - Database Postgresql

0

Hi Community, 
Please help on how to display byte[] data as an image on Japser report.

 1) SQL query : select  * from chart_images where id = 1

2) Filed Name that needs to be displayed as an image  : $F{content}

3) Field data type is : byte[] in jasper reports. 

4) Field type in PostgreSQL is : bytea 

5) Field data looks like 

      ÀÂPNG        IHDR    À          À À J    sRGB  À À  À   xeXIfMM...................................ÀÂP( c À À  À ÀÂ` ÀÂk§À     IEND ÀÂB` ÀÂ

6) Report Design : 

        Taken summary band, Dragged an empty image and put $F{content} feld in the image expression.

Below is the error log. 

Studio Error Log: 

net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.JRException: Image read failed.
    at net.sf.jasperreports.engine.export.HtmlExporter$CellElementVisitor.visit(HtmlExporter.java:3123)
    at net.sf.jasperreports.engine.export.HtmlExporter$CellElementVisitor.visit(HtmlExporter.java:3095)
    at net.sf.jasperreports.engine.fill.JRTemplatePrintImage.accept(JRTemplatePrintImage.java:417)
    at net.sf.jasperreports.engine.export.HtmlExporter$TableVisitor.visit(HtmlExporter.java:3066)
    at net.sf.jasperreports.engine.export.HtmlExporter$TableVisitor.visit(HtmlExporter.java:3050)
    at net.sf.jasperreports.engine.export.tabulator.ElementCell.accept(ElementCell.java:56)
    at net.sf.jasperreports.engine.export.HtmlExporter.exportTable(HtmlExporter.java:590)
    at net.sf.jasperreports.engine.export.HtmlExporter.exportPage(HtmlExporter.java:490)
    at net.sf.jasperreports.engine.export.HtmlExporter.exportReportToWriter(HtmlExporter.java:391)
    at net.sf.jasperreports.engine.export.HtmlExporter.exportReport(HtmlExporter.java:248)
    at com.jaspersoft.studio.editor.preview.actions.export.AExportAction.exportWithProgress(AExportAction.java:223)
    at com.jaspersoft.studio.editor.preview.actions.export.AExportAction.doPreview(AExportAction.java:347)
    at com.jaspersoft.studio.editor.preview.actions.export.AExportAction$3.run(AExportAction.java:191)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: net.sf.jasperreports.engine.JRException: Image read failed.
    at net.sf.jasperreports.engine.util.JRJdk14ImageReader.readImage(JRJdk14ImageReader.java:70)
    at net.sf.jasperreports.engine.util.JRImageLoader.loadAwtImageFromBytes(JRImageLoader.java:164)
    at net.sf.jasperreports.renderers.WrappingImageDataToGraphics2DRenderer.getImage(WrappingImageDataToGraphics2DRenderer.java:76)
    at net.sf.jasperreports.renderers.WrappingImageDataToGraphics2DRenderer.getDimension(WrappingImageDataToGraphics2DRenderer.java:86)
    at net.sf.jasperreports.engine.export.HtmlExporter$InternalImageProcessor.process(HtmlExporter.java:1400)
    at net.sf.jasperreports.engine.export.HtmlExporter.writeImage(HtmlExporter.java:1021)
    at net.sf.jasperreports.engine.export.HtmlExporter$CellElementVisitor.visit(HtmlExporter.java:3115)
    ... 13 more
 

  Have been trying with below data types and expressions but unable get the image displayed and none worked so far. Please help in providing some inputs. 
 java.io.InputStream
 java.awt.Image
 java.lang.Object
 java.sql.Blob

(java.sql.Blob)$F{content}.getBinaryStream()
new java.io.ByteArrayInputStream(javax.xml.DatatypeConverter.parseBase64Binary($F{content}))

new java.io.ByteArrayInputStream(org.apache.commons.codec.binary.Base64.decodeBase64($F{content}.getBytes()))
new java.io.StringBufferInputStream(new org.w3c.tools.codec.Base64Decoder($F{content}).processString())
new java.io.ByteArrayInputStream(Base64.getDecoder().decode($F{content}))

Thank you in Advance. 

Sadakar Pochampalli 

sadakar's picture
727
Joined: Aug 14 2012 - 3:57am
Last seen: 2 months 1 week ago

1 Answer:

0
anibal.duardo's picture
Joined: Mar 27 2013 - 9:21am
Last seen: 1 month 1 week ago
Feedback
randomness