问题描述
您好Picasso + Android用户,
Hello Picasso+Android Users,
我使用了以下版本的毕加索及其下面的 Transformation 代码段:
I have used following version of Picasso and its working with following Transformation snippet:
,并根据 Transform 为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()
,它在新的以下版本中可用:
Now i want to use .priority()
which is available in new following version:
但这给了我 Transformation 的错误,例如:
But it is giving me error of Transformation like:
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)
仅在新版本的 picasso 中出现此错误.
I am getting this error in new version of picasso only.
有什么要解决的解决方案吗?
Is there any solution to solve?
您的帮助将不胜感激.
推荐答案
我认为您应该改用以下内容:
I think you should use the following instead:
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 = ...
}
}
关于异常,实际上,版本2.3.2也已获得它,但是,它具有处理异常的不同方法.您可以看到以下2个屏幕截图:
About the exception, actually, ver 2.3.2 also got it, however, it has different way to process the exception. You can see 2 following screenshots:
版本2.3.2:
版本2.5.2:
这篇关于毕加索新版本2.5.2:不适用于转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!