我有下一个问题:为了避免内存不足错误,我使用毕加索以这种方式将我的大图像加载到ImageViews中:
public static RequestCreator picasso(final Context context, final int resourceId) {
return Picasso.with(context)
.load(resourceId)
.fit()
.centerCrop()
.noFade();
}
在活动或片段中,我将图像加载到 ImageView 中
final ImageView backgroundImage = (ImageView) root.findViewById(R.id.background_image);
Util.picasso(getActivity(),R.drawable.background_soulmap)
.into(backgroundImage);
但是,我有两个问题:
- 图像加载有一些延迟(但我需要立即加载它)
在某些情况下,centerCrop() 不是我需要的。
如何实现像topCrop()或bottomCrop()这样的东西?我试过 https://github.com/cesards/CropImageView 图书馆,但是我在setFrame()方法中得到了NullPointerException(getDrawable()返回null),因为图像尚未加载。提前感谢!
图像加载有一些延迟(但我需要立即加载它)
您必须选择:(a) 内存效率延迟或 (b) 即时但可能的 OOM。我说,根据经验,我在Play商店中的应用程序在毕加索处理它时会有一些延迟。这就是它的工作原理。
在某些情况下,centerCrop() 不是我需要的。
然后,您应该将图像加载into()
Target
。目标将在 UI 线程中接收Drawable
,您可以从那里在 ImageView 中设置它(使用 setScaleType
)或作为您想要的背景。甚至可能使用InsetDrawable
来调整位置。