如下就是关键部分代码:如何才能实现圆角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 推着走吧,工作需要上轮子,学习,啃轮子源码。
一点心得:https://segmentfault.com/a/1190000004646559
你这是怎么用的?先调用这个方法,再setBitmap到ImageView?如果是这样,是有可能不能实现的!因为centerCrop是先给bitmap宽高放大到大于等于ImageView的宽高,然后显示中间的部分!这样你放大以后再裁减就有可能原来的圆角部分超过控件的范围而得不到显示
直接继承imageview在ondraw里画吧!
楼主解决了吗,我也遇到了