private static int calculateInSampleSize( BitmapFactory.Options options, int reqWidth, int reqHeight) { final int height = options.outHeight; final int width = options.outWidth; int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) { if (height > reqHeight && reqHeight != 0) { inSampleSize = (int) Math.floor((double) height / (double) reqHeight); } int tmp = 0; if (width > reqWidth && reqWidth != 0) { tmp = (int) Math.floor((double) width / (double) reqWidth); } inSampleSize = Math.max(inSampleSize, tmp); } int roundedSize; if (inSampleSize <= 8) { roundedSize = 1; while (roundedSize < inSampleSize) { roundedSize <<= 1; } } else { roundedSize = (inSampleSize + 7) / 8 * 8; } return roundedSize; }