Jump to content
Changes to the Jaspersoft community edition download ×

png-image showed transparent color?


Mange

Recommended Posts

Hi,

 

In my selection screen of data for the report I let the user pick a logo to be included in the report. I picked a png-file (and showed it as an Icon on a label) that has a transparent background. The background came out black on the report. As a test I changed the image-element to use a direct path to the same file, instead of a parameter, and the background was transparent.

 

Anyone had the same experience?

 

A test with a gif-file showed up transparent when I sent it in as a parameter.

 

I also tried to set Transparent on/off but no difference.

Link to comment
Share on other sites

  • Replies 11
  • Created
  • Last Reply

Top Posters In This Topic

  • 4 weeks later...
However, that is not the final solution. I am facing a similar problem in my case, and I cant follow the solution you did, though it works. What could be going wrong in taking the BufferedImage approach ??? !! It seems to be losing the transparency. Any leads will be highly appreciated. Thanks.
Link to comment
Share on other sites

  • 2 weeks later...

Hi,

 

my image comes from an POJO as byte[]. I declared the field as object and casted it to byte[].

Code:
JRImageLoader.loadImage((byte[])$F{logo})

My image displays with a black background. Changing mode to transparent didn't help. Is there a workaround for this problem?

 

regards,

 

midrag

Link to comment
Share on other sites

Hi Teodor,

 

thanks for your answer!

I wrote the images to a file and all have a transparent background.

My images dont come directly from a DB. They come from a Java Bean getter. I used the same getter to save it to a file.

 

Do you have another solution or hint for my problem?

 

best regards,

 

midrag

Post edited by: midrag, at: 2006/11/02 13:45

Link to comment
Share on other sites

  • 2 weeks later...

thx Theodor!,

 

it did work.

 

the image comes as byte[] and is shown correctly with the following code:

 

Code:
<imageExpression class="java.io.InputStream"><![CDATA[new java.io.ByteArrayInputStream ((byte[])$F{logo})]]></imageExpression>

 

regards,

 

midrag

Link to comment
Share on other sites

  • 5 years later...

Hi (sorry I know it can be bad form resurrecting old threads)

Currently using JR 4.1.1.

I was having trouble with a png (with alpha transparency) being displayed with a black background. Converting the image to bytes and then an InputStream fixed it - awesome, thanks!

This works well when I only display the image once, however the report I'm generating is basically a list and the image is a logo which appears on multiple rows; when I use it 2 or more times, JR generates an error.

I am trying to display the print job on screen via the JRViewer swing component, i.e new JRViewer(JasperPrint). It constructs ok but when I call setVisible I get the JR message:

Error displaying report page. See the console for details.

There is no console output or stack trace, etc.

 

I tried a different approach, printing: JasperPrintManager.printReport(JasperPrint, true)

When I run that it throws a stack trace:


net.sf.jasperreports.engine.JRException: Error printing report.

    at net.sf.jasperreports.engine.print.JRPrinterAWT.printPages(JRPrinterAWT.java:197)

    at net.sf.jasperreports.engine.print.JRPrinterAWT.printPages(JRPrinterAWT.java:84)

    at net.sf.jasperreports.engine.JasperPrintManager.printPages(JasperPrintManager.java:197)

    at net.sf.jasperreports.engine.JasperPrintManager.printReport(JasperPrintManager.java:88)

    << ... >>

Caused by: net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.JRException: Image read failed.

    at net.sf.jasperreports.engine.export.draw.PrintDrawVisitor.visit(PrintDrawVisitor.java:126)

    at net.sf.jasperreports.engine.export.draw.PrintDrawVisitor.visit(PrintDrawVisitor.java:55)

    at net.sf.jasperreports.engine.fill.JRTemplatePrintImage.accept(JRTemplatePrintImage.java:381)

    at net.sf.jasperreports.engine.export.draw.FrameDrawer.draw(FrameDrawer.java:231)

    at net.sf.jasperreports.engine.export.draw.FrameDrawer.draw(FrameDrawer.java:179)

    at net.sf.jasperreports.engine.export.JRGraphics2DExporter.exportPage(JRGraphics2DExporter.java:259)

    at net.sf.jasperreports.engine.export.JRGraphics2DExporter.exportReportToGraphics2D(JRGraphics2DExporter.java:232)

    at net.sf.jasperreports.engine.export.JRGraphics2DExporter.exportReport(JRGraphics2DExporter.java:171)

    at net.sf.jasperreports.engine.print.JRPrinterAWT.print(JRPrinterAWT.java:227)

    at sun.print.RasterPrinterJob.printPage(RasterPrinterJob.java:1968)

    at sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1457)

    at sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1273)

    at net.sf.jasperreports.engine.print.JRPrinterAWT.printPages(JRPrinterAWT.java:183)

    ... 55 more

Caused by: net.sf.jasperreports.engine.JRException: Image read failed.

    at net.sf.jasperreports.engine.util.JRJdk14ImageReader.readImage(JRJdk14ImageReader.java:73)

    at net.sf.jasperreports.engine.util.JRImageLoader.loadImage(JRImageLoader.java:126)

    at net.sf.jasperreports.engine.JRImageRenderer.getImage(JRImageRenderer.java:364)

    at net.sf.jasperreports.engine.JRImageRenderer.getDimension(JRImageRenderer.java:400)

    at net.sf.jasperreports.engine.JRImageRenderer.getOnErrorRendererForDimension(JRImageRenderer.java:283)

    at net.sf.jasperreports.engine.export.draw.ImageDrawer.draw(ImageDrawer.java:96)

    at net.sf.jasperreports.engine.export.draw.PrintDrawVisitor.visit(PrintDrawVisitor.java:117)

 

 

Does anyone have any ideas about what could be going wrong?

As I have been typing, a thought occurred to me. If the image InputStream is added to the report more than once, is JR considering multiple occurrances (of the same image stream) to be the same thing? Therefore after rendering the first one, it automatically closes the stream, and the second occurance would encounter the "Image read failed" error? If so what is the best strategy for resolving?

Thanks, Phil



Post Edited by time_lord at 04/06/2012 01:16
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...