Slow load of local images with Picasso?

杀马特。学长 韩版系。学妹 提交于 2019-12-10 19:58:27

问题


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?


回答1:


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




回答2:


This is a late answer, but I was curious about the same question. Here's what I found from Jake himself. Hope this helps. LINK



来源:https://stackoverflow.com/questions/36988461/slow-load-of-local-images-with-picasso

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!