public class StandardGifDecoder extends Object implements GifDecoder
This class is optimized for running animations with the frames, there are no methods to get individual frame images, only to decode the next frame in the animation sequence. Instead, it lowers its memory footprint by only housing the minimum data necessary to decode the next frame in the animation sequence.
The animation must be manually moved forward using 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 License
GifDecoder.BitmapProvider, GifDecoder.GifDecodeStatus
STATUS_FORMAT_ERROR, STATUS_OK, STATUS_OPEN_ERROR, STATUS_PARTIAL_DECODE, TOTAL_ITERATION_COUNT_FOREVER
构造器和说明 |
---|
StandardGifDecoder(GifDecoder.BitmapProvider provider) |
StandardGifDecoder(GifDecoder.BitmapProvider provider,
GifHeader gifHeader,
ByteBuffer rawData) |
StandardGifDecoder(GifDecoder.BitmapProvider provider,
GifHeader gifHeader,
ByteBuffer rawData,
int sampleSize) |
限定符和类型 | 方法和说明 |
---|---|
void |
advance()
Move the animation frame counter forward.
|
void |
clear() |
int |
getByteSize()
Returns an estimated byte size for this decoder based on the data provided to
GifDecoder.setData(GifHeader, byte[]) , as well as internal buffers. |
int |
getCurrentFrameIndex()
Gets the current index of the animation frame, or -1 if animation hasn't not yet started.
|
ByteBuffer |
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()
已过时。
|
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()
Resets the frame pointer to before the 0th frame, as if we'd never used this decoder to
decode any frames.
|
void |
setData(GifHeader header,
byte[] data) |
void |
setData(GifHeader header,
ByteBuffer buffer) |
void |
setData(GifHeader header,
ByteBuffer buffer,
int sampleSize) |
void |
setDefaultBitmapConfig(Bitmap.Config config)
Sets the default
Bitmap.Config to use when decoding frames of a GIF. |
public StandardGifDecoder(@NonNull GifDecoder.BitmapProvider provider, GifHeader gifHeader, ByteBuffer rawData)
public StandardGifDecoder(@NonNull GifDecoder.BitmapProvider provider, GifHeader gifHeader, ByteBuffer rawData, int sampleSize)
public StandardGifDecoder(@NonNull GifDecoder.BitmapProvider provider)
public int getWidth()
getWidth
在接口中 GifDecoder
public int getHeight()
getHeight
在接口中 GifDecoder
@NonNull public ByteBuffer getData()
getData
在接口中 GifDecoder
public int getStatus()
GifDecoder
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.
getStatus
在接口中 GifDecoder
public void advance()
GifDecoder
advance
在接口中 GifDecoder
public int getDelay(int n)
GifDecoder
getDelay
在接口中 GifDecoder
n
- int index of frame.public int getNextDelay()
GifDecoder
getNextDelay
在接口中 GifDecoder
public int getFrameCount()
GifDecoder
getFrameCount
在接口中 GifDecoder
public int getCurrentFrameIndex()
GifDecoder
getCurrentFrameIndex
在接口中 GifDecoder
public void resetFrameIndex()
GifDecoder
resetFrameIndex
在接口中 GifDecoder
@Deprecated public int getLoopCount()
GifDecoder
getLoopCount
在接口中 GifDecoder
public int getNetscapeLoopCount()
GifDecoder
GifHeader.NETSCAPE_LOOP_COUNT_FOREVER
) means repeat indefinitely.
It must not be a negative value.
GifDecoder.getTotalIterationCount()
to know how many times the animation sequence should be displayed.getNetscapeLoopCount
在接口中 GifDecoder
GifHeader.NETSCAPE_LOOP_COUNT_DOES_NOT_EXIST
).public int getTotalIterationCount()
GifDecoder
GifDecoder.TOTAL_ITERATION_COUNT_FOREVER
) means repeat indefinitely.
It must not be a negative value.
The total count is calculated as follows by using GifDecoder.getNetscapeLoopCount()
.
This behavior is the same as most web browsers.
getNetscapeLoopCount() |
The total count |
---|---|
GifHeader.NETSCAPE_LOOP_COUNT_FOREVER |
GifDecoder.TOTAL_ITERATION_COUNT_FOREVER |
GifHeader.NETSCAPE_LOOP_COUNT_DOES_NOT_EXIST |
1 |
n (n > 0) |
n + 1 |
getTotalIterationCount
在接口中 GifDecoder
public int getByteSize()
GifDecoder
GifDecoder.setData(GifHeader, byte[])
, as well as internal buffers.getByteSize
在接口中 GifDecoder
@Nullable public Bitmap getNextFrame()
GifDecoder
getNextFrame
在接口中 GifDecoder
public int read(@Nullable InputStream is, int contentLength)
GifDecoder
read
在接口中 GifDecoder
is
- containing GIF file.public void clear()
clear
在接口中 GifDecoder
public void setData(@NonNull GifHeader header, @NonNull byte[] data)
setData
在接口中 GifDecoder
public void setData(@NonNull GifHeader header, @NonNull ByteBuffer buffer)
setData
在接口中 GifDecoder
public void setData(@NonNull GifHeader header, @NonNull ByteBuffer buffer, int sampleSize)
setData
在接口中 GifDecoder
public int read(@Nullable byte[] data)
GifDecoder
read
在接口中 GifDecoder
data
- containing GIF file.public void setDefaultBitmapConfig(@NonNull Bitmap.Config config)
GifDecoder
Bitmap.Config
to use when decoding frames of a GIF.
Valid options are Bitmap.Config.ARGB_8888
and
Bitmap.Config.RGB_565
.
Bitmap.Config.ARGB_8888
will produce higher quality frames, but will
also use 2x the memory of Bitmap.Config.RGB_565
.
Defaults to Bitmap.Config.ARGB_8888
This value is not a guarantee. For example if set to
Bitmap.Config.RGB_565
and the GIF contains transparent pixels,
Bitmap.Config.ARGB_8888
will be used anyway to support the
transparency.
setDefaultBitmapConfig
在接口中 GifDecoder