public static int calculateInSampleSize(int srcWidth,int srcHeight,int reqWidth,int reqHeight){
  if ((reqHeight > 0) && (reqWidth > 0) && (srcHeight > reqHeight)&& (srcWidth > reqWidth)) {
    return Math.min(srcWidth / reqWidth,srcHeight / reqHeight);
  }
 else {
    return 1;
  }
}

public static int calculateInSampleSize ( int srcWidth , int srcHeight , int reqWidth , int reqHeight ) { if ( ( reqHeight > 0 ) && ( reqWidth > 0 ) && ( srcHeight > reqHeight ) && ( srcWidth > reqWidth ) ) { return Math . min ( srcWidth / reqWidth , srcHeight / reqHeight ) ; } else { return 1 ; } }
calculates the ratio of linear dimension of source / required so that a bitmap can be decoded to the smallest size big enough to completely fill the destination . for pedagogical clarity , the most straightforward implementation is presented . the documentation notes that insamplesize is rounded down to the nearest power of 2 . algorithms that exploit this seem to run about 30 % faster .
