public class GifDecoder extends Object
advance()
before requesting the next
frame. This method must also be called before you request the first frame or an error will
occur.
Implementation adapted from sample code published in Lyons. (2004). Java for Programmers,
republished under the MIT Open Source LicenseModifier and Type | Class and Description |
---|---|
static interface |
GifDecoder.BitmapProvider
|
Modifier and Type | Field and Description |
---|---|
static int |
STATUS_FORMAT_ERROR
File read status: Error decoding file (may be partially decoded).
|
static int |
STATUS_OK
File read status: No errors.
|
static int |
STATUS_OPEN_ERROR
File read status: Unable to open source.
|
static int |
STATUS_PARTIAL_DECODE
Unable to fully decode the current frame.
|
static int |
TOTAL_ITERATION_COUNT_FOREVER
The total iteration count which means repeat forever.
|
Constructor and Description |
---|
GifDecoder(GifDecoder.BitmapProvider provider) |
Modifier and Type | Method and Description |
---|---|
void |
advance()
Move the animation frame counter forward.
|
void |
clear() |
int |
getCurrentFrameIndex()
Gets the current index of the animation frame, or -1 if animation hasn't not yet started.
|
byte[] |
getData() |
int |
getDelay(int n)
Gets display duration for specified frame.
|
int |
getFrameCount()
Gets the number of frames read from file.
|
int |
getHeight() |
int |
getLoopCount()
Deprecated.
Use
getNetscapeLoopCount() instead.
This method cannot distinguish whether the loop count is 1 or doesn't exist. |
int |
getNetscapeLoopCount()
Gets the "Netscape" loop count, if any.
|
int |
getNextDelay()
Gets display duration for the upcoming frame in ms.
|
Bitmap |
getNextFrame()
Get the next frame in the animation sequence.
|
int |
getStatus()
Returns the current status of the decoder.
|
int |
getTotalIterationCount()
Gets the total count which represents how many times the animation sequence should be displayed.
|
int |
getWidth() |
int |
read(byte[] data)
Reads GIF image from byte array.
|
int |
read(InputStream is,
int contentLength)
Reads GIF image from stream.
|
void |
resetFrameIndex() |
void |
setData(GifHeader header,
byte[] data) |
public static final int STATUS_OK
public static final int STATUS_FORMAT_ERROR
public static final int STATUS_OPEN_ERROR
public static final int STATUS_PARTIAL_DECODE
public static final int TOTAL_ITERATION_COUNT_FOREVER
public GifDecoder(GifDecoder.BitmapProvider provider)
public int getWidth()
public int getHeight()
public byte[] getData()
public int getStatus()
Status will update per frame to allow the caller to tell whether or not the current frame was decoded successfully and/or completely. Format and open failures persist across frames.
public void advance()
public int getDelay(int n)
n
- int index of frame.public int getNextDelay()
public int getFrameCount()
public int getCurrentFrameIndex()
public void resetFrameIndex()
@Deprecated public int getLoopCount()
getNetscapeLoopCount()
instead.
This method cannot distinguish whether the loop count is 1 or doesn't exist.public int getNetscapeLoopCount()
GifHeader.NETSCAPE_LOOP_COUNT_FOREVER
)
means repeat indefinitely. It must not be a negative value.
getTotalIterationCount()
to know how many times the animation sequence should be displayed.GifHeader.NETSCAPE_LOOP_COUNT_DOES_NOT_EXIST
).public int getTotalIterationCount()
TOTAL_ITERATION_COUNT_FOREVER
) means repeat indefinitely.
It must not be a negative value.
The total count is calculated as follows by using getNetscapeLoopCount()
.
This behavior is the same as most web browsers.
getNetscapeLoopCount() |
The total count |
---|---|
GifHeader.NETSCAPE_LOOP_COUNT_FOREVER |
TOTAL_ITERATION_COUNT_FOREVER |
GifHeader.NETSCAPE_LOOP_COUNT_DOES_NOT_EXIST |
1 |
n (n > 0) |
n +1 |
public Bitmap getNextFrame()
public int read(InputStream is, int contentLength)
is
- containing GIF file.public void clear()
public void setData(GifHeader header, byte[] data)
public int read(byte[] data)
data
- containing GIF file.