I have a PNG image with transparency. I used the format because only PNG can support transparency and alpha masks.
My aim is to paint a JPanel with this image and let the transparent regions have the color of the underlying panel, And ultimately do some animations with the image.
How ever I am facing problems, the transparent regions turn out to be solid white color when loaded and painted on the JPanel.
So java does not support transparent images?
class imgpanel extends JPanel{
BufferedImage image,backg;
imgpanel(){
try {
image = ImageIO.read(new File("theimage.png"));
backg = ImageIO.read(new File("backimage.png"));
} catch (IOException ex) {
System.out.println("No image found");
}
setPreferredSize(new Dimension(400,300));
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(backg,0,0,null);
g.drawImage(image, 0, 0, null);
}
}
Thus I am painting the transparent "theimage" onto the opaque "backimage"