Java tutorial
//package com.java2s; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Path; import android.graphics.Rect; public class Main { private final static float DP = 40; /** * Returns a rounded bitmap using specified bitmap image. * * @param scaleBitmapImage bitmap to make round image. * @return rounded bitmap */ public static Bitmap getRoundedShape(Bitmap scaleBitmapImage) { if (scaleBitmapImage == null) return null; int targetWidth = (int) DP; int targetHeight = (int) DP; Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(targetBitmap); Path path = new Path(); path.addCircle(((float) targetWidth - 1) / 2, ((float) targetHeight - 1) / 2, (Math.min(((float) targetWidth), ((float) targetHeight)) / 2), Path.Direction.CCW); Paint p = new Paint(); p.setAntiAlias(true); canvas.clipPath(path); canvas.drawBitmap(scaleBitmapImage, new Rect(0, 0, scaleBitmapImage.getWidth(), scaleBitmapImage.getHeight()), new Rect(0, 0, targetWidth, targetHeight), p); p.setARGB(255, 16, 18, 16); scaleBitmapImage.recycle(); return targetBitmap; } }