private Bitmap scaleBitmap(Bitmap bitmap,int maxWidth,int maxHeight){
  if (bitmap == null) {
    return null;
  }
  float scaleX=1.0f;
  float scaleY=1.0f;
  if (bitmap.getWidth() > maxWidth) {
    scaleX=maxWidth / (float)bitmap.getWidth();
  }
  if (bitmap.getHeight() > maxHeight) {
    scaleY=maxHeight / (float)bitmap.getHeight();
  }
  float scale=Math.min(scaleX,scaleY);
  int width=(int)(bitmap.getWidth() * scale);
  int height=(int)(bitmap.getHeight() * scale);
  return Bitmap.createScaledBitmap(bitmap,width,height,false);
}

private Bitmap scaleBitmap ( Bitmap bitmap , int maxWidth , int maxHeight ) { if ( bitmap == null ) { return null ; } float scaleX = 1.0f ; float scaleY = 1.0f ; if ( bitmap . getWidth ( ) > maxWidth ) { scaleX = maxWidth / ( float ) bitmap . getWidth ( ) ; } if ( bitmap . getHeight ( ) > maxHeight ) { scaleY = maxHeight / ( float ) bitmap . getHeight ( ) ; } float scale = Math . min ( scaleX , scaleY ) ; int width = ( int ) ( bitmap . getWidth ( ) * scale ) ; int height = ( int ) ( bitmap . getHeight ( ) * scale ) ; return Bitmap . createScaledBitmap ( bitmap , width , height , false ) ; }
scale the specified bitmap to the desired with and height while preserving aspect ratio .
