kishidp
kishidp

Reputation: 1948

Glide resizing image via override does not resize the image

I'm using Glide to download and display image, however, when I tried to resize the image, it does not do so. I get random size (or perhaps its the actual size of the image).

Here's the code I used for loading via Glide

Glide.with(context)
     .load(file.getUrl())
     .asBitmap()
     .diskCacheStrategy(DiskCacheStrategy.ALL)
     .centerCrop()
     .transform(new CropCircleTransform(context))
     .override(dimen, dimen)
     .into(new SimpleTarget<Bitmap>() {
        @Override
        public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
          bitmap = resource;

          Log.info(resource.getWidth() + "x" + resource.getHeight());
        }
      });

the CropCircleTransform just render the bitmap circular and center crop. I tried removing it just to test if this method causes the problem but still the image doesn't resize to the dimension I specified.

Anything wrong with my code? or Am I misunderstanding the override method here?

EDIT:
Tried to remove the override, and it seems to have loaded the image in large size so it means there's actually a resizing that happens when using the override.

How come, it doesn't resize to the actual value I specified though?

EDIT:
As a sample, the value for dimen is 96, but the dimension displayed in the log for the images are like 97x97, 117x117, 154x154, etc.

Does that mean, the value for the override method is the baseline for resize and not the actual dimension to be used?

Upvotes: 10

Views: 12452

Answers (4)

I know this question is old, but I would like to post the correct answer :

 Glide.with(getApplicationContext())
                .asBitmap()
                .load(bitmap)
                .fitCenter()
                .into(new CustomTarget<Bitmap>(1000, 1000) {
                    @Override
                    public void onResourceReady(@NonNull @NotNull Bitmap resource, 
                    }

                    @Override
                    public void onLoadCleared(@Nullable @org.jetbrains.annotations.Nullable Drawable placeholder) {

                    }
                });

DON'T FORGET TO ADD .fitCenter()

Upvotes: 1

Abhi
Abhi

Reputation: 1063

ImageView iv = (ImageView) findViewById(R.id.left);

int width = 60;
int height = 60;

LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(width,height);
iv.setLayoutParams(parms);

Glide.with(context).load(path).centerCrop().crossFade().into(iv);

Upvotes: 4

Leito
Leito

Reputation: 114

I meet this error just now. My solution is set the imageview like this:

  1. set your imageview size in xml file.
  2. Glide.with(context).load(path).centerCrop().crossFade().into(imageview);

it works.

Upvotes: 2

Qian Sijianhao
Qian Sijianhao

Reputation: 564

I have just met the same situation.And I think this is a bug of Glide. Therefore,you have to resize the bitmap by yourself like this:

Glide.with(context).load(url).asBitmap().into(new SimpleTarget<Bitmap>{

    @Override
    public void onResourceReady(Bitmap resource,GlideAnimation<? extends Bitmap>(){
           // resize the bitmap
           bitmap = resize(width,height);
           imageView.setImageBitmap(bitmap);
    }

})

By the way,the scaleType of the ImageView such as 'fitXY','centerCrop','fitCenter' and so on, may also make an difference to the way that Glide resize the image.

Upvotes: 0

Related Questions