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;
}
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;
}
Good work! I have recently read an article on Data Analytics and Data Mining.
ReplyDeleteI hope you would like it.