Android.graphics.drawable.TransitionDrawable cannot be added to com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable

I uploaded the remote image to ImageViewusing below code

Glide.with(context)
                .load(imageUrl)                   
                .placeholder(R.drawable.placeholderImage)
                .into(holder.wallPaperImageView);

Now I want to get a bitmap from imageview

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

but above the line of code below the exception:

java.lang.ClassCastException: android.graphics.drawable.TransitionDrawable cannot be dropped by com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable

How to resolve this?

+4
source share
3 answers

Use this instead:

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);
        }
    });
+16
source

If you want to 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 can get a bitmap:

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

Glide 3.8.0

".

0

If you are using 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 the warning "Unchecked method ..." add before method @SuppressWarnings ("unchecked")

0
source

All Articles