Android ImageView that handles animated GIF images

Overview

GifImageView

Android ImageView that handles Animated GIF images

Android Arsenal Build Status

Usage

In your build.gradle file:

dependencies {
  compile 'com.felipecsl:gifimageview:2.2.0'
}

In your Activity class:

@Override protected void onCreate(final Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  gifView = findViewById(R.id.gifImageView);
  gifView.setBytes(bitmapData);
}

@Override protected void onStart() {
  super.onStart();
  gifView.startAnimation();
}

@Override protected void onStop() {
  super.onStop();
  gifView.stopAnimation();
}

If you need to post-process the GIF frames, you can do that via GifImageView.setOnFrameAvailable(). You can see an example of that in the sample app included on the repository.

gifImageView.setOnFrameAvailable(new GifImageView.OnFrameAvailable() {
  @Override public Bitmap onFrameAvailable(Bitmap bitmap) {
    return blurFilter.blur(bitmap);
  }
});

You can also reset an animation to play again from the beginning gifImageView.resetAnimation(); or show a specific frame of the animation gifImageView.gotoFrame(3);

Demo

Be sure to also check the demo project for a sample of usage!

Snapshots of the development version are available in Sonatype's snapshots repository.

Contributing

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.

Copyright and license

Code and documentation copyright 2011- Felipe Lima. Code released under the MIT license.

