Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Path; import android.graphics.Rect; public class Main { public static Bitmap getCircleBitmap(Context context, Bitmap src, float radius) { radius = dipTopx(context, radius); int w = src.getWidth(); int h = src.getHeight(); int canvasW = Math.round(radius * 2); Bitmap bitmap = Bitmap.createBitmap(canvasW, canvasW, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Path path = new Path(); path.addCircle(radius, radius, radius, Path.Direction.CW); canvas.clipPath(path); Paint paint = new Paint(); paint.setAntiAlias(true); Rect srcRect = new Rect(0, 0, w, h); Rect dstRect = new Rect(0, 0, canvasW, canvasW); canvas.drawBitmap(src, srcRect, dstRect, paint); return bitmap; } public static float dipTopx(Context context, float dpValue) { final float scale = context.getResources().getDisplayMetrics().density; return (dpValue * scale + 0.5f); } }