public class AnimatedGifEncoder extends Object
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();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.
Constructor and Description |
---|
AnimatedGifEncoder() |
Modifier and Type | Method and Description |
---|---|
boolean |
addFrame(Bitmap im)
Adds next GIF frame.
|
boolean |
addFrame(Bitmap im,
int x,
int y)
Adds next GIF frame to the specified position.
|
boolean |
finish()
Flushes any pending data and closes output file.
|
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 fixed GIF frame size for all the frames.
|
void |
setTransparent(int color)
Sets the transparent color for the last added frame and any subsequent
frames.
|
boolean |
start(OutputStream os)
Initiates GIF file creation on the given stream.
|
boolean |
start(String file)
Initiates writing of a GIF file with the specified name.
|
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(int color)
color
- Color to be treated as transparent on display.public boolean addFrame(Bitmap im)
finish()
flushes all frames. If
setSize
was invoked, the size is used for all subsequent frames.
Otherwise, the actual size of the image is used for each frames.im
- BufferedImage containing frame to write.public boolean addFrame(Bitmap im, int x, int y)
finish()
flushes all frames. If setSize
was invoked, the
size is used for all subsequent frames. Otherwise, the actual size of the image is used for
each frame.
See page 11 of http://giflib.sourceforge.net/gif89.txt for the position of the frameim
- BufferedImage containing frame to write.x
- Column number, in pixels, of the left edge of the image, with respect to the left
edge of the Logical Screen.y
- Row number, in pixels, of the top edge of the image with respect to the top edge of
the Logical Screen.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(OutputStream os)
os
- OutputStream on which GIF images are written.public boolean start(String file)
file
- String containing output file name.