Comments
  • Latest commit on gradle available?

    Latest commit on gradle available?

    Can we get the latest code update i.e. fix of divide by zero error through gradle?

    I am using compile 'com.felipecsl:gifimageview:2.0.0' to use this library but it is still showing divide by zero exception.

    Please help!!

    opened by SalmanJawed 6
  • divide by zero Problem

    divide by zero Problem

    I get this error when using GifImageView with GridView using custom ImageAdapter extends BaseAdapter

    12-02 16:06:56.619 15491-15601/? E/AndroidRuntime: FATAL EXCEPTION: Thread-3008 Process: vn.messengerkvtm.gs, PID: 15491 java.lang.ArithmeticException: divide by zero at com.felipecsl.gifimageview.library.GifDecoder.advance(GifDecoder.java:229) at com.felipecsl.gifimageview.library.GifImageView.run(GifImageView.java:157) at java.lang.Thread.run(Thread.java:841)

    ImageAdapter.txt

    opened by TaQuangTien 6
  • Some gifs display broken

    Some gifs display broken

    Please take a look at this gif http://katemobile.ru/tmp/sample3.gif It's fine. But if you try to open it in GifImageView you can see some glitches at the bottom of the file. It's not about this specific gif, I can get more samples like that. Have no idea why it happens. But there's one hint I can provide: GifImageView and Glide use the same GifDecoder implementations right? It's pretty much modified in both projects but still I guess it comes from the same place. But Glide implementation plays this git correctly. So if we can figure out the difference between two implementations we can tell where the problem is. Probably not that easy to do.

    opened by thest1 6
  • Does this support transparent GIFs?

    Does this support transparent GIFs?

    I'm rendering animated GIFs with transparent backgrounds. They appear correctly on iOS but on Android they have a black background. Am I not specifying a parameter for the decoder? I didn't see one. Looks like it's taking its cue from each frame. Thanks!

    opened by teddis 6
  • Apply latest changes of glide gifdecoder, fix DISPOSE_BACKGROUND and DISPOSE_PREVIOUS

    Apply latest changes of glide gifdecoder, fix DISPOSE_BACKGROUND and DISPOSE_PREVIOUS

    Instead of https://github.com/felipecsl/GifImageView/pull/54 , submitting a new PR.

    As @felipecsl mentioned, copied code block from https://github.com/bumptech/glide/blob/6ddb5f0598b1a5a5a51647fb968e998d6cabbd3d/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/StandardGifDecoder.java#L389-L392

    Works well with my case, and also I hope it will fix https://github.com/felipecsl/GifImageView/issues/46

    Thanks.

    opened by keewon 5
  • Fix #29 - Division by Zero Exception

    Fix #29 - Division by Zero Exception

    Added Grid View activity to the sample:

    1. To demonstrate / test lots of GIFs at once.
    2. #29 was reported to occur in a GridView so made sense to test with it.

    Fixes #29.

    opened by lordcodes 5
  • getting Build failed after migrated to AndroidX

    getting Build failed after migrated to AndroidX

    Build error: ERROR: Unable to resolve dependency for ':app@devDebug/compileClasspath': Failed to transform file 'gifimageview-2.2.0.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform Show Details Affected Modules: app

    ERROR: Unable to resolve dependency for ':app@devDebugAndroidTest/compileClasspath': Failed to transform file 'gifimageview-2.2.0.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform Show Details Affected Modules: app

    ERROR: Unable to resolve dependency for ':app@devDebugUnitTest/compileClasspath': Failed to transform file 'gifimageview-2.2.0.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform Show Details Affected Modules: app

    ERROR: Unable to resolve dependency for ':app@devRelease/compileClasspath': Failed to transform file 'gifimageview-2.2.0.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform Show Details Affected Modules: app

    ERROR: Unable to resolve dependency for ':app@devReleaseUnitTest/compileClasspath': Failed to transform file 'gifimageview-2.2.0.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform Show Details Affected Modules: app

    ERROR: Unable to resolve dependency for ':app@inhouseDebug/compileClasspath': Failed to transform file 'gifimageview-2.2.0.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform Show Details Affected Modules: app

    ERROR: Unable to resolve dependency for ':app@inhouseDebugAndroidTest/compileClasspath': Failed to transform file 'gifimageview-2.2.0.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform Show Details Affected Modules: app

    ERROR: Unable to resolve dependency for ':app@inhouseDebugUnitTest/compileClasspath': Failed to transform file 'gifimageview-2.2.0.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform Show Details Affected Modules: app

    ERROR: Unable to resolve dependency for ':app@inhouseRelease/compileClasspath': Failed to transform file 'gifimageview-2.2.0.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform Show Details Affected Modules: app

    ERROR: Unable to resolve dependency for ':app@inhouseReleaseUnitTest/compileClasspath': Failed to transform file 'gifimageview-2.2.0.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform Show Details Affected Modules: app

    ERROR: Unable to resolve dependency for ':app@betaDebug/compileClasspath': Failed to transform file 'gifimageview-2.2.0.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform Show Details Affected Modules: app

    ERROR: Unable to resolve dependency for ':app@betaDebugAndroidTest/compileClasspath': Failed to transform file 'gifimageview-2.2.0.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform Show Details Affected Modules: app

    ERROR: Unable to resolve dependency for ':app@betaDebugUnitTest/compileClasspath': Failed to transform file 'gifimageview-2.2.0.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform Show Details Affected Modules: app

    ERROR: Unable to resolve dependency for ':app@betaRelease/compileClasspath': Failed to transform file 'gifimageview-2.2.0.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform Show Details Affected Modules: app

    ERROR: Unable to resolve dependency for ':app@betaReleaseUnitTest/compileClasspath': Failed to transform file 'gifimageview-2.2.0.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform Show Details Affected Modules: app

    opened by shyamkumarm 4
  • Does this support Android 4.4.2?

    Does this support Android 4.4.2?

    I use setImageResource() to set a gif from drawable folder, not download from url. And call startAnimation(), then isAnimating() return true, but UI doesn't visually work.

    opened by chengxinwen-vinci 3
  •  java.lang.IllegalArgumentException: Bad position

    java.lang.IllegalArgumentException: Bad position

    This is the following stacktrace happens when set bytes to the view

    Caused by java.lang.IllegalArgumentException: Bad position (limit 34457): 34641 at java.nio.Buffer.positionImpl(Buffer.java:357) at java.nio.Buffer.position(Buffer.java:351) at com.felipecsl.gifimageview.library.GifHeaderParser.skip(GifHeaderParser.java:364) at com.felipecsl.gifimageview.library.GifHeaderParser.skipImageData(GifHeaderParser.java:354) at com.felipecsl.gifimageview.library.GifHeaderParser.readBitmap(GifHeaderParser.java:245) at com.felipecsl.gifimageview.library.GifHeaderParser.readContents(GifHeaderParser.java:136) at com.felipecsl.gifimageview.library.GifHeaderParser.readContents(GifHeaderParser.java:114) at com.felipecsl.gifimageview.library.GifHeaderParser.parseHeader(GifHeaderParser.java:89) at com.felipecsl.gifimageview.library.GifDecoder.read(GifDecoder.java:485) at com.felipecsl.gifimageview.library.GifImageView.setBytes(GifImageView.java:56)

    opened by djhacktor 3
  • Fallback to default frame delay if it's not specified

    Fallback to default frame delay if it's not specified

    Please try this gif https://psv4.vk.me/c537619/u98835002/docs/97b6b1010e47/file317.gif It plays fine in any gif player. But it plays super-fast in GifImageViewer. That happens because delays are not specified in this file, all delays are zero there. That's why I propose this modification. Fallback to 100 ms delay if it's not specified inside gif. I have tested this modification on multiple gifs and it works just fine. In other gif decoder implementations I can see the same fallback, for example take a look at this one https://github.com/bumptech/glide/blob/c2fc19316d8680322cabeed31234d19e942866e8/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeaderParser.java#L189

    opened by thest1 3
  • How to display gif image from external storage ?

    How to display gif image from external storage ?

    Hello there,

    I am unable to display locally stored gif image programatically. Here is my code String root = Environment.getExternalStorageDirectory().toString()+"/EnthuonsChat/Images/"+imageName; File fileToDownload = new File(root); if(fileToDownload.exists()){ new GifDataDownloader() { @Override protected void onPostExecute(final byte[] bytes) { ((ItemMessageUserHolder) holder).gifImageView.setBytes(bytes); ((ItemMessageUserHolder) holder).gifImageView.startAnimation(); } }.execute(root); } Please help me to resolve this issue....

    opened by ervinod 2
  • Memory leak due to rapid toggle of animation

    Memory leak due to rapid toggle of animation

    I'm using a GifImageView in situation where the animation is stopped and started very rapidly for a period of time. This toggling can happen as frequently as <10 milliseconds. This creates a memory leak which eventually crashes my app.

    From the code here, it looks like the thread which runs the animation is not actually stopped on the call to stopAnimation.

    https://github.com/felipecsl/GifImageView/blob/master/library/src/main/java/com/felipecsl/gifimageview/library/GifImageView.java#L184

    Am I correct in that and, if so, what is the reason for this behavior?

    opened by mrhubbs 0
  • play animation for only once and stop

    play animation for only once and stop

    Firstly I would like to thank you for a such a useful library for GIF. I am currently facing one issue while using this library. I want to a play the animation only once.I don't see a interface for stopping the animation after it plays once. and we don't have access GifDecoder to know if we want to stop at a particular frame. OnframeAvailble only priovdes the Bitmap but not the frame index.

    Regards Ravi

    opened by career4ravi 1
  • Frame might still get updated after stopAnimation is called

    Frame might still get updated after stopAnimation is called

    I am using the GifImageView in an Adapter where also static images can be set to the ImageView. So when stopping the Animation via clear() and setting a static image right afterwards via setImageBitmap(...), sometimes the static image is displayed only for an instant and is replaced by a frame of the previous set GIF almost immediately.

    This might be a threading issue: I think the updateResults Runnable might get executed even after clear() was called on the View. For that, I would suggest checking for animating == true in the Runnable before updating the Bitmap.

    opened by eltos 0
  • Gif play speed varies from device to device

    Gif play speed varies from device to device

    I noticed that on an older device I have (Galaxy S4 - 4.4.4) and on the emulators running 6.0, the gif I am using plays back at normal speed. However I just tried running it on a Galaxy S7 (6.0.1) and the playback speed of the gif seems to be about half. Any ideas on what could cause this?

    opened by smyang10 2
Owner
Felipe Lima
🇧🇷
Felipe Lima
A circular ImageView for Android

CircleImageView A fast circular ImageView perfect for profile images. This is based on RoundedImageView from Vince Mi which itself is based on techniq

Henning Dodenhof 14.4k Jan 5, 2023
Custom shaped android imageview components

Shape Image View Provides a set of custom shaped android imageview components, and a framework to define more shapes. Implements both shader and bitma

Siyamed SINIR 2.6k Jan 8, 2023
Android ImageView that supports different radii on each corner.

SelectableRoundedImageView Note that this project is no longer maintained. Android ImageView that supports different radii on each corner. It also sup

Joonho Kim 1.1k Nov 25, 2022
A fast ImageView that supports rounded corners, ovals, and circles.

RoundedImageView A fast ImageView (and Drawable) that supports rounded corners (and ovals or circles) based on the original example from Romain Guy. I

Vince Mi 6.4k Jan 8, 2023
An imageView can auto scroll with device rotating.

PanoramaImageView An imageView can auto scroll with device rotating. ScreenShots Include PanoramaImageView to Your Project With gradle: dependencies {

郭佳哲 2.2k Dec 26, 2022
Powerful and flexible library for loading, caching and displaying images on Android.

Universal Image Loader The great ancestor of modern image-loading libraries :) UIL aims to provide a powerful, flexible and highly customizable instru

