-
public class AnimatedGifEncoderClass AnimatedGifEncoder - Encodes a GIF file consisting of one or more frames.
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.Example: AnimatedGifEncoder e = new AnimatedGifEncoder(); e.start(outputFileName); e.setDelay(1000); // 1 frame per sec e.addFrame(image1); e.addFrame(image2); e.addFrame(image3, 100, 100); // set position of the frame e.finish();
-
-
Field Summary
Fields Modifier and Type Field Description private Integertransparentprivate intrepeatprivate intdelayprivate intdispose
-
Method Summary
Modifier and Type Method Description voidsetTransparent(int color)Sets the transparent color for the last added frame and any subsequentframes. voidsetRepeat(int iter)Sets the number of times the set of GIF frames should be played. voidsetDelay(int ms)Sets the delay time between each frame, or changes it for subsequent frames(applies to last frame added). voidsetDispose(int code)Sets the GIF frame disposal code for the last added frame and anysubsequent frames. booleanaddFrame(@Nullable() Bitmap im)Adds next GIF frame. booleanaddFrame(@Nullable() Bitmap im, int x, int y)Adds next GIF frame to the specified position. booleanfinish()Flushes any pending data and closes output file. voidsetFrameRate(float fps)Sets frame rate in frames per second. voidsetQuality(int quality)Sets quality of color quantization (conversion of images to the maximum 256colors allowed by the GIF specification). voidsetSize(int w, int h)Sets the fixed GIF frame size for all the frames.This should be called before start. booleanstart(@Nullable() OutputStream os)Initiates GIF file creation on the given stream. booleanstart(@NonNull() String file)Initiates writing of a GIF file with the specified name. -
-
Method Detail
-
setTransparent
void setTransparent(int color)
Sets the transparent color for the last added frame and any subsequentframes. Since all colors are subject to modification in the quantizationprocess, the color in the final palette for each frame closest to the givencolor becomes the transparent color for that frame. May be set to null toindicate no transparent color.
- Parameters:
color- Color to be treated as transparent on display.
-
setRepeat
void setRepeat(int iter)
Sets the number of times the set of GIF frames should be played. Default is1; 0 means play indefinitely. Must be invoked before the first image isadded.
- Parameters:
iter- int number of iterations.
-
setDelay
void setDelay(int ms)
Sets the delay time between each frame, or changes it for subsequent frames(applies to last frame added).
- Parameters:
ms- int delay time in milliseconds
-
setDispose
void setDispose(int code)
Sets the GIF frame disposal code for the last added frame and anysubsequent frames. Default is 0 if no transparent color has been set,otherwise 2.
- Parameters:
code- int disposal code.
-
addFrame
boolean addFrame(@Nullable() Bitmap im)
Adds next GIF frame. The frame is not written immediately, but is actuallydeferred until the next frame is received so that timing data can beinserted. Invoking
finish()flushes all frames. IfsetSizewas invoked, the size is used for all subsequent frames.Otherwise, the actual size of the image is used for each frames.- Parameters:
im- BufferedImage containing frame to write.
-
addFrame
boolean addFrame(@Nullable() Bitmap im, int x, int y)
Adds next GIF frame to the specified position. The frame is not written immediately, but isactually deferred until the next frame is received so that timing data can be inserted.Invoking
finish()flushes all frames. IfsetSizewas invoked, thesize is used for all subsequent frames. Otherwise, the actual size of the image is used foreach frame.See page 11 of http://giflib.sourceforge.net/gif89.txt for the position of the frame- Parameters:
im- BufferedImage containing frame to write.x- Column number, in pixels, of the left edge of the image, with respect to the leftedge of the Logical Screen.y- Row number, in pixels, of the top edge of the image with respect to the top edge ofthe Logical Screen.
-
finish
boolean finish()
Flushes any pending data and closes output file. If writing to anOutputStream, the stream is not closed.
-
setFrameRate
void setFrameRate(float fps)
Sets frame rate in frames per second. Equivalent to
setDelay(1000/fps).- Parameters:
fps- float frame rate (frames per second)
-
setQuality
void setQuality(int quality)
Sets quality of color quantization (conversion of images to the maximum 256colors allowed by the GIF specification). Lower values (minimum = 1)produce better colors, but slow processing significantly. 10 is thedefault, and produces good color mapping at reasonable speeds. Valuesgreater than 20 do not yield significant improvements in speed.
- Parameters:
quality- int greater than 0.
-
setSize
void setSize(int w, int h)
Sets the fixed GIF frame size for all the frames.This should be called before start.
- Parameters:
w- int frame width.h- int frame width.
-
start
boolean start(@Nullable() OutputStream os)
Initiates GIF file creation on the given stream. The stream is not closedautomatically.
- Parameters:
os- OutputStream on which GIF images are written.
-
-
-
-