Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PorterDuff.Mode; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.graphics.RectF; public class Main { public static Bitmap getRoundCornerBitmap(Bitmap bitmap, int radius) { // Canvas canvas = new Canvas(bitmap); // Rect r =new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); // RectF rect = new RectF(r); // Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); // paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OVER)); // canvas.drawRoundRect(rect, 3f, 3f, paint); // // canvas.drawBitmap(bitmap, 0, 0, paint); // return 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 = radius; paint.setAntiAlias(true); // canvas.drawARGB(0, 0, 0, 0); // paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, new Paint(Paint.ANTI_ALIAS_FLAG)); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; } }