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.Color; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; public class Main { public static Bitmap circleBitmap(final Bitmap source) { int width = source.getWidth(); int height = source.getHeight(); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.WHITE); Bitmap clipped = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(clipped); final float radius = width > height ? height / 2 : width / 2; canvas.drawCircle(width / 2, height / 2, radius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); Bitmap rounded = Bitmap.createBitmap(width, height, Config.ARGB_8888); canvas = new Canvas(rounded); canvas.drawBitmap(source, 0, 0, null); canvas.drawBitmap(clipped, 0, 0, paint); source.recycle(); clipped.recycle(); return rounded; } }