Jump to content
We've recently updated our Privacy Statement, available here ×

Image not transparent in generated pdf


neian

Recommended Posts

Hello,

I have a problem in the image embedded in the pdf file that jasper report generated. The image was not transparent and has a dark grey color.

This occurred when I used PJA toolkit to be able to run the JasperFillManager.fillReport(xx) in our unix server.

I am using the code below to get the image.

Image logo = new ImageIcon(imageURL).getImage();

 

In the jrxml, the image is declared as an Image object.

<image scaleImage="RetainShape" isLazy="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >

<reportElement mode="Transparent" x="191" y="30" width="167" height="62" key="image-1"/>

<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/> <graphicElement stretchType="NoStretch" pen="None"/> <imageExpression class="java.awt.Image"><![CDATA[$P{Logo}]]></imageExpression>

</image>

Maybe somebody has also encountered this and can share their insights on what could be the cause of the image problem and how to solve it?

Thanks.

Link to comment
Share on other sites

  • 2 weeks later...
  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Hello,

Thank you for the suggestion but I cannot set the java.awt.headless = true since I am using jdk 1.3.

However I was able to find a solution for my problem. I just need to put my Image in a BufferedImage and use the Graphics2D to draw the Image.

In order to use jasper reports in the Unix environment, we used PJA toolkit and just set the server properties as per PJA documentation.

Below is the code I used to generate the Image.

 

public static Image getLogo() {

 

URL imageURL = Thread.currentThread().getContextClassLoader().getResource("images/WMS_K_2.jpg");

ImageIcon icon = new ImageIcon(imageURL);

BufferedImage logo = new BufferedImage(icon.getIconWidth(),icon.getIconHeight(),BufferedImage.TYPE_INT_RGB);

Graphics2D graphics = logo.createGraphics();

graphics.drawImage(icon.getImage(),0,0,icon.getImageObserver());

 

return logo;

}

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...