From c188ffee66e30718a792bfccb581a9e630a1c4f1 Mon Sep 17 00:00:00 2001 From: pezhan Date: Wed, 1 Mar 2017 14:28:34 +0800 Subject: SnapdragonCamera: Fix Camera1 force close when refocusing the picture. When the screen is PORTRAIT mode, we get the screen always height < width. But we get the image always height < width.Under this circumstance, the inSampleSize maybe incorrect , which will cause OOM when create bitmap. Need to check the screen's orientation,and choose the correct width and height to calculate the inSampleSize. Change-Id: I11743c862ebdb9d35c4fc5de7bf40003c69b7219 CRs-Fixed: 2013250 --- src/com/android/camera/RefocusActivity.java | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/com/android/camera/RefocusActivity.java b/src/com/android/camera/RefocusActivity.java index 599d46656..bc80a4f1b 100644 --- a/src/com/android/camera/RefocusActivity.java +++ b/src/com/android/camera/RefocusActivity.java @@ -39,6 +39,7 @@ import android.animation.PropertyValuesHolder; import android.animation.ValueAnimator; import android.app.Activity; import android.content.Context; +import android.content.res.Configuration; import android.content.res.Resources; import android.content.Intent; import android.graphics.Bitmap; @@ -215,6 +216,8 @@ public class RefocusActivity extends Activity { private class LoadImageTask extends AsyncTask { protected Bitmap doInBackground(String... path) { final BitmapFactory.Options o = new BitmapFactory.Options(); + int height; + int width; o.inJustDecodeBounds = true; BitmapFactory.decodeFile(path[0], o); ExifInterface exif = new ExifInterface(); @@ -226,13 +229,24 @@ public class RefocusActivity extends Activity { } int h = o.outHeight; int w = o.outWidth; + int screenOrientation = RefocusActivity.this.getResources().getConfiguration() + .orientation; + if (screenOrientation == Configuration.ORIENTATION_PORTRAIT) { + height = mWidth; + width = mHeight; + } else { + height = mHeight; + width = mWidth; + } int sample = 1; - if (h > mHeight || w > mWidth) { - while (h / sample / 2 > mHeight && w / sample / 2 > mWidth) { + if (h > height || w > width) { + while (h / sample / 2 > height && w / sample / 2 > width) { sample *= 2; } } - + Log.d(TAG, "sample = " + sample); + Log.d(TAG, "h = " + h + " height = " + height); + Log.d(TAG, "w = " + w + " width = " + width); o.inJustDecodeBounds = false; o.inSampleSize = sample; Bitmap bitmap = BitmapFactory.decodeFile(path[0], o); -- cgit v1.2.3