net.wotonomy.ui.swing.util
Class GIFEncoder

java.lang.Object
  extended by net.wotonomy.ui.swing.util.GIFEncoder

public class GIFEncoder
extends java.lang.Object

GIFEncoder is a class which takes an image and saves it to a stream using the GIF file format. A GIFEncoder is constructed with either an AWT Image (which must be fully loaded) or a set of RGB arrays. The image can be written out with a call to write.

Three caveats:

This implementation is heavily based on code made available by Adam Doppelt, which was based upon gifsave.c, which was written and released by Sverre H. Huseby.

Author:
amd@brown.edu, sverrehu@ifi.uio.no, michael@mpowers.net

Constructor Summary
GIFEncoder(byte[][] r, byte[][] g, byte[][] b)
          Construct a GIFEncoder.
GIFEncoder(java.awt.Image image)
          Construct a GIFEncoder.
 
Method Summary
 void write(java.io.OutputStream output)
          Writes the image out to a stream in the GIF file format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GIFEncoder

public GIFEncoder(java.awt.Image image)
           throws java.awt.AWTException
Construct a GIFEncoder. The constructor will convert the image to an indexed color array. This may take some time. If more than 256 colors are encountered, all subsequent colors are mapped to the first color encountered.

Parameters:
image - The image to encode. The image must be completely loaded.
Throws:
java.awt.AWTException - Will be thrown if the pixel grab fails. This can happen if Java runs out of memory.

GIFEncoder

public GIFEncoder(byte[][] r,
                  byte[][] g,
                  byte[][] b)
           throws java.awt.AWTException
Construct a GIFEncoder. The constructor will convert the image to an indexed color array. This may take some time.

Each array stores intensity values for the image. In other words, r[x][y] refers to the red intensity of the pixel at column x, row y.

Parameters:
r - An array containing the red intensity values.
g - An array containing the green intensity values.
b - An array containing the blue intensity values.
Throws:
java.awt.AWTException - Will be thrown if the image contains more than 256 colors.
Method Detail

write

public void write(java.io.OutputStream output)
           throws java.io.IOException
Writes the image out to a stream in the GIF file format. This will be a single GIF87a image, non-interlaced, with no background color. This may take some time.

Parameters:
output - The stream to output to. This should probably be a buffered stream.
Throws:
java.io.IOException - Will be thrown if a write operation fails.


Copyright © 2006 null. All Rights Reserved.