Here you can find the source of scaleClipBitmapByCircle(Bitmap src, int nRadius, float fStrokeWidth)
public static Bitmap scaleClipBitmapByCircle(Bitmap src, int nRadius, float fStrokeWidth)
//package com.java2s; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; public class Main { public static Bitmap scaleClipBitmapByCircle(Bitmap src, int nRadius, float fStrokeWidth) { if (null != src) { Bitmap maskMap = Bitmap.createBitmap(nRadius << 1, nRadius << 1, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(maskMap); canvas.drawARGB(0, 0, 0, 0); Paint ptDrawCircle = new Paint(); ptDrawCircle.setColor(Color.BLACK); ptDrawCircle.setStyle(Style.FILL); canvas.drawCircle(nRadius, nRadius, nRadius, ptDrawCircle); Paint paint = new Paint(); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); Rect rcSrc = new Rect(); rcSrc.set(0, 0, src.getWidth(), src.getHeight()); Rect rcDst = new Rect(); rcDst.set(0, 0, maskMap.getWidth(), maskMap.getHeight()); canvas.drawBitmap(src, rcSrc, rcDst, paint); ptDrawCircle.setStyle(Style.STROKE); ptDrawCircle.setStrokeWidth(fStrokeWidth); ptDrawCircle.setColor(Color.WHITE); ptDrawCircle.setAntiAlias(true); canvas.drawCircle(nRadius, nRadius, nRadius - fStrokeWidth / 2, ptDrawCircle);// ww w . j ava 2 s. c o m return maskMap; } return null; } }