I'm trying to draw an animated gif image on a JFrame. At the moment, this is how I'm doing it:
public class JImageComponent extends JComponent {
private static final long serialVersionUID = -6926323540532721196L;
private final Image image;
public JImageComponent(Image image) {
this.image = image;
}
public JImageComponent(byte[] data) {
this(Toolkit.getDefaultToolkit().createImage(data));
}
@Override
protected void paintComponent(Graphics graphics) {
super.paintComponent(graphics);
final int centerX = getWidth() / 2 - image.getWidth(this) / 2;
final int centerY = getHeight() / 2 - image.getHeight(this) / 2;
graphics.drawImage(image, centerX, centerY, this);
}
}
This is fine, however, (because there's shading on the edge) if i have a background colour set, it shows a nasty white edge. I think i know what's causing this, it's because of the the Image class does not utilise an alpha channel. I don't know how to make the image use a 32-bit colour model using the 8 most significant bits as the alpha value. Any help is appreciated! Thanks.
Edit: when I tried using a ImageIO and a BufferedImage, it didn't animate. Apparently this is because it doesn't update the ImageObserver
Edit: This is what the image looks like when there's a background: http://puu.sh/bQ5sZ.png I don't want that white edge, it should look like this: http://puu.sh/bQ5Ya.png. Like i said previously, i know why it's happening; I need the Image class to use RGBA not RBG.