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?
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 .
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.
The image picker is pretty basic. Images are stored in Firebase and limited to 10mb files.
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);
I meet this error just now. My solution is set the imageview like this:
Glide.with(context).load(path).centerCrop().crossFade().into(imageview);
it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With