am 0bb4dade: Displaying Bitmaps Efficiently Training - Fix inSampleSize selection

* commit '0bb4dade30d3413cc7951c5d2c0ee761a93ae468':
  Displaying Bitmaps Efficiently Training - Fix inSampleSize selection
This commit is contained in:
Adam Koch
2013-01-10 06:26:46 -08:00
committed by Android Git Automerger
2 changed files with 10 additions and 5 deletions

View File

@@ -110,12 +110,17 @@ public static int calculateInSampleSize(
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
if (width > height) {
inSampleSize = Math.round((float)height / (float)reqHeight);
} else {
inSampleSize = Math.round((float)width / (float)reqWidth);
}
// Calculate ratios of height and width to requested height and width
final int heightRatio = Math.round((float) height / (float) reqHeight);
final int widthRatio = Math.round((float) width / (float) reqWidth);
// Choose the smallest ratio as inSampleSize value, this will guarantee
// a final image with both dimensions larger than or equal to the
// requested height and width.
inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
}
return inSampleSize;
}
</pre>