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

Will Picasso's fit(), resize(), and transform() downsize images before downloading?

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

例如。

        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 的变换方法是否也会处理下载前图像的缩小?如果不是,最好的方法是什么,同时不为列表视图的 imageViews 设置固定比例?

我也和毕加索一起工作,我的回答是"no"。图像 总是先下载,然后 resized/transformed,然后显示

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

您可以对 Pollexor 使用 Thumbor service to crop and resize images before downloading. Square has a nice Java client for it - Pollexor. And special Picasso RequestTransformer。也就是说,您会将所有预处理提取到后端。