to.etc.sjit
Class AnimGifEncoder

java.lang.Object
  extended by to.etc.sjit.AnimGifEncoder

public class AnimGifEncoder
extends java.lang.Object

This class can be used to write an animated GIF file by combining several images. It is loosely based on the Acme GIF encoder.

The characteristics of the generated Gif 89a image are:

An example of how to save an image to GIF is:

 import to.etc.sjit.*;   // Simple Java Imaging Tools

 private void saveGIF(File f, Image i2) throws IOException
 {
     OutputStream    ros = new FileOutputStream(f);
     try
     {
         AnimGifEncoder  ge  = new AnimGifEncoder(ros);
         ge.add(i);
         ge.encode();
     }
     finally
     {
         try { if(ros != null) ros.close(); } catch {}
     }
 }
 

Author:
Frits Jalvingh

Field Summary
 boolean m_no_opt
           
 
Constructor Summary
AnimGifEncoder(java.io.OutputStream os)
          This constructor creates an empty default codec.
AnimGifEncoder(java.io.OutputStream os, boolean interlace)
          Creates a codec and specify interlace (not implemented yet).
 
Method Summary
 void add(java.awt.Image ima)
          Adds the specified image to the list of images.
 void add(java.awt.Image ima, int delay)
          Adds the specified image to the list of images.
 void add(java.awt.Image ima, int delaytime, boolean interlace, int px, int py)
          Adds the specified image to the list of images.
 void encode()
          Creates the GIF file from all images added to the encoder.
 void flush()
          Releases ALL cached resources.
 void setLoop(boolean loop)
          For animated GIF's the default is to LOOP all images in the GIF file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_no_opt

public boolean m_no_opt
Constructor Detail

AnimGifEncoder

public AnimGifEncoder(java.io.OutputStream os)
This constructor creates an empty default codec.


AnimGifEncoder

public AnimGifEncoder(java.io.OutputStream os,
                      boolean interlace)
Creates a codec and specify interlace (not implemented yet).

Method Detail

setLoop

public void setLoop(boolean loop)

For animated GIF's the default is to LOOP all images in the GIF file. This means that after displaying all images in the file the first image is redisplayed ad infinitum.

To prevent the images from looping call setLoop(false) before calling the encode() method.

The current version does not allow the number of repetitions to be specified.


flush

public void flush()
Releases ALL cached resources.


add

public void add(java.awt.Image ima,
                int delaytime,
                boolean interlace,
                int px,
                int py)
         throws java.io.IOException
Adds the specified image to the list of images. While adding, the image is converted to pixels; each color is added to the color table and the resulting 8-bit pixelset is saved. After this call the image is released, and only the pixelset remains until the encode call is made. Calling encode will release the pixelset.

Throws:
java.io.IOException

add

public void add(java.awt.Image ima)
         throws java.io.IOException
Adds the specified image to the list of images.

Throws:
java.io.IOException

add

public void add(java.awt.Image ima,
                int delay)
         throws java.io.IOException
Adds the specified image to the list of images.

Throws:
java.io.IOException

encode

public void encode()
            throws java.io.IOException
Creates the GIF file from all images added to the encoder.

Throws:
java.io.IOException