Split GIF into frames

前端 未结 1 601
闹比i
闹比i 2020-12-31 07:48

Trying to play animated GIFs on Android here (see Android: How do a display a large animated gif given a url?). It\'s anything but smooth. On Android 1.5, the Movie.decodeSt

相关标签:
1条回答
  • 2020-12-31 08:42

    EDIT: I've migrated my project to Google GifFileDecoder, slightly patched. The MovieView class from the legacy solution remained mostly intact, but the GIF parsing logic is in Java.

    Couple points of interest: GifFileDecoder does its own looping. If the animation is looped and you do readFrame() until there are no more frames, this loop will be infinite; the decoder has its own wrap-around logic. Also, the buffer that readFrame() returns is being reused over and over, so don't store the result of readFrame as it is, next time you call readFrame it will be overwritten. Make a deep copy instead. Also, the decoder assumes reading from a file, but can be trivially modified to read from any other stream, sacrificing the looping logic.

    Here's the 10 year old answer, for old times' sake:

    giflib 4.1.4 and NDK. You have to manually resolve the palette colors in the GIF to match one of Android's ARGBxxxx formats, then pass the pixel array to a Bitmap object via copyPixelsFromBuffer(). If you want transparency and/or animation, you have to go through extension blocks and look for the one with code 0xf9.

    Shared my code, along with guidance, here: http://rathertech.blogspot.com/2014/04/splitting-gif-into-frames-on-android.html

    0 讨论(0)
提交回复
热议问题