30

Why I can't resolve this method while using Glide also I can't resolve .diskstaretegy() :

Glide.with(getActivity())
                .load(chalet.profilePhoto)
                .asBitmap() <--- cannot resolve this
                .diskCacheStrategy(DiskCacheStrategy.ALL) <--- cannot reslove this
                .fitCenter()
                .placeholder(R.drawable.logo).dontAnimate().into(mImageView);

My gradle :-

compile 'com.github.bumptech.glide:glide:4.0.0'
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

7 Answers7

78

I found the way to fix it, you must add the asBitmap() right After with() and it will work just like old times.

PS: my Glide Version is 4.7.1

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Arash Afsharpour
  • 1,282
  • 11
  • 22
33

for the asBitmap you need to write it as follows:

Glide.with(getActivity()).asBitmap().load(chalet.profilePhoto).into(mImageView);
Sami Kanafani
  • 14,244
  • 6
  • 45
  • 41
14
// Put asBitmap() right after Glide.with(context)   ,,. 4.0+
// And for SubsamplingScaleImageView use SimpleTarget

  Glide.with(context)
                .asBitmap()
                .load(images[position])
                .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.AUTOMATIC))
                .into(new SimpleTarget<Bitmap>(width, height) {
                    @Override
                    public void onResourceReady(Bitmap bitmap, Transition<? super Bitmap> transition) {
                        subsampleImageView.setImage(ImageSource.bitmap(bitmap)); //For SubsampleImage
                    }
                });
Muhammad Jasim
  • 461
  • 5
  • 6
9

Call asBitmap() before load()

Glide.with(context)
 .asBitmap()
 .load(uri)
Pretasoc
  • 1,116
  • 12
  • 22
Amer Dajah
  • 111
  • 2
  • 2
9

If you getting an error, follow the steps below.

In Glide library move .asBitmap() before the .load()

---------------------OR-----------------------

Glide.with(context)
.setDefaultRequestOptions(requestOptions)
.asBitmap()
.load(url)
.into(holder.imageView);
MEGHA DOBARIYA
  • 1,622
  • 9
  • 7
  • I wonder why just copying the answer that gave Amer Dajah a couple of years before has given you almost the same upvotes. – Buddy Christ Jan 03 '22 at 10:44
7

https://bumptech.github.io/glide/doc/migrating.html#requestoptions

        Glide.with(getActivity()).asBitmap()
                .load(headerURl)
                .listener(new RequestListener<Bitmap>() {
                              @Override
                              public boolean onLoadFailed(@Nullable GlideException e, Object o, Target<Bitmap> target, boolean b) {
//                                  Toast.makeText(cxt,getResources().getString(R.string.unexpected_error_occurred_try_again),Toast.LENGTH_SHORT).show();
                                  return false;
                              }

                              @Override
                              public boolean onResourceReady(Bitmap bitmap, Object o, Target<Bitmap> target, DataSource dataSource, boolean b) {
                                  if (null == header)
                                      return false;

                                 //set image
                                  header.setImageBitmap(bitmap);

                                  //process bitmap
                                  Palette.from(bitmap).generate(
                                          new Palette.PaletteAsyncListener() {
                                              @SuppressWarnings("ResourceType")
                                              @Override
                                              public void onGenerated(Palette palette) {

                                                  int vibrantColor = palette
                                                          .getVibrantColor(R.color.primary_500);
                                                  int vibrantDarkColor = palette
                                                          .getDarkVibrantColor(R.color.primary_700);
                                                  collapsingToolbarLayout
                                                          .setContentScrimColor(vibrantColor);
                                                  collapsingToolbarLayout
                                                          .setStatusBarScrimColor(vibrantDarkColor);
                                              }
                                          });
                                  return false;
                              }
                          }
                ).submit();
Hitesh Sahu
  • 41,955
  • 17
  • 205
  • 154
5

You can set it another way like that

RequestOptions requestOptions = new RequestOptions();
requestOptions.placeholder(R.drawable.ic_placeholder);
requestOptions.diskCacheStrategy(DiskCacheStrategy.ALL)
requestOptions.error(R.drawable.ic_error);

Glide.with(context)
     .setDefaultRequestOptions(requestOptions)
     .asBitmap()
     .load(url).into(holder.imageView);
Mohit Suthar
  • 8,725
  • 10
  • 37
  • 67