Transparent gif, png
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Wednesday, January 16, 2002 10:48 AM

How can i make a transparent GIF or png or Image with transparent background?

Re: Transparent gif, png

Posted By:   Yuval_Zukerman  
Posted On:   Thursday, January 24, 2002 12:47 PM

You can display either GIFs or JPEGs in AWT. This includes GIFs with transparent areas - although they would still be handled as having rectangular areas.
Since regular AWT components are knowns as heavyweight - whcih means that they have to have an opaque background, you must create your own lightweight AWT component - and that component will contain your GIF - and THEN it will appear with its transparent areas.

To create a lightweight component, create a class that extends either java.awt.Component or java.awt.Container (normally java.awt.Component).


For example:


class LightWeight extends Component

{

private String pathToImage; // this is the GIF

private Image theImage;



public LightWeight(String image)

{

pathToImage = image;

}



public void paint (Graphics g)

{

theImage = Toolkit.getDefaultToolkit().getImage(pathToImage);

g.drawImage(theImage, 0, 0, this);

}

public Dimension getPreferredSize()

{

return new Dimension (

theImage.getWidth(this),

theImage.getHeight(this));

}

}


This should be a start...
About | Sitemap | Contact