public Bitmap scaleCenterCrop(Bitmap source,int destWidth,int destHeight){
  int sourceWidth=source.getWidth();
  int sourceHeight=source.getHeight();
  float xScale=(float)destWidth / sourceWidth;
  float yScale=(float)destHeight / sourceHeight;
  float scale=Math.max(xScale,yScale);
  float scaledWidth=scale * sourceWidth;
  float scaledHeight=scale * sourceHeight;
  float left=(destWidth - scaledWidth) / 2;
  float top=(destHeight - scaledHeight) / 2;
  RectF destRect=new RectF(left,top,left + scaledWidth,top + scaledHeight);
  Bitmap dest=Bitmap.createBitmap(destWidth,destHeight,source.getConfig());
  Canvas canvas=new Canvas(dest);
  canvas.drawBitmap(source,null,destRect,null);
  return dest;
}

public Bitmap scaleCenterCrop ( Bitmap source , int destWidth , int destHeight ) { int sourceWidth = source . getWidth ( ) ; int sourceHeight = source . getHeight ( ) ; float xScale = ( float ) destWidth / sourceWidth ; float yScale = ( float ) destHeight / sourceHeight ; float scale = Math . max ( xScale , yScale ) ; float scaledWidth = scale * sourceWidth ; float scaledHeight = scale * sourceHeight ; float left = ( destWidth - scaledWidth ) / 2 ; float top = ( destHeight - scaledHeight ) / 2 ; RectF destRect = new RectF ( left , top , left + scaledWidth , top + scaledHeight ) ; Bitmap dest = Bitmap . createBitmap ( destWidth , destHeight , source . getConfig ( ) ) ; Canvas canvas = new Canvas ( dest ) ; canvas . drawBitmap ( source , null , destRect , null ) ; return dest ; }
scale and center crop a bitmap to fit new dimensions
