Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have loaded remote image to ImageView using below code

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

Now I want to get the bitmap from imageview

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

but above line of code throws below exception:

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

How to resolve this?

like image 870
C.P. Avatar asked Nov 29 '22 23:11

C.P.


1 Answers

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);
        }
    });
like image 73
Vindhya Pratap Singh Avatar answered Dec 04 '22 12:12

Vindhya Pratap Singh