装载毕加索的大图像

时间:2016-11-17 21:06:01

标签: android image android-asynctask android-imageview picasso

我有一个列表视图,我在其中加载带有人名的图像。列表视图中有大约538个项目。我从网址获取人物的图像。目前我正在做以下事情: -

Picasso.with(getContext()).load(url).resize(70,70).onlyScaleDown().into(im1);

URL中存在的图像非常大,一些图像的加载需要花费大量时间,并且在加载时也会占用我的内存。有人可以帮我快速有效地加载图像。

可以在以下URL中找到一个人的示例图像: -

https://theunitedstates.io/images/congress/original/D000626.jpg

2 个答案:

答案 0 :(得分:10)

您可以使用onlyScaleDown()调整大小

Picasso  
    .with(context)
    .load(imageUrl)
    .resize(6000, 2000)
    .onlyScaleDown() // the image will only be resized if it's bigger than 6000x2000 pixels.
    .into(imageViewResizeScaleDown);

或者您可以使用fit()

Picasso  
    .with(context)
    .load(imageUrl)
    .fit()
    // call .centerInside() or .centerCrop() to avoid a stretched image
    .into(imageViewFit);

fit()测量目标ImageView的尺寸,并在内部使用resize()将图像大小缩小为ImageView的尺寸。 fit()有两点需要了解。首先,调用fit()可以延迟图像请求,因为Picasso需要等到可以测量ImageView的大小。其次,你只能使用fit()和ImageView作为目标(我们稍后会看到其他目标)。

优点是图像处于尽可能低的分辨率,而不会影响其质量。较低的分辨率意味着要在缓存中保留较少的数据。这可以显着降低图像在应用内存占用中的影响。总之,如果您希望在更快的加载时间内降低内存影响,fit()是一个很好的工具。

答案 1 :(得分:0)

根据毕加索的新版本

Picasso.get().load(galleryList[position].mediaUrl).fit()
                .placeholder(R.mipmap.ic_launcher).into(holder?.ivImags)
相关问题