I have a list view where I load image with person name. There are around 538 items in the list view. I get the images of persons from a url. Currently I am doing the following:-
Picasso.with(getContext()).load(url).resize(70,70).onlyScaleDown().into(im1);
The images present in the URL are very large in size and loading of some images takes a lot of time and it eats up my memory also while loading. Can some one please help me in loading the images efficiently and fastly.
Example image for one person can be found in the following URL:-
https://theunitedstates.io/images/congress/original/D000626.jpg
Picasso does not support GIF animation on a simple image view. Glide loads images faster than Picasso.
Glide is faster and the results of Picasso and Coil are similar. But what about when we are loading from the cache. As you can see in the images below we have the best times for Glide in most of the cases.
Android App Development for Beginners Picasso is image processing library and developed by Square Inc.
You can use onlyScaleDown()
to resize
Picasso
.with(context)
.load(imageUrl)
.resize(6000, 2000)
.onlyScaleDown() // the image will only be resized if it's bigger than 6000x2000 pixels.
.into(imageViewResizeScaleDown);
Or you can use fit()
Picasso
.with(context)
.load(imageUrl)
.fit()
// call .centerInside() or .centerCrop() to avoid a stretched image
.into(imageViewFit);
fit() is measuring the dimensions of the target ImageView and internally uses resize() to reduce the image size to the dimensions of the ImageView. There are two things to know about fit(). First, calling fit() can delay the image request since Picasso will need to wait until the size of the ImageView can be measured. Second, you only can use fit() with an ImageView as the target (we'll look at other targets later).
The advantage is that the image is at the lowest possible resolution, without affecting its quality. A lower resolution means less data to be hold in the cache. This can significantly reduce the impact of images in the memory footprint of your app. In summary, if you prefer a lower memory impact over a little faster loading times, fit() is a great tool.
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