Hello Picasso + Android用户,
我使用了以下版本的 Picasso ,并使用了以下转化代码段:
compile' com.squareup.picasso:picasso:2.3.2'
并为Image Transformation
public class ImageTransformation implements Transformation {
int maxWidth;
int maxHeight;
public ImageTransformation(ImageView imageView) {
this.maxWidth = imageView.getWidth();
this.maxHeight = imageView.getHeight();
}
@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;
}
}
和使用类似:
Picasso.with(mContext).load(photo.getLink())
.error(R.drawable.ic_place_holder_circle)
.placeholder(R.drawable.ic_place_holder_circle)
.transform(new ImageTransformation(holder.albumPhotoDetailSubMainImage))
.into(holder.albumPhotoDetailSubMainImage);
现在我想使用以下新版本中提供的.priority()
:
compile' com.squareup.picasso:picasso:2.5.2'
但它给了我转换的错误,如:
java.lang.IllegalArgumentException: width and height must be > 0
at android.graphics.Bitmap.createBitmap(Bitmap.java:815)
at android.graphics.Bitmap.createBitmap(Bitmap.java:794)
at android.graphics.Bitmap.createBitmap(Bitmap.java:725)
at com.squareup.picasso.BitmapHunter.transformResult(BitmapHunter.java:558)
at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:232)
at com.squareup.picasso.BitmapHunter.run(BitmapHunter.java:159)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:411)
我仅在full code的新版本中收到此错误。
有什么解决方案可以解决吗?
我们将不胜感激。
答案 0 :(得分:0)
我认为您应该使用以下内容:
public ImageTransformation(ImageView imageView) {
this.maxWidth = imageView.getLayoutParams().width; //imageView.getWidth();
this.maxHeight = imageView.getLayoutParams().height; //imageView.getHeight();
// check
if (this.maxWidth <= 0) {
this.maxWidth = ...
}
if (this.maxHeight <= 0) {
this.maxHeight = ...
}
}
关于异常,实际上,ver 2.3.2也得到了它,但是,它有不同的处理异常的方法。您可以看到以下2个屏幕截图:
Ver 2.3.2:
Ver 2.5.2: