Skip to main content

GIF Animations

2 replies [Last post]
gwampole
Offline
Joined: 2005-02-15
Points: 0

I'm attempting to use the GIF ImageWriter to create an animated GIF in the following style:

<br />
ImageWriter gifWriter = ImageIO.getImageWritersByFormatName( "gif" ).next();<br />
gifWriter.setOutput( new FileImageOutputStream( new File( "test.gif" ) ) );<br />
gifWriter.prepareWriteSequence( null );</p>
<p>/* 'image1', 'image2', and 'image3' were gleaned from other GIF files */</p>
<p>gifWriter.writeToSequence( new IIOImage( image1, null, null ), null ) );<br />
gifWriter.writeToSequence( new IIOImage( image2, null, null ), null ) );<br />
gifWriter.writeToSequence( new IIOImage( image3, null, null ), null ) );<br />
... etc<br />
gifWriter.endWriteSequence();<br />

What I end up with appears to be an image with all consituent frames superimposed upon one another. Is my ImageWriter usage wrong, or perhaps there is there some value I must set in the metadata to indicate that an animation is desired?

Any help is appreciated!
-Garrett

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
gwampole
Offline
Joined: 2005-02-15
Points: 0

After finding the GIF image metadata DTD among the IIO framework API documentation, I'm able to create a GIF animation...however, it's not immediately clear to me how I can specify the number of times the animation will loop (it appears that the default is once).

Any point in the right direction would certainly help!
Thank you!
-Garrett

gwampole
Offline
Joined: 2005-02-15
Points: 0

In case anyone is interested, you have to add an application extension to the metadata whose application identifier and Authentication Code are "NETSCAPE" and "2.0" respectively.

The application data consists of three bytes, where the first byte has a value of '1', and the next two bytes compose an integer value that denotes the desired number of animation loops (zero indicating continuous looping).