transparent images created from java 2D

B

babz

AoA all,



I am trying to create transparent png images. I create them using the
following code :

GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();

GraphicsDevice gs = ge.getDefaultScreenDevice();

GraphicsConfiguration gc =
gs.getDefaultConfiguration();



// Create an image that supports transparent pixels

BufferedImage bufImg = gc.createCompatibleImage(width,
height, Transparency.BITMASK);



Graphics2D g = (Graphics2D)bufImg.getGraphics();

g.setBackground(new Color(0,0,0,0));

g.clearRect(0,0,width,height);



//then some code for drawing lines.. etc



When I open the image in Internet explorer, it gives me a translucent
image with light greenish background. opening in Paint gives me a
complete black background.

Can someone help me out with it? I want a completely transparent image.

Thnks
Babz
 
R

Roedy Green

When I open the image in Internet explorer, it gives me a translucent
image with light greenish background. opening in Paint gives me a
complete black background.

this is a bug in Internet explorer. It can't handle transparent PNGs.
Try other browsers. They will display them fine. If you want to
display them in IE, "doctor" them as described in
http://mindprod.com/applets/masker.html

That however destroys some of their transparency info.
 
B

babz

When i open that image in MS Paint, it gives a completely black
background. I have tried some png's that are not created using Java2D
they work fine. My aim is not to display those images in Internet
Explorer but to programmatically render them in pdf. The pdf output is
black (same as MS Paint output) but some other transparent pngs are
added normally without any difficulty.

Thanks for your help anyway:)

Can anyone help me out???

Thnks
Babz
 
B

babz

Well the doctoring is of no use to me.. because i will programmatically
use those images to render them in pdf. Can you suggest some PNG Writer
that will do it for me?? Other file formats can also be used like gifs,
jpgs, etc.. Any thing would work provided they are transparent.. :)

Thanks

Babz
 
B

babz

i tried the doctoring too.. but it makes it a white background and so
anything that is under it would not be visible.. that doesnot serve the
purpose of transparency..

Thanks

Babz
 
B

babz

AoA every one..

I have identified this problem. An image created in Palette Mode will
give correct results in Internet Explorer for Transparent PNGs. So try
to create images with the Pallete mode.

Thanks

Babz
 
R

Roedy Green

Well the doctoring is of no use to me.. because i will programmatically
use those images to render them in pdf. Can you suggest some PNG Writer
that will do it for me?? Other file formats can also be used like gifs,
jpgs, etc.. Any thing would work provided they are transparent.. :)

Gifs have transparency but not variable transparency. However, Java
has no built in gig encoder to write them out. See
http://mindprod.com/jgloss/gifencoder.html for your other options.

JAI has more options that you can shake a stick at. Perhaps you could
hit a magic combo.

see http://mindprod.com/jgloss/jai.html
 
R

Roedy Green

i tried the doctoring too.. but it makes it a white background and so
anything that is under it would not be visible.. that doesnot serve the
purpose of transparency..

you have to set the transparency.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,145
Latest member
web3PRAgeency
Top