Android circular Imageview
The circular imageview custom control found on the Internet :'
Package com. wangll. widget; import android. content. context; import android. graphics. bitmap; import android. graphics. bitmap. config; import android. graphics. canvas; import android. graphics. paint; import android. graphics. paintFlagsDrawFilter; import android. graphics. porterDuff. mode; import android. graphics. porterduxfermode; import android. graphics. rect; import android. graphics. rectF; import android. graphics. dra Wable. bitmapDrawable; import android. graphics. drawable. drawable; import android. util. attributeSet; import android. widget. imageView;/*** circular Imageview ** @ author wangll **/public class CircularImage extends ImageView {public CircularImage (Context context) {super (context );} public CircularImage (Context context, AttributeSet attrs) {super (context, attrs);} public CircularImage (Context context, TributeSet attrs, int defStyle) {super (context, attrs, defStyle) ;}@ Override protected void onDraw (Canvas canvas) {Drawable drawable = getDrawable (); if (null! = Drawable) {Bitmap bitmap = (BitmapDrawable) drawable). getBitmap (); if (null! = Bitmap) {Bitmap B = toRoundCorner (bitmap); Paint paint = new Paint (); paint. setAntiAlias (true); paint. setFilterBitmap (true); canvas. drawBitmap (B, new Rect (0, 0, B. getWidth (), B. getHeight (), new Rect (0, 0, this. getWidth (), this. getHeight (), paint) ;}} else {super. onDraw (canvas) ;}} private Bitmap toRoundCorner (Bitmap bitmap) {Bitmap outBitmap = Bitmap. createBitmap (bitmap. getWidth (), bitmap. GetHeight (), Config. ARGB_8888); final Paint paint = new Paint (); paint. setAntiAlias (true); paint. setFilterBitmap (true); paint. setColor (0 xffffffff); final Rect rect = new Rect (0, 0, bitmap. getWidth (), bitmap. getHeight (); final RectF rectF = new RectF (rect); final float roundPX = bitmap. getWidth ()/2 <bitmap. getHeight ()/2? Bitmap. getWidth (): bitmap. getHeight (); Canvas canvas = new Canvas (outBitmap); canvas. drawARGB (0, 0, 0, 0); canvas. setDrawFilter (new PaintFlagsDrawFilter (0, Paint. ANTI_ALIAS_FLAG | Paint. FILTER_BITMAP_FLAG); canvas. drawRoundRect (rectF, roundPX, roundPX, paint); paint. setXfermode (new porterduduxfermode (Mode. SRC_IN); canvas. drawBitmap (bitmap, rect, rect, paint); return outBitmap ;}}
Directly use
Image effects: