Showing Gif Image with Library

前端 未结 4 984
傲寒
傲寒 2020-12-07 02:17

I am using this library to show gif image: https://github.com/felipecsl/GifImageView

But I don\'t know how to implement my gif image in these code. I have some GifIm

相关标签:
4条回答
  • 2020-12-07 02:50

    I would suggest looking into the Glide library, since it does animated GIFs without any modifications, and can fit into any project.

    It also has the added benefit of smoother loading and proper resizing, if you're using these images in any type of recycled view.


    As @fixmycode said, you are never defining bytes[], if you want to use your current implementation.

    0 讨论(0)
  • 2020-12-07 03:04

    1.I would suggest you to checkout Image Management Library by Facebook that is Fresco that is pretty awesome and mature as compared to other Image Loading Library.

    2.Fresco has SimpleDraweeView as custom image view which supports Rounded Corners and Circles link and supports Animated(.gif, .webp) as well as Normal Images(.jpg, .png).

    3.Fresco handles all the things caching of images with 3 Tier architecture ( BITMAP_MEMORY_CACHE, ENCODED_MEMORY_CACHE and DISK_CACHE). It also reduces OOM(Out Of Memory) issues. When image in a view goes out of screen it automatically recycles the bitmap, hence releasing the memory.

    0 讨论(0)
  • 2020-12-07 03:06

    The library link you provided had a sample within it. Your way of loading the GifImageView was different from the way written in the sample. The sample was downloading a gif from the internet.

    Here is a snippet from MainActivity of the sample:

    GifImageView gifImageView = (GifImageView) findViewById(R.id.gifImageView);
    
    new GifDataDownloader() {
        @Override
        protected void onPostExecute(final byte[] bytes) {
            gifImageView.setBytes(bytes);
            gifImageView.startAnimation();
            Log.d(TAG, "GIF width is " + gifImageView.getGifWidth());
            Log.d(TAG, "GIF height is " + gifImageView.getGifHeight());
        }
    }.execute("http://gifs.joelglovier.com/aha/aha.gif");
    

    Solution:

    I am not sure if you can load GifImageView from your assets with this library, but I prefer using ion library. It's really nice and simple. With that library, you can also stretch gif images as you like:

    https://github.com/koush/ion

    Simple Example:

    ImageView imageView = (ImageView) findViewById(R.id.imageView);
    Ion.with(imageView).load("http://gifs.joelglovier.com/aha/aha.gif");
    
    0 讨论(0)
  • 2020-12-07 03:07

    First, you need to put you gif in the assets folder. The assets folder is not created by default in Android Studio projects, so you should create a directory in src/main/assets and put your .gif files inside. The drawable resources folder should be reserved for drawables.

    You can use an input stream to load the bytes into your byte array, this is done inside your onCreate method:

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_play_activity);
        try {
            //animation.gif is just an example, use the name of your file
            //that is inside the assets folder.
    
            InputStream is = getAssets().open("animation.gif");
            bytes = new byte[is.available()];
            is.read(bytes);
            is.close();
    
            gifView = (GifImageView) findViewById(R.id.gifImageView);
            gifView = new GifImageView(this);
            gifView.setBytes(bytes);
            gifView.startAnimation();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    0 讨论(0)
提交回复
热议问题