diff options
author | Chih-Chung Chang <chihchung@google.com> | 2011-11-07 22:59:55 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-11-07 22:59:55 -0800 |
commit | 713c9a331e226c970af57c59ff17be29b73025c1 (patch) | |
tree | 890c72f52a669374cf388aec8758ec73f1ce2980 /media | |
parent | ee7ebb3257d9337627b175835dc3d08f9b8ab339 (diff) | |
parent | b1224ff1c4ef8324c9d76b857463787aabd84707 (diff) | |
download | frameworks_base-713c9a331e226c970af57c59ff17be29b73025c1.zip frameworks_base-713c9a331e226c970af57c59ff17be29b73025c1.tar.gz frameworks_base-713c9a331e226c970af57c59ff17be29b73025c1.tar.bz2 |
Merge "Fix 5509346: Resize the thumbnails if it's too large." into ics-mr1
Diffstat (limited to 'media')
-rwxr-xr-x | media/java/android/media/videoeditor/MediaImageItem.java | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/media/java/android/media/videoeditor/MediaImageItem.java b/media/java/android/media/videoeditor/MediaImageItem.java index a862d00..590b4ae 100755 --- a/media/java/android/media/videoeditor/MediaImageItem.java +++ b/media/java/android/media/videoeditor/MediaImageItem.java @@ -154,7 +154,7 @@ public class MediaImageItem extends MediaItem { final Bitmap imageBitmap; - if (mHeight > maxResolution.second) { + if (mWidth > maxResolution.first || mHeight > maxResolution.second) { /** * We need to scale the image */ @@ -971,14 +971,13 @@ public class MediaImageItem extends MediaItem { /** * Create the bitmap from file */ - if (nativeWidth / bitmapWidth > 1) { - - final BitmapFactory.Options options = new BitmapFactory.Options(); - options.inSampleSize = nativeWidth / (int)bitmapWidth; - srcBitmap = BitmapFactory.decodeFile(filename, options); - } else { - srcBitmap = BitmapFactory.decodeFile(filename); - } + int sampleSize = (int) Math.ceil(Math.max( + (float) nativeWidth / bitmapWidth, + (float) nativeHeight / bitmapHeight)); + sampleSize = nextPowerOf2(sampleSize); + final BitmapFactory.Options options = new BitmapFactory.Options(); + options.inSampleSize = sampleSize; + srcBitmap = BitmapFactory.decodeFile(filename, options); } else { bitmapWidth = width; bitmapHeight = height; @@ -1009,4 +1008,14 @@ public class MediaImageItem extends MediaItem { srcBitmap.recycle(); return bitmap; } + + public static int nextPowerOf2(int n) { + n -= 1; + n |= n >>> 16; + n |= n >>> 8; + n |= n >>> 4; + n |= n >>> 2; + n |= n >>> 1; + return n + 1; + } } |