In Android, you can create bitmaps with anti-aliased rounded corners on the fly using the code snippet below. If anyone finds a more obvious way please feel free to ping me – I’d really love to know about it.
(This code may be used under the terms of Apache License – Version 2)
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), 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); final float roundPx = 12; paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
how to call this method and how to pass imageview to this method??
please help me…
LikeLike
thank you for your coding
i want to ask, how to cropping circle image manual in android?
I want to cropping the image according to the size that can change without changing the coding?
thank you before
LikeLike