summaryrefslogtreecommitdiffstats
path: root/gallerycommon/src/com/android/gallery3d/common
diff options
context:
space:
mode:
Diffstat (limited to 'gallerycommon/src/com/android/gallery3d/common')
-rw-r--r--gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java13
1 files changed, 12 insertions, 1 deletions
diff --git a/gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java b/gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java
index aaf4f6665..c34e89631 100644
--- a/gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java
+++ b/gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java
@@ -85,7 +85,7 @@ public class BitmapUtils {
// minSideLength long. If that's not possible, return 1.
public static int computeSampleSizeLarger(int w, int h,
int minSideLength) {
- int initialSize = Math.min(w / minSideLength, h / minSideLength);
+ int initialSize = Math.max(w / minSideLength, h / minSideLength);
if (initialSize <= 1) return 1;
return initialSize <= 8
@@ -155,6 +155,17 @@ public class BitmapUtils {
return resizeBitmapByScale(bitmap, scale, recycle);
}
+ // Resize the bitmap if each side is >= targetSize * 2
+ public static Bitmap resizeDownIfTooBig(
+ Bitmap bitmap, int targetSize, boolean recycle) {
+ int srcWidth = bitmap.getWidth();
+ int srcHeight = bitmap.getHeight();
+ float scale = Math.max(
+ (float) targetSize / srcWidth, (float) targetSize / srcHeight);
+ if (scale > 0.5f) return bitmap;
+ return resizeBitmapByScale(bitmap, scale, recycle);
+ }
+
// Crops a square from the center of the original image.
public static Bitmap cropCenter(Bitmap bitmap, boolean recycle) {
int width = bitmap.getWidth();