transparent images created from java 2D

Discussion in 'Java' started by babz, Sep 13, 2005.

  1. babz

    babz Guest

    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
    babz, Sep 13, 2005
    #1
    1. Advertising

  2. babz

    Roedy Green Guest

    On 13 Sep 2005 04:15:03 -0700, "babz" <> 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.
    Roedy Green, Sep 13, 2005
    #2
    1. Advertising

  3. babz

    babz Guest

    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
    babz, Sep 14, 2005
    #3
  4. babz

    Roedy Green Guest

    On 13 Sep 2005 21:52:57 -0700, "babz" <> 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.
    Roedy Green, Sep 14, 2005
    #4
  5. babz

    babz Guest

    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
    babz, Sep 20, 2005
    #5
  6. babz

    babz Guest

    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
    babz, Sep 21, 2005
    #6
  7. babz

    babz Guest

    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
    babz, Sep 22, 2005
    #7
  8. babz

    Roedy Green Guest

    On 20 Sep 2005 05:35:08 -0700, "babz" <> 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.
    Roedy Green, Sep 23, 2005
    #8
  9. babz

    Roedy Green Guest

    On 20 Sep 2005 21:58:30 -0700, "babz" <> 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.
    Roedy Green, Sep 23, 2005
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. eruess
    Replies:
    0
    Views:
    456
    eruess
    Aug 8, 2003
  2. MW de Jager

    Transparent images

    MW de Jager, Jun 10, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    445
    MW de Jager
    Jun 10, 2005
  3. =?Utf-8?B?TWVrZW4=?=

    Resize transparent gif images

    =?Utf-8?B?TWVrZW4=?=, Jul 20, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    592
    =?Utf-8?B?TWVrZW4=?=
    Jul 20, 2005
  4. Ramon F Herrera
    Replies:
    6
    Views:
    1,683
    Andrew Thompson
    Jul 2, 2005
Loading...

Share This Page