Package pl.droidsonroids.gif
Class GifDecoder
java.lang.Object
pl.droidsonroids.gif.GifDecoder
public class GifDecoder extends Object
GifDecoder allows lightweight access to GIF frames, without wrappers like Drawable or View.
Bitmap with size equal to or greater than size of the GIF is needed.
For access only metadata (size, number of frames etc.) without pixels see GifAnimationMetaData.-
Constructor Summary
Constructors Constructor Description GifDecoder(InputSource inputSource)Constructs new GifDecoder.GifDecoder(InputSource inputSource, GifOptions options)Constructs new GifDecoder -
Method Summary
Modifier and Type Method Description longgetAllocationByteCount()StringgetComment()intgetDuration()intgetFrameDuration(int index)intgetHeight()intgetLoopCount()intgetNumberOfFrames()longgetSourceLength()intgetWidth()booleanisAnimated()voidrecycle()voidseekToFrame(int frameIndex, Bitmap buffer)voidseekToTime(int position, Bitmap buffer)
-
Constructor Details
-
GifDecoder
Constructs new GifDecoder. Equivalent ofGifDecoder(InputSource, GifOptions)with nulloptions- Parameters:
inputSource- source- Throws:
IOException- when creation fails
-
GifDecoder
public GifDecoder(@NonNull InputSource inputSource, @Nullable GifOptions options) throws IOExceptionConstructs new GifDecoder- Parameters:
inputSource- sourceoptions- null-ok; options controlling subsampling and opacity- Throws:
IOException- when creation fails
-
-
Method Details
-
getComment
- Returns:
- GIF comment
-
getLoopCount
public int getLoopCount()- Returns:
- loop count, 0 means that animation is infinite
-
getSourceLength
public long getSourceLength()- Returns:
- number of bytes backed by input source or -1 if it is unknown
-
seekToTime
- Parameters:
position- position to seek to in millisecondsbuffer- the frame buffer- Throws:
IllegalArgumentException- ifposition < 0orbufferis recycled
-
seekToFrame
- Parameters:
frameIndex- position to seek to in millisecondsbuffer- the frame buffer- Throws:
IllegalArgumentException- ifframeIndex < 0orbufferis recycled
-
getAllocationByteCount
public long getAllocationByteCount()- Returns:
- possible size of the memory needed to store pixels of this object
-
getFrameDuration
public int getFrameDuration(@IntRange(from=0L) int index)- Parameters:
index- index of the frame- Returns:
- duration of the given frame in milliseconds
- Throws:
IndexOutOfBoundsException- ifindex < 0 || index >= <number of frames>
-
getDuration
public int getDuration()- Returns:
- duration of of one loop the animation in milliseconds. Result is always multiple of 10.
-
getWidth
public int getWidth()- Returns:
- width od the GIF canvas in pixels
-
getHeight
public int getHeight()- Returns:
- height od the GIF canvas in pixels
-
getNumberOfFrames
public int getNumberOfFrames()- Returns:
- number of frames in GIF, at least one
-
isAnimated
public boolean isAnimated()- Returns:
- true if GIF is animated (has at least 2 frames and positive duration), false otherwise
-
recycle
public void recycle()
-