[#5031] - The transparency and the alpha aren't correctly detected during the creation of a renderable from an image

Category:
Bug report
Priority:
Normal
Status:
Feedback Requested
Project: Severity:
Minor
Resolution:
Open
Component: Reproducibility:
Always
Assigned to:

My report files (jrxml) use the tag "imageExpression", I pass java.awt.Image instances into it, they have an alpha channel and some transparency.

Expected result:
When I generate my reports (PDF), the background color is the one set in Jasper Studio.

Current result:
When I generate my reports (PDF), I always obtain a black background.

Workaround:
Pass an instance of net.sf.jasperreports.engine.Renderable with the image type ImageTypeEnum.PNG when the alpha and the transparency are properly detected instead of an instance of java.awt.Image. It requires to modify each report.

Root cause:
The alpha and the transparency are correctly handled only in a very particular case when the passed java.awt.Image is an instance of java.awt.image.RenderedImage:
http://sourceforge.net/p/jasperreports/code/ci/master/tree/jasperreports...
http://sourceforge.net/p/jasperreports/code/ci/master/tree/jasperreports...

However, there are some other trivial cases not handled by the code above as you can see in this example:
http://exampledepot.8waytrips.com/egs/java.awt.image/GetColorModel.html

A (debatable) addition consists in using a class of the internal Java API to avoid using a pixel grabber when the image comes from the AWT toolkit:
if (image instanceof sun.awt.image.ToolkitImage) {
sun.awt.image.ToolkitImage tkImage = (sun.awt.image.ToolkitImage) image;
return tkImage.getColorModel();
}

Possible patch:
Use the method getColorModel() above instead of handling only java.awt.image.RenderedImage.

I can provide a clean patch if you want. Best regards.

v6.1
gouessej's picture
Joined: Jul 2 2015 - 2:26am
Last seen: 3 years 8 months ago

5 Comments:

#1
  • Status:New» Feedback Requested
  • Assigned:nobody» teodord

Hi,

A patch would be great!

Thanks,
Teodor

#2

Thank you Teodor. I'll post a patch next week.

#3
AttachmentSize
File bug5031_jasperreportslibrary.patch4.99 KB
#4

Please find my first patch above (see bug5031_jasperreportslibrary.patch).

#5

I provided a patch more than two years ago and I'm still waiting for a feedback about it. Is there anything wrong?

Feedback
randomness