android.graphics.drawable.TransitionDrawable cannot be cast to com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable

ⅰ亾dé卋堺 提交于 2019-12-05 14:31:16
Vindhya Pratap Singh

Use this instead of that:

Bitmap bmp = ((GlideBitmapDrawable)holder.wallPaperImageView.getDrawable().getCurrent()).getBitmap();

or

Glide
    .with(this)
    .load(a.getAlbum_artwork())
    .asBitmap()
    .into(new SimpleTarget<Bitmap>(300,300) {
        @Override
        public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
            setBackgroundImage(resource);
        }
    });

If you wanna get away from resizing use this (talisman):

Glide.with(context)
                .load(imageUrl)       
                .asBitmap() //needed for obtaining bitmap            
                .placeholder(R.drawable.placeholderImage)
                .into(holder.wallPaperImageView);

Then you are free to get bitmap:

Bitmap bitmap = ((BitmapDrawable)holder.wallPaperImageView.getDrawable()).getBitmap();

It's working with Glide 3.8.0

Good luck,'.

If you use Glide v4

 private BaseTarget target = new BaseTarget<BitmapDrawable>() {
        @Override
        public void onResourceReady(BitmapDrawable bitmap, Transition<? super BitmapDrawable> transition) {
            //here is your integration by ex: activityReference.get().toolbar.setNavigationIcon(bitmap);
        }

        @Override
        public void getSize(SizeReadyCallback cb) {
            cb.onSizeReady(100, 100);
        }

        @Override
        public void removeCallback(SizeReadyCallback cb) {}
    };

and after

Glide.with(activityReference.get().getApplicationContext())
                            .load(url of image)
                            .apply(new RequestOptions()
                                    .placeholder(R.mipmap.img)
                                    .error(R.mipmap.img)
                                    .diskCacheStrategy(DiskCacheStrategy.ALL))
                            .apply(circleCropTransform())
                            .into(target);

if you have warning 'Unchecked method ...' add before method @SuppressWarnings("unchecked")

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!