Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 692
kishidp Avatar asked Jan 11 '16 11:01

kishidp


People also ask

How do you change the size of a picture on Glide?

With Glide, if the image should not be automatically fitted to the ImageView , call override(horizontalSize, verticalSize) . This will resize the image before displaying it in the ImageView .

How do you compress images in Glide?

centerCrop() is a cropping technique that scales the image so that it fills the requested bounds of the ImageView and then crops the extra. The ImageView will be filled completely, but the entire image might not be displayed. RequestOptions myOptions = new RequestOptions() . centerCrop(); Glide.

Where does glide save images?

The image picker is pretty basic. Images are stored in Firebase and limited to 10mb files.


2 Answers

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);
like image 160
Abhi Avatar answered Oct 16 '22 17:10

Abhi


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.

like image 35
Leito Avatar answered Oct 16 '22 17:10

Leito