diff options
| author | 2013-01-10 06:32:43 -0800 | |
|---|---|---|
| committer | 2013-01-10 06:32:43 -0800 | |
| commit | d6ddb51b3d4ec1bb2e6305823681cdeb05c0ea7b (patch) | |
| tree | 00e152c9e4ab7020157cad3916ff9985ed396b74 | |
| parent | 854458f4d52937f9a1385559d759bd8019eb3294 (diff) | |
| parent | 2d255b7e1fb1cb1ceb64a962f672f145eab585e8 (diff) | |
am 2d255b7e: am ec7ffa14: am 0bb4dade: Displaying Bitmaps Efficiently Training - Fix inSampleSize selection
* commit '2d255b7e1fb1cb1ceb64a962f672f145eab585e8':
Displaying Bitmaps Efficiently Training - Fix inSampleSize selection
| -rw-r--r-- | docs/downloads/training/BitmapFun.zip | bin | 397971 -> 430475 bytes | |||
| -rw-r--r-- | docs/html/training/displaying-bitmaps/load-bitmap.jd | 15 |
2 files changed, 10 insertions, 5 deletions
diff --git a/docs/downloads/training/BitmapFun.zip b/docs/downloads/training/BitmapFun.zip Binary files differindex e48bfd304185..c4ea7aa92c4b 100644 --- a/docs/downloads/training/BitmapFun.zip +++ b/docs/downloads/training/BitmapFun.zip diff --git a/docs/html/training/displaying-bitmaps/load-bitmap.jd b/docs/html/training/displaying-bitmaps/load-bitmap.jd index c0a5709d41cc..283f27215bfe 100644 --- a/docs/html/training/displaying-bitmaps/load-bitmap.jd +++ b/docs/html/training/displaying-bitmaps/load-bitmap.jd @@ -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> |