这个问题已经被问到了,并且已经为我正在使用的毕加索版本做出了承诺:如何使用毕加索将循环位图发送到ImageView?我刚接触毕加索,我唯一用过的就是
Picasso.with(context).load(url).resize(w, h).into(imageview);
我已经找到了https://gist.github.com/julianshen/5829333,但我不确定如何以一种简单的方式将它与上面的代码行结合起来。
发布于 2014-09-30 11:39:58
之前稍微研究一下,因为有可用的答案。无论如何,请关注This Link并仔细阅读,以了解如何使用它。
试试这个:
import com.squareup.picasso.Transformation;
public class CircleTransform implements Transformation {
@Override
public Bitmap transform(Bitmap source) {
int size = Math.min(source.getWidth(), source.getHeight());
int x = (source.getWidth() - size) / 2;
int y = (source.getHeight() - size) / 2;
Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
if (squaredBitmap != source) {
source.recycle();
}
Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
BitmapShader shader = new BitmapShader(squaredBitmap,
Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
paint.setShader(shader);
paint.setAntiAlias(true);
float r = size / 2f;
canvas.drawCircle(r, r, r, paint);
squaredBitmap.recycle();
return bitmap;
}
@Override
public String key() {
return "circle";
}
}
然后像这样简单地应用它:
Picasso.with(activity).load(mayorShipImageLink).transform(new CircleTransform()).into(ImageView);
发布于 2018-10-31 16:39:55
毕加索有一个转换库。
只需添加gradle依赖项
implementation 'jp.wasabeef:picasso-transformations:2.2.1'
最终使用它
Picasso.with(context)
.load(url)
.resize(w, h)
.transform(new CropCircleTransformation())
.into(imageview);
发布于 2015-10-10 06:25:12
我发现的另一个替代方案是这个guys库。它可以独立工作,也可以与毕加索一起工作。我选择了毕加索的路线,如下所示:
https://github.com/vinc3m1/RoundedImageView
Transformation transformation = new RoundedTransformationBuilder()
.borderColor(Color.BLACK)
.borderWidthDp(3)
.cornerRadiusDp(30)
.oval(false)
.build();
Picasso.with(context)
.load(url)
.fit()
.transform(transformation)
.into(imageView);
对我很管用!
https://stackoverflow.com/questions/26112150
复制相似问题