Android Picasso 设置图拍呢

释放双眼,带上耳机,听听看~!
调用Picasso 很简单
Picasso.with(mContext).load(mDatas.get(position).getHeadImageUrl()).transform(new CircleTransform()).into(holder.mEvaluateUserpic);
图片裁剪类 CircleTransform()
// 声明一个Picasso 裁剪图片的类,设置为圆形头像。
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,
BitmapShader.TileMode.CLAMP, BitmapShader.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";
}
}

人已赞赏
Android文章

Android开发毫秒数转日期

2020-3-28 7:32:15

Android文章

Android开发java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class andro

2020-3-28 8:46:54

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索