之后如何在Android中加载低质量然后高质量的图像(就像WhatsApp的配置文件图像一样) [英] How to load low quality and then high quality image afterwards in android (just like WhatsApp profile image)
问题描述
我正在寻找一种我可以使用的设计模式,以便在android recyclerView中我可以快速加载低质量的图像,然后也可以致电获取高质量的图像 然后写出低质量的图像.我经常看到这样的情况:首先加载低质量的图像,然后加载高质量的图像.
I am searching for a design pattern i can use so that in android recyclerView i can load images quickly at low quality and then also make a call to for a high quality image will will write over the low quality image afterwards . I see it often where a low quality image is loaded first and then the high quality appears after.
但是在回收者视图的适配器中这是如何完成的.现在我正在使用毕加索进行缓存和图像加载.因此,例如,这里是指向低质量图像的链接:
But How is this done in the adapter for the recycler view. right now i am using picasso for cache and image loading. so for example here is a link to a low quality image:
http://example.com/lowQuality.jpg 以及同样高质量的 http://example.com/highQuality.jpg
所以在我的recyclerView适配器中,如果我在viewholder中这样做:
So in my adapter for the recyclerView if i do this in the viewholder:
public class SearchItemHolder extends RecyclerView.ViewHolder {
@BindView(R.id.iv)
ImageView iv;
@BindView(R.id.tv_description)
TextView tv_description;
public SearchItemHolder(View view) {
super(view);
ButterKnife.bind(this, view);
}
public void bindSearch(final SearchModel searchModel) {
String description = searchModel.getProductName();
final String imageLowQualityIDUrl = searchModel.getIdLowQualityImage();
final String imageHighQualityIDUrl = searchModel.getIdHighQualityImage();
tv_price.setText(price);
tv_description.setText(description);
Picasso.with(mContext).load(imageLowQualityIDUrl).into(iv);
//but how to switch it to high quality URL after its finished loading ?
}
}
因此要明确一点,我希望只要尚未加载高质量图像就可以首先显示低质量图像.
so to be clear, i want that the low quality image can show first as long as the high quality image is not loaded yet.
更新:我真正想要的是我在低质量图像快速加载的应用程序上看到的效果,然后在几秒钟后过渡到更高质量.如果还有其他工具或方法可以让我知道.我想要与whatsapp个人资料图片相同的效果(它如何从劣质逐渐淡化为高质量).
Update :What i really want is that effect i see on apps where the low quality image loads quickly then after a few seconds it transitions to a higher quality. If there is another tool or way to do this let me know. I want the same effect as the whatsapp profile image (how it fades in from poor quality to good quality).
推荐答案
我找到了 Glide 的解决方案. 您可以指定要作为缩略图加载的低分辨率图像.您只需要:
I found solution with Glide. You can specify low resolution image to be loaded as thumbnail. All you need is:
private void loadImageThumbnailRequest() {
// setup Glide request without the into() method
DrawableRequestBuilder<String> thumbnailRequest = Glide
.with( context )
.load( yourData.getLowQualityLink() );
// pass the request as a a parameter to the thumbnail request
Glide
.with( context )
.load( yourData.getHdUrl() )
.thumbnail( thumbnailRequest )
.into( imageView );
}
在来源此处
这篇关于之后如何在Android中加载低质量然后高质量的图像(就像WhatsApp的配置文件图像一样)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!