Animated Gif's in Java

An artist wants to send me animated .gif’s to use within a Java game. For the sprites he sent me, I told him to just use a regular .gif with the frames in a horizontal strip. But he wants to send me some other things now, and I figure it’s a good time to learn how to use animated .gif’s.

I searched the API and the Internet, and I found that Java has some sort of way to load animated gif’s. I found a note that they were displayed normally in old versions of Java (1.2, I believe) but required additional work in later versions of Java.

There’s a note about animated gif’s in the API for ImageIcon.setImageObserver, but it doesn’t make much sense. I thought that ImageObservers were for seeing whether an image was loaded, not for doing animations.

All I really need to do is get an array of images from an animated gif file, but I don’t know how to work with them.

Can anyone direct me to a tutorial or any sort of information about animated gif’s in Java?

How about googling for “java animated gif”? =)

Anyway, if your purpose is to put an animated gif into your
Swing GUI, then it’s automatically supported - just create an
javax.swing.ImageIcon object for your image and set it into your component.
This should cover most of the use cases.

If you need to read individual frames, or write an animated
gif you can use javax.imageo.ImageIO set of API.

Dmitri

Thank you. Googling for “java animated gif” worked. I hadn’t searched for that particular combination of words (even though it’s the obvious thing to search for).

I had tried google with several different word combinations, but I think I kept saying “gifs” instead of “gif”. Referring to multiple gif images as “gifs” must be unusual.