|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectAnimatedGifEncoder
public class AnimatedGifEncoder
Class AnimatedGifEncoder - Encodes a GIF file consisting of one or more frames.
Example: AnimatedGifEncoder e = new AnimatedGifEncoder(); e.start(outputFileName); e.setDelay(1000); // 1 frame per sec e.addFrame(image1); e.addFrame(image2); e.finish();No copyright asserted on the source code of this class. May be used for any purpose, however, refer to the Unisys LZW patent for restrictions on use of the associated LZWEncoder class. Please forward any corrections to kweiner@fmsware.com.
Field Summary | |
---|---|
protected boolean |
closeStream
boolean that represents closing the stream when finished (False) and not closing the stream (True). |
protected int |
colorDepth
int that represents the number of bit planes. |
protected byte[] |
colorTab
byte array that represents the RGB palette. |
protected int |
delay
int that represents the frame delay in hundredths. |
protected int |
dispose
int that represents the disposal code (-1 = use default). |
protected boolean |
firstFrame
boolean that represents animation is on the first frame(True) and not on the first frame (False). |
protected int |
height
int that represents the height of the image size. |
protected java.awt.image.BufferedImage |
image
BufferedImage object that represents the current frame. |
protected byte[] |
indexedPixels
byte array to hold converted frame indexed to palette. |
protected java.io.OutputStream |
out
OutputStream object for printing. |
protected int |
palSize
int that represents the color table size (bits-1). |
protected byte[] |
pixels
byte array to hold RGB values from frame. |
protected int |
repeat
int that represents the number of times to repeat the animation, DEFALUT is -1 (no repeat). |
protected int |
sample
int that represents the default sample interval for quantizer (10). |
protected boolean |
sizeSet
boolean that represents getting size from first frame (False) do not get size from first frame (True). |
protected boolean |
started
boolean that represents whether or not it is ready to output frames. |
protected int |
transIndex
int that represents the transparent index in the color table. |
protected java.awt.Color |
transparent
Color object that represents the transparent color. |
protected boolean[] |
usedEntry
boolean array to represent active palette entries. |
protected int |
width
int that represents the width of the image size. |
Constructor Summary | |
---|---|
AnimatedGifEncoder()
|
Method Summary | |
---|---|
boolean |
addFrame(java.awt.image.BufferedImage im)
Adds next GIF frame. |
protected void |
analyzePixels()
Analyzes image colors and creates color map. |
protected int |
findClosest(java.awt.Color c)
Returns index of palette color closest to c. |
boolean |
finish()
Flushes any pending data and closes output file. |
protected void |
getImagePixels()
Extracts image pixels into byte array "pixels". |
void |
setDelay(int ms)
Sets the delay time between each frame, or changes it for subsequent frames (applies to last frame added). |
void |
setDispose(int code)
Sets the GIF frame disposal code for the last added frame and any subsequent frames. |
void |
setFrameRate(float fps)
Sets frame rate in frames per second. |
void |
setQuality(int quality)
Sets quality of color quantization (conversion of images to the maximum 256 colors allowed by the GIF specification). |
void |
setRepeat(int iter)
Sets the number of times the set of GIF frames should be played. |
void |
setSize(int w,
int h)
Sets the GIF frame size. |
void |
setTransparent(java.awt.Color c)
Sets the transparent color for the last added frame and any subsequent frames. |
boolean |
start(java.io.OutputStream os)
Initiates GIF file creation on the given stream. |
boolean |
start(java.lang.String file)
Initiates writing of a GIF file with the specified name. |
protected void |
writeGraphicCtrlExt()
Writes Graphic Control Extension. |
protected void |
writeImageDesc()
Writes Image Descriptor. |
protected void |
writeLSD()
Writes Logical Screen Descriptor. |
protected void |
writeNetscapeExt()
Writes Netscape application extension to define repeat count. |
protected void |
writePalette()
Writes color table. |
protected void |
writePixels()
Encodes and writes pixel data. |
protected void |
writeShort(int value)
Write 16-bit value to output stream, LSB first. |
protected void |
writeString(java.lang.String s)
Writes string to output stream. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected int width
protected int height
protected java.awt.Color transparent
protected int transIndex
protected int repeat
protected int delay
protected boolean started
protected java.io.OutputStream out
protected java.awt.image.BufferedImage image
protected byte[] pixels
protected byte[] indexedPixels
protected int colorDepth
protected byte[] colorTab
protected boolean[] usedEntry
protected int palSize
protected int dispose
protected boolean closeStream
protected boolean firstFrame
protected boolean sizeSet
protected int sample
Constructor Detail |
---|
public AnimatedGifEncoder()
Method Detail |
---|
public void setDelay(int ms)
ms
- int delay time in millisecondspublic void setDispose(int code)
code
- int disposal code.public void setRepeat(int iter)
iter
- int number of iterations.public void setTransparent(java.awt.Color c)
c
- Color to be treated as transparent on display.public boolean addFrame(java.awt.image.BufferedImage im)
finish()
flushes all
frames. If setSize
was not invoked, the size of the
first image is used for all subsequent frames.
im
- BufferedImage containing frame to write.
public boolean finish()
public void setFrameRate(float fps)
setDelay(1000/fps)
.
fps
- float frame rate (frames per second)public void setQuality(int quality)
quality
- int greater than 0.public void setSize(int w, int h)
w
- int frame width.h
- int frame width.public boolean start(java.io.OutputStream os)
os
- OutputStream on which GIF images are written.
public boolean start(java.lang.String file)
file
- String containing output file name.
protected void analyzePixels()
protected int findClosest(java.awt.Color c)
c
- a Color object
protected void getImagePixels()
protected void writeGraphicCtrlExt() throws java.io.IOException
java.io.IOException
protected void writeImageDesc() throws java.io.IOException
java.io.IOException
protected void writeLSD() throws java.io.IOException
java.io.IOException
protected void writeNetscapeExt() throws java.io.IOException
java.io.IOException
protected void writePalette() throws java.io.IOException
java.io.IOException
protected void writePixels() throws java.io.IOException
java.io.IOException
protected void writeShort(int value) throws java.io.IOException
value
- an int specifying a number to be printed as a 16-bit value
java.io.IOException
protected void writeString(java.lang.String s) throws java.io.IOException
s
- a String to print to output stream
java.io.IOException
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |