Here you can find the source of getRoundedCornerBitmap(Bitmap bitmap, int maxHeight, int pixels)
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int maxHeight, int pixels)
//package com.java2s; // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.graphics.RectF; public class Main { private static Context sApplicationContext; public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int maxHeight, int pixels) { if (bitmap == null) return bitmap; maxHeight = (int) (getApplicationContext().getResources() .getDisplayMetrics().density * maxHeight); float scale = bitmap.getHeight() * 1.0f / maxHeight; int newWidth = (int) (bitmap.getWidth() / scale); Bitmap output = Bitmap.createBitmap(newWidth, maxHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xffffffff; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());// w w w . ja v a2 s. c o m final Rect dstRect = new Rect(0, 0, newWidth, maxHeight); final RectF rectF = new RectF(dstRect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, (float) pixels, (float) pixels, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, dstRect, paint); return output; } public static Context getApplicationContext() { return sApplicationContext; } }