Someone asked about animated icons on the Java2D list and this link popped up:
http://rabbit-hole.blogspot.com/2006/09/animated-icon-redux.html
That may help you. I don't know, you haven't really said what you mean by "distorted" or told us how you're loading and displaying the animated GIF.
I've put animated gifs in applets plenty of times and it worked fine. No "distortion". Actually not only did it work fine, but it was easy -- you just use drawImage like you would with any other image, and repaint() frequently, and the GUI toolkit figured out how to select frames for animation. I didn't even have to do the animation part.
> I've put animated gifs in applets plenty of times and
> it worked fine. No "distortion". Actually not only
> did it work fine, but it was easy -- you just use
> drawImage like you would with any other image, and
> repaint() frequently, and the GUI toolkit figured out
> how to select frames for animation. I didn't even
> have to do the animation part.
It's not quite that simple though. Depending on how the image is loaded that may or may not actually work. For example, one of these draws the animation perfectly, the other doesn't:
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new JLabel(new ImageIcon("C:\\anim.gif")));
frame.pack();
frame.setVisible(true);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new JLabel(new ImageIcon(ImageIO.read(new File("C:\\anim.gif"))));
frame.pack();
frame.setVisible(true);
import java.awt.*;
import java.applet.*;
// These classes are for Url's.
import java.net.*;
public class finding extends Applet
{
Image image;
URL base;
public void init()
{
base = getDocumentBase();
image = getImage(base,"finding.gif");
}
public void paint( Graphics g )
{
g.drawImage( image, 0, 0, this );
}
}
//////////////////////////////////////
this is what I did.. The image animates but it flashes across the screen... it isnt smooth animation.. I made the program as simple as I could..