我正在使用库Picasso
下载图片。对于小图像,它工作得很好,但对于1.5Mb或更多图像,调用方法onBitmapFailed
并且不显示图像。我就是这样做的:
final int shortestSide = Math.min(image.getHeight(), image.getWidth());
final int longestSideView = Math.max(getAvailableHeight(), getAvailableWidth());
final float picassoScale = (float) longestSideView / (float) shortestSide;
final int widthWithoutExif;
final int heightWithoutExif;
final int exifRotation = Util.mod(image.getExifOrientation(), 360);
switch (exifRotation){
case 90:
case 270:
widthWithoutExif = image.getHeight();
heightWithoutExif = image.getWidth();
break;
default:
widthWithoutExif = image.getWidth();
heightWithoutExif = image.getHeight();
}
final RequestCreator requestCreator;
requestCreator = picasso.load(new File(cacheFilePath()));
requestCreator.resize((int) (widthWithoutExif * picassoScale), (int) (heightWithoutExif * picassoScale));
requestCreator.into(this);
有人知道我错过了什么吗?提前谢谢!
修改 这是堆栈跟踪:
java.io.IOException: Cannot reset
04-25 14:20:30.225 26278-26278/debug W/System.err: at com.squareup.picasso.MarkableInputStream.reset(MarkableInputStream.java:99)
04-25 14:20:30.225 26278-26278/debug W/System.err: at com.squareup.picasso.BitmapHunter.decodeStream(BitmapHunter.java:140)
04-25 14:20:30.225 26278-26278/debug W/System.err: at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:217)
04-25 14:20:30.225 26278-26278/debug W/System.err: at com.squareup.picasso.BitmapHunter.run(BitmapHunter.java:159)
04-25 14:20:30.225 26278-26278/debug W/System.err: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
04-25 14:20:30.225 26278-26278/debug W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
04-25 14:20:30.225 26278-26278/debug W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
04-25 14:20:30.225 26278-26278/debug W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
04-25 14:20:30.225 26278-26278/debug W/System.err: at java.lang.Thread.run(Thread.java:818)
04-25 14:20:30.225 26278-26278/debug W/System.err: at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:411)