Package COM. kale. utils; import android. content. context; import android. graphics. bitmap; import android. graphics. bitmapfactory; import android. graphics. canvas; import android. graphics. paint; import android. graphics. porterduxfermode; import android. graphics. rect; import android. graphics. rectf; import android. graphics. bitmap. config; import android. graphics. porterduff. mode; import android. graphics. drawable. bitm Apdrawable; import android. graphics. drawable. drawable; public class circleimagemanager {/*** @ Param context object * @ Param resid image resource ID * @ return a circular drawable object */public static drawable getcircledrawable (context, int resid) {Bitmap bitmap = getcirclebitmap (context, resid); drawable = new bitmapdrawable (context. getresources (), bitmap); Return drawable;}/*** @ Param context * @ par Am resid * @ return: converted bitmap object */public static bitmap getcirclebitmap (context, int resid) {Bitmap bitmap = bitmapfactory. decoderesource (context. getresources (), resid); int width = bitmap. getwidth (); int Height = bitmap. getheight (); float roundpx; float left, top, right, bottom, dst_left, dst_top, dst_right, dst_bottom; If (width <= height) {roundpx = width/2; left = 0; Top = 0; Right = Width; bottom = width; Height = width; dst_left = 0; dst_top = 0; dst_right = width; dst_bottom = width;} else {roundpx = height/2; float clip = (width-height)/2; left = clip; Right = width-clip; Top = 0; bottom = height; width = height; dst_left = 0; dst_top = 0; dst_right = height; dst_bottom = height;} bitmap output = bitmap. createbitmap (width, height, config. argb_8888); canvas can Vas = new canvas (output); Final paint = new paint (); Final rect src = new rect (INT) left, (INT) Top, (INT) Right, (INT) Bottom); Final rect DST = new rect (INT) dst_left, (INT) dst_top, (INT) dst_right, (INT) dst_bottom ); final rectf = new rectf (DST); paint. setantialias (true); // you can specify a paint brush that does not have a sawtooth canvas. drawargb (0, 0, 0, 0); // fill the entire canvas. // you can draw circles, drawrounrect, and drawcircle canvas in either of the following ways. drawroundrec T (rectf, roundpx, roundpx, paint); // draw a rounded rectangle. The first parameter is the graphic display area, the second and third parameters are the radius of the horizontal and vertical rounded corners. // Canvas. drawcircle (roundpx, paint); paint. setxfermode (New porterduduxfermode (mode. src_in); // set the pattern when two images are intersecting, refer to the http://trylovecatch.iteye.com/blog/1189452 canvas. drawbitmap (bitmap, SRC, DST, paint); // In mode. in src_in mode, merge bitmap with the draw circle return output ;}}