使用Picasso加载本地图像的速度很慢吗? [英] Slow load of local images with Picasso?

查看:263
本文介绍了使用Picasso加载本地图像的速度很慢吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发Android应用程序已有六年了,并且使用一个简单的自家"图像缓存库已经有很长时间了.我最近开始使用依赖于毕加索的组件,并决定可能是时候切换到通用库了,而不是将我的旧解决方案写在很多年前.

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.

我的大多数图像是本地图像,存储在可绘制的文件夹中,尺寸适中(每侧100-200像素).

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

但是,将Picasso的图像加载到布局的ImageViews中时,我看到了明显的性能下降.在渲染的布局和位图变为可见之间存在一个可见的斑点"(一旦缓存了图像,该斑点便消失了).对于我的HG库,该库基本上只是BitmapFactory.decodeResource,并围绕着稀疏的SoftReferences数组(如我所说,这是 old )进行了一些缓存编码,对于同一视图的加载是无缝的,并且看起来像是瞬间.

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.

很明显,我在毕加索中正常加载图像和异步加载的方式存在很大差异,但这确实是预期的行为吗?这似乎使Picasso不适合将本地可绘制对象加载到UI中,这让我感到非常惊讶.我用非常简单的方式加载图像:

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?

推荐答案

您可以禁用淡入淡出动画以提高加载速度

You can disable fade animation to improve load speed

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

如果加载大量图像,请尝试使用resize以获得更好的内存性能:

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);

如果使用列表视图,则可以停止在onScroll上加载图片以提高性能:

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); } }

有关其他解决方案,您可以查看此帖子毕加索Github

For other solution you can see this post Picasso Github

如果这些解决方案都不适合您,请尝试使用其他库.在这里,您可以找到最有名的图像库,各有其优缺点 Stackoverflow答案

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

这篇关于使用Picasso加载本地图像的速度很慢吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