gpt4 book ai didi

android - Picasso 的 fit()、resize() 和 transform() 会在下载前缩小图像尺寸吗?

转载 作者:行者123 更新时间:2023-11-29 15:13:20 28 4
gpt4 key购买 nike

我知道通过使用 fit() 和 resize(),图像会在下载前缩小。然而,当使用 listView 并且图像的比例发生变化时,我需要将 imageView 的 layout_width 和 layout_height 设置为 wrap_content,然后在将图像放入 imageView 之前使用 transform() 确定图像的比例。

例如。

        Picasso.with(mContext).load(region.getImage_url()).transform(new Transformation() {
@Override
public Bitmap transform(Bitmap source) {
int targetWidth = getContext().getSharedPreferences(Constants.PREFERENCES, Context.MODE_PRIVATE).getInt(Constants.DEVICE_WIDTH, 0);
double aspectRatio = (double) source.getHeight() / (double) source.getWidth();
int targetHeight = (int) (holder.targetWidth * aspectRatio);
Bitmap result = Bitmap.createScaledBitmap(source, targetWidth, targetHeight, false);
if (result != source) {
// Same bitmap is returned if sizes are the same
source.recycle();
}
return result;
}

@Override
public String key() {
return "transformation" + " desiredWidth";
}
}).into(holder.imageView);

所以我的问题是 Picasso 的变换方法是否也会在下载之前处理图像的缩小?如果不是,最好的方法是什么,同时不为 ListView 的 imageViews 设置固定比例?

最佳答案

我也和 picasso 一起工作,我的回答是“不”。图片总是先下载,然后调整大小/转换,然后显示

下载缩小尺寸(显示在 ListView 中)的唯一方法是提供较小尺寸或缩略图版本的图像。如果您将图像托管在自己的服务器中,则很容易实现。

关于android - Picasso 的 fit()、resize() 和 transform() 会在下载前缩小图像尺寸吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27936647/

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