protected int calculateBestSubsampleFactor(Size imageSize,Size targetSize){
  int maxSubsample=Math.min(imageSize.getWidth() / targetSize.getWidth(),imageSize.getHeight() / targetSize.getHeight());
  if (maxSubsample < 1) {
    return 1;
  }
  for (int i=maxSubsample; i >= 1; i--) {
    if (((imageSize.getWidth() % (2 * i) == 0) && (imageSize.getHeight() % (2 * i) == 0))) {
      return i;
    }
  }
  return 1;
}

protected int calculateBestSubsampleFactor ( Size imageSize , Size targetSize ) { int maxSubsample = Math . min ( imageSize . getWidth ( ) / targetSize . getWidth ( ) , imageSize . getHeight ( ) / targetSize . getHeight ( ) ) ; if ( maxSubsample < 1 ) { return 1 ; } for ( int i = maxSubsample ; i >= 1 ; i -- ) { if ( ( ( imageSize . getWidth ( ) % ( 2 * i ) == 0 ) && ( imageSize . getHeight ( ) % ( 2 * i ) == 0 ) ) ) { return i ; } } return 1 ; }
calculates the best integer subsample from a given height and width to a target width and height it is assumed that the exact scaling will be done with the android bitmap framework ; this subsample value is to best convert raw images into the lowest resolution raw images in visually lossless manner without changing the aspect ratio or creating subsample artifacts .
