if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
-
+
+ // calculates the largest inSampleSize value (for smallest sample) that is a power of 2 and keeps both
+ // height and width **larger** than the requested height and width.
while ((halfHeight / inSampleSize) > reqHeight
&& (halfWidth / inSampleSize) > reqWidth) {
inSampleSize *= 2;