The following is an example of Improving the rounded corner image made by our predecessors.
Public static Bitmap roundCorners (final Bitmap source, final float radius ){
Int width = source. getWidth ();
Int height = source. getHeight ();
Paint paint = new Paint ();
Paint. setAntiAlias (true );
Paint. setColor (android. graphics. Color. WHITE );
Bitmap clipped = Bitmap. createBitmap (width, height, Bitmap. Config. ARGB_8888 );
Canvas canvas = new Canvas (clipped );
Canvas. drawRoundRect (new RectF (0, 0, width, height), radius, radius,
Paint );
Paint. setXfermode (new porterduxfermode (android. graphics. PorterDuff. Mode. SRC_IN ));
Canvas. drawBitmap (source, 0, 0, paint );
Source. recycle ();
Return clipped;
}
Example:
/**
* Round the corners of a {@ link Bitmap}
*
* @ Param source
* @ Param radius
* @ Return rounded corner bitmap
*/
Public static Bitmap roundCorners (final Bitmap source, final float radius ){
Int width = source. getWidth ();
Int height = source. getHeight ();
Paint paint = new Paint ();
Paint. setAntiAlias (true );
Paint. setColor (WHITE );
Bitmap clipped = Bitmap. createBitmap (width, height, ARGB_8888 );
Canvas canvas = new Canvas (clipped );
Canvas. drawRoundRect (new RectF (0, 0, width, height), radius, radius,
Paint );
Paint. setXfermode (new porterduxfermode (DST_IN ));
Bitmap rounded = Bitmap. createBitmap (width, height, ARGB_8888 );
Canvas = new Canvas (rounded );
Canvas. drawBitmap (source, 0, 0, null );
Canvas. drawBitmap (clipped, 0, 0, paint );
Source. recycle ();
Clipped. recycle ();
Return rounded;
}