From eae57c0ccbb9d22a61f681fed3d2696a5135d3c4 Mon Sep 17 00:00:00 2001 From: Owen Lin Date: Wed, 30 May 2012 16:39:21 +0800 Subject: Check the offset of output rect when cropping image. bug: 6568720 Change-Id: I36c98cab5830eaac15369ada1a1a988e10b0fbf4 --- src/com/android/gallery3d/app/CropImage.java | 6 ++++++ src/com/android/gallery3d/app/Wallpaper.java | 10 ++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/com/android/gallery3d/app/CropImage.java b/src/com/android/gallery3d/app/CropImage.java index 835970b4f..4f450d85e 100644 --- a/src/com/android/gallery3d/app/CropImage.java +++ b/src/com/android/gallery3d/app/CropImage.java @@ -612,8 +612,14 @@ public class CropImage extends AbstractGalleryActivity { int sample = BitmapUtils.computeSampleSizeLarger( Math.max(scaleX, scaleY)); options.inSampleSize = sample; + + // The decoding result is what we want if + // 1. The size of the decoded bitmap match the destination's size + // 2. The destination covers the whole output bitmap + // 3. No rotation if ((rect.width() / sample) == dest.width() && (rect.height() / sample) == dest.height() + && (outputX == dest.width()) && (outputY == dest.height()) && rotation == 0) { // To prevent concurrent access in GLThread synchronized (mRegionDecoder) { diff --git a/src/com/android/gallery3d/app/Wallpaper.java b/src/com/android/gallery3d/app/Wallpaper.java index 07a3d5313..c08c1d705 100644 --- a/src/com/android/gallery3d/app/Wallpaper.java +++ b/src/com/android/gallery3d/app/Wallpaper.java @@ -18,9 +18,9 @@ package com.android.gallery3d.app; import android.app.Activity; import android.content.Intent; +import android.graphics.Point; import android.net.Uri; import android.os.Bundle; -import android.view.Display; /** * Wallpaper picker for the gallery application. This just redirects to the @@ -78,9 +78,10 @@ public class Wallpaper extends Activity { case STATE_PHOTO_PICKED: { int width = getWallpaperDesiredMinimumWidth(); int height = getWallpaperDesiredMinimumHeight(); - Display display = getWindowManager().getDefaultDisplay(); - float spotlightX = (float) display.getWidth() / width; - float spotlightY = (float) display.getHeight() / height; + Point size = new Point(); + getWindowManager().getDefaultDisplay().getSize(size); + float spotlightX = (float) size.x / width; + float spotlightY = (float) size.y / height; Intent request = new Intent(CropImage.ACTION_CROP) .setDataAndType(mPickedItem, IMAGE_TYPE) .addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT) @@ -91,6 +92,7 @@ public class Wallpaper extends Activity { .putExtra(CropImage.KEY_SPOTLIGHT_X, spotlightX) .putExtra(CropImage.KEY_SPOTLIGHT_Y, spotlightY) .putExtra(CropImage.KEY_SCALE, true) + .putExtra(CropImage.KEY_SCALE_UP_IF_NEEDED, true) .putExtra(CropImage.KEY_NO_FACE_DETECTION, true) .putExtra(CropImage.KEY_SET_AS_WALLPAPER, true); startActivity(request); -- cgit v1.2.3