Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Big images loading with Picasso

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

like image 471
Zxxxxx Avatar asked Nov 17 '16 21:11

Zxxxxx


People also ask

Can Picasso load GIF?

Picasso does not support GIF animation on a simple image view. Glide loads images faster than Picasso.

Which is better glide or 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.

What is Picasso library in Android?

Android App Development for Beginners Picasso is image processing library and developed by Square Inc.


1 Answers

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.

like image 67
Luiz Fernando Salvaterra Avatar answered Sep 29 '22 03:09

Luiz Fernando Salvaterra