This article describes the method of Android development to realize rounded corners of pictures. Share it for your reference, as follows:
Bitmap myCoolBitmap = ... ; // <-- Your bitmap you want rounded int w = (), h = (); Bitmap rounder = (w,h,.ARGB_8888); Canvas canvas = new Canvas(rounder); Paint xferPaint = new Paint(Paint.ANTI_ALIAS_FLAG); (); (new RectF(0,0,w,h), 20.0f, 20.0f, xferPaint); (new PorterDuffXfermode(.DST_IN)); (myCoolBitmap, 0,0, null); (rounder, 0, 0, xferPaint);
or:
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) { Bitmap output = ((), (), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, (), ()); final RectF rectF = new RectF(rect); final float roundPx = 12; (true); (0, 0, 0, 0); (color); (rectF, roundPx, roundPx, paint); (new PorterDuffXfermode(Mode.SRC_IN)); (bitmap, rect, rect, paint); return output; }
For more information about Android related content, please check out the topic of this site:Summary of Android graphics and image processing skills》、《Android development introduction and advanced tutorial》、《Android debugging skills and solutions to common problems》、《Android multimedia operation skills summary (audio, video, recording, etc.)》、《Summary of the usage of basic Android components》、《Android View View Tips Summary》、《Android layout layout tips summary"and"Android control usage summary》
I hope this article will be helpful to everyone's Android programming design.