Glide resizing image via override does not resize the image

房东的猫 提交于 2019-12-23 09:26:21

问题


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?


回答1:


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.




回答2:


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);



回答3:


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.



来源:https://stackoverflow.com/questions/34720436/glide-resizing-image-via-override-does-not-resize-the-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!