美文网首页
Glide 加载Gif 图,正常加载不出来,将GIF转流加载

Glide 加载Gif 图,正常加载不出来,将GIF转流加载

作者: 勤劳的蚂蚁 | 来源:发表于2020-09-27 15:17 被阅读0次

    有时候不需要添加 .asGif () 也可以加载gif 动画,加上.asGif () 效果可能会充满屏幕

                Resources res = getResources();
                int id= R.mipmap.twtx01;
    
                InputStream is = null;
    
                try {
                    final TypedValue value = new TypedValue();
                    is = res.openRawResource(id, value);
                    ByteArrayOutputStream outStream = new ByteArrayOutputStream ();
                    byte[] data = new byte[4048];
                    int count = -1;
                    while((count = is.read(data,0,4048)) != -1)
                        outStream.write(data, 0, count);
                    Glide.with (iv_mrzb.getContext ())
                            .load (outStream.toByteArray ())
                            .asGif ()
                            .placeholder (R.mipmap.sign_after_001) //
    //                .diskCacheStrategy(DiskCacheStrategy.NONE)
                            .error (R.mipmap.sign_after_001)
                            .into (iv_mrzb);
    
                } catch (Exception e) {
                /*  do nothing.
                    If the exception happened on open, bm will be null.
                    If it happened on close, bm is still valid.
                */
                } finally {
                    try {
                        if (is != null) is.close();
                    } catch (IOException e) {
                        // Ignore
                    }
                }
    
    

    相关文章

      网友评论

          本文标题:Glide 加载Gif 图,正常加载不出来,将GIF转流加载

          本文链接:https://www.haomeiwen.com/subject/xwcluktx.html