gpt4 book ai didi

java - 从 URL 部分加载图像,就像在 WhatsApp 中实现的一样

转载 作者:塔克拉玛干 更新时间:2023-11-02 18:54:45 25 4
gpt4 key购买 nike

WhatsApp 开发人员最近改进了图像加载,立即加载图像的某些部分(获取图像的尺寸和图像的一些像素),然后在加载整个图像后,用完整图像替换占位符:

enter image description here

我的问题是,他们是如何实现的?他们是否通过读取标题(元数据)来读取图像的尺寸?图片内容如何?或者他们在服务器端有两个版本的图像,一个较小的低质量图像首先加载,另一个较大的图像是完整图像?请注意,如果是第二种方法,那么一旦从发件人那里收到图像,他们仍然需要在服务器端提取图像的较小版本。还有其他方法吗?

最佳答案

colored placeholder 解决方案还有另一种选择,即显示缩略图(可能只有 100 X 100 像素)作为占位符,直到加载真实图像,这比只有彩色占位符更酷:)。

我在 Zingoo 中做到了并做了一个blog post关于它。使用 Picasso ,你可以这样做:

Transformation blurTransformation = new Transformation() {
@Override
public Bitmap transform(Bitmap source) {
Bitmap blurred = Blur.fastblur(LiveImageView.this.context, source, 10);
source.recycle();
return blurred;
}

@Override
public String key() {
return "blur()";
}
};

Picasso.with(context)
.load(thumbUrl) // thumbnail url goes here
.placeholder(R.drawable.placeholder)
.resize(imageViewWidth, imageViewHeight)
.transform(blurTransformation)
.into(imageView, new Callback() {
@Override
public void onSuccess() {
Picasso.with(context)
.load(url) // image url goes here
.resize(imageViewWidth, imageViewHeight)
.placeholder(imageView.getDrawable())
.into(imageView);
}

@Override
public void onError() {
}
});

帖子本身有更多详细信息,包括 Blur 类。

关于java - 从 URL 部分加载图像,就像在 WhatsApp 中实现的一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19882110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com