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 Details

  • Method Details

    • getComment

      public String 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

      public void seekToTime​(@IntRange(from=0L,to=2147483647L) int position, @NonNull Bitmap buffer)
      Parameters:
      position - position to seek to in milliseconds
      buffer - the frame buffer
      Throws:
      IllegalArgumentException - if position < 0 or buffer is recycled
    • seekToFrame

      public void seekToFrame​(@IntRange(from=0L,to=2147483647L) int frameIndex, @NonNull Bitmap buffer)
      Parameters:
      frameIndex - position to seek to in milliseconds
      buffer - the frame buffer
      Throws:
      IllegalArgumentException - if frameIndex < 0 or buffer is 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 - if index < 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()