Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > transparent images created from java 2D

Reply
Thread Tools

transparent images created from java 2D

 
 
babz
Guest
Posts: n/a
 
      09-13-2005
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

 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      09-13-2005
On 13 Sep 2005 04:15:03 -0700, "babz" <(E-Mail Removed)> wrote or
quoted :

>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.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
 
 
 
babz
Guest
Posts: n/a
 
      09-14-2005
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

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-14-2005
On 13 Sep 2005 21:52:57 -0700, "babz" <(E-Mail Removed)> wrote or
quoted :

>Can anyone help me out???


Did you try the doctoring I suggested?
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
babz
Guest
Posts: n/a
 
      09-20-2005
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

 
Reply With Quote
 
babz
Guest
Posts: n/a
 
      09-21-2005
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

 
Reply With Quote
 
babz
Guest
Posts: n/a
 
      09-22-2005
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

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-23-2005
On 20 Sep 2005 05:35:08 -0700, "babz" <(E-Mail Removed)> wrote or
quoted :

>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
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-23-2005
On 20 Sep 2005 21:58:30 -0700, "babz" <(E-Mail Removed)> wrote or
quoted :

>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.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Resize transparent gif images =?Utf-8?B?TWVrZW4=?= ASP .Net 0 07-20-2005 08:02 AM
Is there problem with Java and transparent images? Ramon F Herrera Java 6 07-02-2005 11:03 AM
Transparent images MW de Jager ASP .Net 3 06-10-2005 11:44 AM
transparent images anonymous@coolgroups.com Java 3 06-10-2004 04:24 AM
problem system.drawing transparent web images eruess ASP .Net 0 08-08-2003 05:58 PM



Advertisments