Mange Posted September 22, 2006 Share Posted September 22, 2006 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 More sharing options...
Teodor Danciu Posted September 22, 2006 Share Posted September 22, 2006 Hi, It would be helpful to see how do you pass the image to the report as parameter.Maybe some intermediate BufferedImage is involved and this is why you get the black background. I hope this helps.Teodor Link to comment Share on other sites More sharing options...
Mange Posted September 22, 2006 Author Share Posted September 22, 2006 Thanks! You are so right. I read the file into an ImageBuffer using the ImageIO.read(). I will do a litle better test with a variety of files and I can post my findings. Link to comment Share on other sites More sharing options...
Mange Posted September 22, 2006 Author Share Posted September 22, 2006 OK, I changed the parameter to a string and I send in the filename instead of the image and now it show just fine :) Thanks again for the pointer! Link to comment Share on other sites More sharing options...
mkharche Posted October 18, 2006 Share Posted October 18, 2006 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 More sharing options...
Teodor Danciu Posted October 30, 2006 Share Posted October 30, 2006 Hi, If it is about a BufferedImage, it means you are manipulating that image yourself and it is probably your code that loses the transparency.Try store your image in an image file and see if it still transparent. I hope this helps.Teodor Link to comment Share on other sites More sharing options...
midrag Posted November 1, 2006 Share Posted November 1, 2006 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 More sharing options...
Teodor Danciu Posted November 1, 2006 Share Posted November 1, 2006 Hi, As I said, try write those bytes into a file on disk and see if that image is really transparent. I hope this helps.Teodor Link to comment Share on other sites More sharing options...
midrag Posted November 2, 2006 Share Posted November 2, 2006 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, midragPost edited by: midrag, at: 2006/11/02 13:45 Link to comment Share on other sites More sharing options...
Teodor Danciu Posted November 16, 2006 Share Posted November 16, 2006 Hi, If the image comes from a POJO as a byte array, do not attempt to load it into a java.awt.Image as you did, but rather wrap that into a ByteArrayInputStream and give it to the <imageExpression> directly. I hope this helps.Teodor Link to comment Share on other sites More sharing options...
midrag Posted November 20, 2006 Share Posted November 20, 2006 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 More sharing options...
time_lord Posted April 6, 2012 Share Posted April 6, 2012 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 moreCaused 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, PhilPost Edited by time_lord at 04/06/2012 01:16 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