Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slow load of local images with Picasso?

I've been developing Android apps for six years now, and using a simple "home-grown" image caching library for just as long. I recently started using a component that depends Picasso, and decided that it might be time to make the switch to a general library, rather than keep my old solution written many years ago.

Most of my images are local ones stored in the drawable folders, with modest dimensions (100-200 px a side).

However, I'm seeing a noticeable performance penalty when loading images with Picasso into the ImageViews of my layout. There is a visible "blip" between the layout being rendered and the bitmaps becoming visible (this blip disappears once the images are cached). With my HG library, which is basically just BitmapFactory.decodeResource with some cache coding around a sparse array of SoftReferences (this is old, as I said), loading for the same view is seamless and appears to be instantaneous.

Obviously, there are big differences in how I normally load the images and the asynch loading in Picasso, but is this really the expected behavior? This would seem to make Picasso ill-suited for the loading of local drawables into the UI, which I find rather surprising. I load images with the very simple:

Picasso.with(getActivity())
    .load(getPixId)
    .into(imageView);

Is there any way to tune this for better performance? What may I be overlooking?

like image 952
Michael A. Avatar asked Dec 11 '22 17:12

Michael A.


1 Answers

You can disable fade animation to improve load speed

Picasso.with(getActivity()).load(getPixId).noFade().into(imageView);

If you load a lot of image, try to use resize for better memory performance:

Picasso.with(getActivity()).load(getPixId).resize('widthImageView', 'heightImageView').noFade().into(imageView);

If you use a listview, you can stop load image onScroll for improve performance:

Picasso.with(getActivity()).load(getPixId).resize('widthImageView', 'heightImageView').noFade().tag('a group tag').into(imageView);

@Override public void onScrollStateChanged(AbsListView view, int scrollState) { final Picasso picasso = Picasso.with(context); if (scrollState == SCROLL_STATE_IDLE || scrollState == SCROLL_STATE_TOUCH_SCROLL) { picasso.resumeTag(context); } else { picasso.pauseTag(context); } }

For other solution you can see this post Picasso Github

If none of these solutions is for you, try a different library. Here you can find the most famous image libraries with their pros and cons Stackoverflow Answer

like image 128
Francesco Bonnì Avatar answered Feb 26 '23 23:02

Francesco Bonnì