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

2020-09-27  本文已影响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
                }
            }

上一篇下一篇

猜你喜欢

热点阅读