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.finish();
来自:https://github.com/rtyley/animated-gif-lib-for-java
Modifier and Type | Field and Description |
---|---|
protected Color |
background |
protected boolean |
closeStream |
protected int |
colorDepth |
protected byte[] |
colorTab |
protected int |
delay |
protected int |
dispose |
protected boolean |
firstFrame |
protected int |
height |
protected BufferedImage |
image |
protected byte[] |
indexedPixels |
protected OutputStream |
out |
protected int |
palSize |
protected byte[] |
pixels |
protected int |
repeat |
protected int |
sample |
protected boolean |
sizeSet |
protected boolean |
started |
protected int |
transIndex |
protected Color |
transparent |
protected boolean |
transparentExactMatch |
protected boolean[] |
usedEntry |
protected int |
width |
Constructor and Description |
---|
AnimatedGifEncoder() |
Modifier and Type | Method and Description |
---|---|
boolean |
addFrame(BufferedImage im)
Adds next GIF frame.
|
protected void |
analyzePixels()
Analyzes image colors and creates color map.
|
protected int |
findClosest(Color c)
Returns index of palette color closest to c
|
protected int |
findExact(Color c)
Returns index of palette exactly matching to color c or -1 if there is no exact matching.
|
boolean |
finish()
Flushes any pending data and closes output file.
|
protected void |
getImagePixels()
Extracts image pixels into byte array "pixels"
|
boolean |
isStarted() |
void |
setBackground(Color c)
Sets the background color for the last added frame
and any subsequent frames.
|
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(Color c)
Sets the transparent color for the last added frame
and any subsequent frames.
|
void |
setTransparent(Color c,
boolean exactMatch)
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.
|
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(String s)
Writes string to output stream
|
protected int width
protected int height
protected Color transparent
protected boolean transparentExactMatch
protected Color background
protected int transIndex
protected int repeat
protected int delay
protected boolean started
protected OutputStream out
protected 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
public void setDelay(int ms)
ms
- 间隔时间,单位毫秒public void setDispose(int code)
code
- int disposal code.public void setRepeat(int iter)
iter
- int number of iterations.public void setTransparent(Color c)
c
- Color to be treated as transparent on display.public void setTransparent(Color c, boolean exactMatch)
c
- Color to be treated as transparent on display.exactMatch
- If exactMatch is set to true, transparent color index is search with exact matchpublic void setBackground(Color c)
c
- Color to be treated as background on display.public boolean addFrame(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(OutputStream os)
os
- OutputStream on which GIF images are written.public boolean start(String file)
file
- String containing output file name.public boolean isStarted()
protected void analyzePixels()
protected int findClosest(Color c)
c
- Colorprotected int findExact(Color c)
c
- Colorprotected void getImagePixels()
protected void writeGraphicCtrlExt() throws IOException
IOException
- IO异常protected void writeImageDesc() throws IOException
IOException
- IO异常protected void writeLSD() throws IOException
IOException
- IO异常protected void writeNetscapeExt() throws IOException
IOException
- IO异常protected void writePalette() throws IOException
IOException
- IO异常protected void writePixels() throws IOException
IOException
- IO异常protected void writeShort(int value) throws IOException
value
- 16-bit valueIOException
- IO异常protected void writeString(String s) throws IOException
s
- StringIOException
- IO异常Copyright © 2024. All rights reserved.