毕加索没有加载特定图像 url

Picasso not loading a particular image url

我正在尝试使用毕加索加载此 http://assets.myntassets.com/v1/images/style/properties/Jockey-Men-Black-Innerwear-Vest-9926-0105_435418e1b17c4d0c5583dd33ba24193d_images.jpg url。在检查日志时显示 errored。但是当我尝试相同的 url by:

InputStream is = (InputStream) new URL(url).getContent();
Bitmap d = BitmapFactory.decodeStream(is);

图片正在加载。这很奇怪。无法弄清楚为什么会这样。

这里是 logcat:

D/Picasso (27123): Main        created      [R9] Request{http://assets.myntassets.com/v1/images/style/properties/Jockey-Men-Black-Innerwear-Vest-9926-0105_435418e1b17c4d0c5583dd33ba24193d_images.jpg resize(720,1184) centerInside}
D/Picasso (27123): Dispatcher  enqueued     [R9]+7ms 
D/Picasso (27123): Main        created      [R10] Request{http://assets.myntassets.com/v1/images/style/properties/Jockey-Men-Black-Innerwear-Vest-9926-0105_435418e1b17c4d0c5583dd33ba24193d_images.jpg resize(720,1184) centerInside}
D/Picasso (27123): Hunter      executing    [R9]+15ms 
D/Picasso (27123): Hunter      removed      [R9]+21ms from 
D/Picasso (27123): Dispatcher  canceled     [R9]+21ms 
D/Picasso (27123): Dispatcher  enqueued     [R10]+16ms 
D/Picasso (27123): Hunter      executing    [R10]+16ms 
D/Picasso (27123): Dispatcher  retrying     [R10]+538ms 
D/Picasso (27123): Hunter      executing    [R10]+542ms 
D/Picasso (27123): Dispatcher  retrying     [R10]+1057ms 
D/Picasso (27123): Hunter      executing    [R10]+1062ms 
D/Picasso (27123): Dispatcher  batched      [R10]+1586ms for error (will replay)

毕加索代码:

Picasso.with(context)
                    .load(url)
                    .resize(height,width)
                    .centerInside()
                    .into(imgView);

对于这种特殊情况,heightwidth 分别是 7201184

按照此示例,您将获得适合 MAX_WIDTH 和 MAX_HEIGHT 边界的图像(保持宽高比)

private static final int MAX_WIDTH = 1024;
private static final int MAX_HEIGHT = 768;

int size = (int) Math.ceil(Math.sqrt(MAX_WIDTH * MAX_HEIGHT));

// Loads given image
Picasso.with(imageView.getContext())
   .load(imagePath)
   .transform(new BitmapTransform(MAX_WIDTH, MAX_HEIGHT))
   .skipMemoryCache()
   .resize(size, size)
   .centerInside()
   .into(imageView);

这是我自定义的 BitmapTransform class:

import android.graphics.Bitmap;
import com.squareup.picasso.Transformation;

/** * 转换加载的图像以避免OutOfMemoryException */

public class BitmapTransform implements Transformation {

    int maxWidth;
    int maxHeight;

    public BitmapTransform(int maxWidth, int maxHeight) {
        this.maxWidth = maxWidth;
        this.maxHeight = maxHeight;
    }

 @Override
 public Bitmap transform(Bitmap source) {
    int targetWidth, targetHeight;
    double aspectRatio;

    if (source.getWidth() > source.getHeight()) {
        targetWidth = maxWidth;
        aspectRatio = (double) source.getHeight() / (double)     source.getWidth();
        targetHeight = (int) (targetWidth * aspectRatio);
    } else {
        targetHeight = maxHeight;
        aspectRatio = (double) source.getWidth() / (double)   source.getHeight();
        targetWidth = (int) (targetHeight * aspectRatio);
    }

    Bitmap result = Bitmap.createScaledBitmap(source, targetWidth,  targetHeight, false);
    if (result != source) {
        source.recycle();
    }
    return result;
}

@Override
public String key() {
    return maxWidth + "x" + maxHeight;
}

};

Here 是 link 在 github 上报告的此问题。