通过覆盖滑动调整图像的大小不会调整图像的大小
我正在使用 Glide 下载和显示图像,但是,当我尝试调整图像大小时,并没有这样做.我得到随机大小(或者可能是图像的实际大小).
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).
这是我用于通过Glide加载的代码
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());
}
});
CropCircleTransform
只是将位图渲染为圆形和中心裁剪.我尝试将其删除只是为了测试此方法是否会导致问题,但图像仍无法调整为我指定的尺寸.
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?
尝试删除替代项,并且似乎已加载了较大尺寸的图像,因此这意味着使用替代项时实际上会发生调整大小的情况.
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?
作为示例,dimen
的值为96,但是图像的日志中显示的尺寸为97x97、117x117、154x154等.
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?
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);