summaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorAdam Koch <akoch@google.com>2013-01-09 16:58:59 -0500
committerAdam Koch <akoch@google.com>2013-01-09 16:58:59 -0500
commit0bb4dade30d3413cc7951c5d2c0ee761a93ae468 (patch)
tree4e7236033782f428172c425a7a99d8ed368b3e1e /docs
parentcdf5106aafb77d17584d5401b207cbcc7a20f5f3 (diff)
downloadframeworks_base-0bb4dade30d3413cc7951c5d2c0ee761a93ae468.zip
frameworks_base-0bb4dade30d3413cc7951c5d2c0ee761a93ae468.tar.gz
frameworks_base-0bb4dade30d3413cc7951c5d2c0ee761a93ae468.tar.bz2
Displaying Bitmaps Efficiently Training - Fix inSampleSize selection
When computing inSampleSize, calculateInSampleSize() needs to compare height/width ratios, rather than raw values. Bug: 7951398 Change-Id: I207f9abc2aae4cc569b406bac237e221d8e64d1e
Diffstat (limited to 'docs')
-rw-r--r--docs/downloads/training/BitmapFun.zipbin397971 -> 430475 bytes
-rw-r--r--docs/html/training/displaying-bitmaps/load-bitmap.jd15
2 files changed, 10 insertions, 5 deletions
diff --git a/docs/downloads/training/BitmapFun.zip b/docs/downloads/training/BitmapFun.zip
index e48bfd3..c4ea7aa 100644
--- a/docs/downloads/training/BitmapFun.zip
+++ b/docs/downloads/training/BitmapFun.zip
Binary files differ
diff --git a/docs/html/training/displaying-bitmaps/load-bitmap.jd b/docs/html/training/displaying-bitmaps/load-bitmap.jd
index c0a5709..283f272 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>