1,单个图片
public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, (float) pixels, (float) pixels, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
2,一系列图片,继承imageview
参考博客:Android BitmapShader 实战 实现圆形、圆角图片
开源控件:SelectableRoundedImageView——Android图片圆角类库
as中引用:compile 'com.joooonho:selectableroundedimageview:1.0.1'
compile 'com.makeramen:roundedimageview:2.1.2'