Jump to content
Changes to the Jaspersoft community edition download ×

using transparent gif images


Recommended Posts

By: Oleg Pavliv - oleg_pavliv

using transparent gif images

2003-06-16 05:43

Hello Teodor,

 

I have the following problem when using gif images dynamically (as Field): transparent part of image is black.

 

After analyzing the problem I saw that JRImageLoader paints the image to the BufferedImage and encodes it to the byte array using jpeg encoder. By such way we are losing the transparency.

 

Currently I found the following workaround:

 

public class JRImageLoader {

 

private static HashMap idxToImage = new HashMap();

private static HashMap imageToIdx = new HashMap();

private static int lastIdx = 0;

 

 

 

public static byte[] loadImageDataFromAWTImage(Image img) throws JRException

{

Integer idx = (Integer)imageToIdx.get(img);

if(idx == null) {

idx = new Integer(lastIdx);

imageToIdx.put(img, idx);

idxToImage.put(idx, img);

++lastIdx;

}

int i = idx.intValue();

byte result[] = new byte[4];

result[0] = (byte)(i & 0x000f); i >>= 4;

result[1] = (byte)(i & 0x000f); i >>= 4;

result[2] = (byte)(i & 0x000f); i >>= 4;

result[3] = (byte)(i & 0x000f);

return result;

}

 

 

public static Image loadImage(byte[] bytes)

{

Image image;

if(bytes.length == 4) {

int i = 0;

i += bytes[3]; i <<= 4;

i += bytes[2]; i <<= 4;

i += bytes[1]; i <<= 4;

i += bytes[0];

 

image = (Image)idxToImage.get(new Integer(i));

} else {

image = Toolkit.getDefaultToolkit().createImage( bytes );

}

 

MediaTracker traker = new MediaTracker(new Panel());

traker.addImage(image, 0);

try

{

traker.waitForID(0);

}

catch (Exception e)

{

e.printStackTrace();

image = null;

}

 

return image;

}

 

 

}

 

 

My solution is not the best, but the quickest to implement. Please write me if you plan to corrent this problem in the future.

 

Best regards.

 

Oleg Pavliv

Software Architect.

Lysis SA

opavliv@lysis.com

 

 

 

 

 

 

 

 

 

 

By: Eric Everman - eeverman

RE: using transparent gif images

2003-06-16 08:37

Hey this is a great addition - I was just wondering if gifs with transparencies would work on my current project.

 

Teodor - could this be added as a standard feature of JasperReports?

 

Thanks,

 

Eric Everman

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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