Sergey Tarasevich 16.8k Jan 8, 2023
An Android library for managing images and the memory they use.

Fresco Fresco is a powerful system for displaying images in Android applications. Fresco takes care of image loading and display, so you don't have to

Facebook 16.9k Jan 8, 2023
An Android view for displaying repeated continuous side scrolling images. This can be used to create a parallax animation effect.

Scrolling Image View An Android view for displaying repeated continuous side scrolling images. This can be used to create a parallax animation effect.

Q42 1.8k Dec 27, 2022
Media Picker is an Android Libary that lets you to select multiple images or video

Media Picker Please let me know if your application go to production via this link Media Picker is an Android Libary that lets you to select multiple

Abdullah Alhazmy 264 Nov 10, 2022
Andorid library that loads images asynchronously into cache using a thread pool

AndroidImageLoader AndroidImageLoader is a fork of the Image Loader component in libs-for-android. The AndroidImageLoader is an Android library that h

David Wu 63 Feb 19, 2019
🍂 Jetpack Compose image loading library which can fetch and display network images using Glide, Coil, and Fresco.

?? Jetpack Compose image loading library which can fetch and display network images using Glide, Coil, and Fresco.

Jaewoong Eum 1.4k Jan 2, 2023
Load images using Glide

Glide_Demo Load images using Glide Image used private val image = "https://cdn.pixabay.com/photo/2018/05/03/21/49/android-3372580_1280.png" Add Glide

Daniel Kago K 0 Nov 1, 2021
Splash - Wanted an app that displays images from Unsplash, well here it is

Splash - Wanted an app that displays images from Unsplash, well here it is

Bamidele Ajewole 2 Apr 26, 2022
An image loading and caching library for Android focused on smooth scrolling

Glide | View Glide's documentation | 简体中文文档 | Report an issue with Glide Glide is a fast and efficient open source media management and image loading

Bump Technologies 33.2k Jan 7, 2023
Android Asynchronous Networking and Image Loading

Android Asynchronous Networking and Image Loading Download Maven Git Features Kotlin coroutine/suspend support Asynchronously download: Images into Im

Koushik Dutta 6.3k Dec 27, 2022
A powerful image downloading and caching library for Android

Picasso A powerful image downloading and caching library for Android For more information please see the website Download Download the latest AAR from

Square 18.4k Jan 6, 2023
Image loading for Android backed by Kotlin Coroutines.

An image loading library for Android backed by Kotlin Coroutines. Coil is: Fast: Coil performs a number of optimizations including memory and disk cac

Coil 8.8k Jan 8, 2023
Photo picker library for android. Let's you pick photos directly from files, or navigate to camera or gallery.

ChiliPhotoPicker Made with ❤️ by Chili Labs. Library made without DataBinding, RxJava and image loading libraries, to give you opportunity to use it w

Chili Labs 394 Jan 2, 2023
:ribbon: The simple way to implement a beautiful ribbon with the shimmering on Android.

AndroidRibbon ?? The simple way to implement a beautiful ribbon with the shimmering on Android. 中文語 Download Gradle Add below codes to your root build

Jaewoong Eum 653 Jan 7, 2023