使用Picasso加载自定义圆角的圆形图片
private void loadRoundImg(String url, ImageView img, final int corner,int width,int height) {
Picasso.with(context).load(url).error(R.drawable.shangcheng).resize(width,height).placeholder(R.drawable.shangcheng).transform(new Transformation() {
@Override
public Bitmap transform(Bitmap source) {
final Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
canvas.drawRoundRect(new RectF(0, 0, source.getWidth(), source.getHeight()), corner, corner, paint);
if (source != output) {
source.recycle();
}
return output;
}
@Override
public String key() {
return "circle";
}
}).into(img);
}