private Bitmap compress(String imagePath,int width,int height){
  BitmapFactory.Options options=new BitmapFactory.Options();
  options.inJustDecodeBounds=true;
  BitmapFactory.decodeFile(imagePath,options);
  int outH=options.outHeight;
  int outW=options.outWidth;
  int inSampleSize=1;
  if (outH > height || outW > width) {
    int halfH=outH / 2;
    int halfW=outW / 2;
    while ((halfH / inSampleSize) > height && (halfW / inSampleSize) > width) {
      inSampleSize*=2;
    }
  }
  options.inSampleSize=inSampleSize;
  options.inJustDecodeBounds=false;
  int heightRatio=(int)Math.ceil(options.outHeight / (float)height);
  int widthRatio=(int)Math.ceil(options.outWidth / (float)width);
  if (heightRatio > 1 || widthRatio > 1) {
    if (heightRatio > widthRatio) {
      options.inSampleSize=heightRatio;
    }
 else {
      options.inSampleSize=widthRatio;
    }
  }
  options.inJustDecodeBounds=false;
  return BitmapFactory.decodeFile(imagePath,options);
}

private Bitmap compress ( String imagePath , int width , int height ) { BitmapFactory . Options options = new BitmapFactory . Options ( ) ; options . inJustDecodeBounds = true ; BitmapFactory . decodeFile ( imagePath , options ) ; int outH = options . outHeight ; int outW = options . outWidth ; int inSampleSize = 1 ; if ( outH > height || outW > width ) { int halfH = outH / 2 ; int halfW = outW / 2 ; while ( ( halfH / inSampleSize ) > height && ( halfW / inSampleSize ) > width ) { inSampleSize *= 2 ; } } options . inSampleSize = inSampleSize ; options . inJustDecodeBounds = false ; int heightRatio = ( int ) Math . ceil ( options . outHeight / ( float ) height ) ; int widthRatio = ( int ) Math . ceil ( options . outWidth / ( float ) width ) ; if ( heightRatio > 1 || widthRatio > 1 ) { if ( heightRatio > widthRatio ) { options . inSampleSize = heightRatio ; } else { options . inSampleSize = widthRatio ; } } options . inJustDecodeBounds = false ; return BitmapFactory . decodeFile ( imagePath , options ) ; }
obtain the thumbnail that specify the size
