如下就是关键部分代码:如何才能实现圆角ImageView以centerCrop模式显示?
public static Bitmap getBitmap(int width, int height) {
//int shadow = (int)(UIUtils.dip2px(2));
Bitmap output = Bitmap.createBitmap(width,
height, 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, width, height);
final RectF rectF = new RectF(rect);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, getRoundPx(), getRoundPx(), paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(output, rect, rect, paint);
return output;
}
https://github.com/hdodenhof/CircleImageView 推着走吧,工作需要上轮子,学习,啃轮子源码。