如下就是关键部分代码:如何才能实现圆角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 Just push it, work requires getting on the wheel, learning, and chewing the wheel source code.
Some thoughts: https://segmentfault.com/a/1190000004646559
How do you use this? Call this method first and then setBitmap to ImageView? If so, it may not be possible! Because centerCrop first enlarges the bitmap width and height to be greater than or equal to the width and height of ImageView, and then displays the middle part! In this way, if you zoom in and then crop, the original rounded corners may exceed the range of the control and not be displayed
Inherit imageview directly and draw in ondraw!
Has the poster solved it? I also encountered it