How do Bitmap images round edges at the required radius?

At once I will say that libraries like CircularImageView are not needed, because it is the Bitmap change that is of particular interest, not the View.

1 answer 1

Thanks to the commentators, the answer is received.

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int radius) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap .getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); 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); canvas.drawRoundRect(rectF, radius, radius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }