public static Bitmap cutCircleFromBitmap(String picturePath,int destCube){
  BitmapFactory.Options opts=new BitmapFactory.Options();
  opts.inDither=false;
  opts.inPurgeable=true;
  opts.inInputShareable=true;
  opts.inTempStorage=new byte[32 * 1024];
  Bitmap bitmapImg=BitmapFactory.decodeFile(picturePath,opts);
  int cube=destCube;
  if (bitmapImg == null)   return null;
  int smallest=Math.min(bitmapImg.getWidth(),bitmapImg.getHeight());
  Bitmap output=Bitmap.createBitmap(cube,cube,Config.ARGB_8888);
  Canvas canvas=new Canvas(output);
  final int color=0xff424242;
  final Paint paint=new Paint();
  int left=(int)((bitmapImg.getWidth() - smallest) * 0.5);
  int top=(int)((bitmapImg.getHeight() - smallest) * 0.5);
  final Rect rectSrc=new Rect(left,top,left + smallest,top + smallest);
  final Rect rectDest=new Rect(0,0,cube,cube);
  paint.setAntiAlias(true);
  canvas.drawARGB(0,0,0,0);
  paint.setColor(color);
  canvas.drawCircle(cube / 2,cube / 2,cube / 2,paint);
  paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
  canvas.drawBitmap(bitmapImg,rectSrc,rectDest,paint);
  bitmapImg.recycle();
  return output;
}

public static Bitmap cutCircleFromBitmap ( String picturePath , int destCube ) { BitmapFactory . Options opts = new BitmapFactory . Options ( ) ; opts . inDither = false ; opts . inPurgeable = true ; opts . inInputShareable = true ; opts . inTempStorage = new byte [ 32 * 1024 ] ; Bitmap bitmapImg = BitmapFactory . decodeFile ( picturePath , opts ) ; int cube = destCube ; if ( bitmapImg == null ) return null ; int smallest = Math . min ( bitmapImg . getWidth ( ) , bitmapImg . getHeight ( ) ) ; Bitmap output = Bitmap . createBitmap ( cube , cube , Config . ARGB_8888 ) ; Canvas canvas = new Canvas ( output ) ; final int color = 0xff424242 ; final Paint paint = new Paint ( ) ; int left = ( int ) ( ( bitmapImg . getWidth ( ) - smallest ) * 0.5 ) ; int top = ( int ) ( ( bitmapImg . getHeight ( ) - smallest ) * 0.5 ) ; final Rect rectSrc = new Rect ( left , top , left + smallest , top + smallest ) ; final Rect rectDest = new Rect ( 0 , 0 , cube , cube ) ; paint . setAntiAlias ( true ) ; canvas . drawARGB ( 0 , 0 , 0 , 0 ) ; paint . setColor ( color ) ; canvas . drawCircle ( cube / 2 , cube / 2 , cube / 2 , paint ) ; paint . setXfermode ( new PorterDuffXfermode ( Mode . SRC_IN ) ) ; canvas . drawBitmap ( bitmapImg , rectSrc , rectDest , paint ) ; bitmapImg . recycle ( ) ; return output ; }
cut a circle from a bitmap
