Tuesday 29 January 2013

Android conversion of Bitmap to Rounded corner Bitmap.

In order to convert bitmap into rounded corner Bitmap, Just call this given method . This will return rounded corner bitmap.
getRoundedCornerBitmap() Method having two parameter
1) Bitmap
2) int pixel(Radius of corner edge say 10)


/**
* Convert bitmap into rounded corner Bitmap
* @param value
*  Bitmap value to convert
  * @param value
  *  int value in terms of radius to make corner edge
* @return A Rounded corner Bitmap.
*/


public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels)
throws NullPointerException {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = Color.parseColor("#000000");
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = pixels;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}

1 comment: