From 5c811f55cd456a9a16a7805c7d89eee8386de1be Mon Sep 17 00:00:00 2001 From: Issei Aoki Date: Tue, 26 Apr 2016 15:09:47 +0900 Subject: [PATCH 1/5] Fix bug image ratio collapse --- .../main/java/com/isseiaoki/simplecropview/CropImageView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simplecropview/src/main/java/com/isseiaoki/simplecropview/CropImageView.java b/simplecropview/src/main/java/com/isseiaoki/simplecropview/CropImageView.java index 8bf1de5..ca8e06c 100644 --- a/simplecropview/src/main/java/com/isseiaoki/simplecropview/CropImageView.java +++ b/simplecropview/src/main/java/com/isseiaoki/simplecropview/CropImageView.java @@ -1279,7 +1279,7 @@ private Bitmap scaleBitmapIfNeeded(Bitmap cropped) { int height = cropped.getHeight(); int outWidth = 0; int outHeight = 0; - float imageRatio = getRatioX() / getRatioY(); + float imageRatio = getRatioX(mFrameRect.width()) / getRatioY(mFrameRect.height()); if (mOutputWidth > 0) { outWidth = mOutputWidth; From 932af8eec847eb24385fdc9c445b5245607cfaed Mon Sep 17 00:00:00 2001 From: Issei Aoki Date: Tue, 26 Apr 2016 15:31:52 +0900 Subject: [PATCH 2/5] Fix bug DialogFragment crash --- .../example/simplecropviewsample/MainFragment.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/simplecropview-sample/src/main/java/com/example/simplecropviewsample/MainFragment.java b/simplecropview-sample/src/main/java/com/example/simplecropviewsample/MainFragment.java index 2a27b12..9d5ce5b 100644 --- a/simplecropview-sample/src/main/java/com/example/simplecropviewsample/MainFragment.java +++ b/simplecropview-sample/src/main/java/com/example/simplecropviewsample/MainFragment.java @@ -69,8 +69,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) { bindViews(view); // apply custom font FontUtils.setFont(mRootLayout); - -// mCropView.setDebug(true); +// mCropView.setDebug(true); // set bitmap to CropImageView if (mCropView.getImageBitmap() == null) { mCropView.setImageResource(R.drawable.sample5); @@ -83,7 +82,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent result) { if (requestCode == REQUEST_PICK_IMAGE && resultCode == Activity.RESULT_OK) { showProgress(); mCropView.startLoad(result.getData(), mLoadCallback); - }else if(requestCode == REQUEST_SAF_PICK_IMAGE && resultCode == Activity.RESULT_OK){ + } else if (requestCode == REQUEST_SAF_PICK_IMAGE && resultCode == Activity.RESULT_OK) { showProgress(); mCropView.startLoad(Utils.ensureUriPermission(getContext(), result), mLoadCallback); } @@ -135,12 +134,12 @@ public void cropImage() { } @OnShowRationale(Manifest.permission.READ_EXTERNAL_STORAGE) - public void showRationaleForPick(PermissionRequest request){ + public void showRationaleForPick(PermissionRequest request) { showRationaleDialog(R.string.permission_pick_rationale, request); } @OnShowRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE) - public void showRationaleForCrop(PermissionRequest request){ + public void showRationaleForCrop(PermissionRequest request) { showRationaleDialog(R.string.permission_crop_rationale, request); } @@ -149,7 +148,7 @@ public void showProgress() { getFragmentManager() .beginTransaction() .add(f, PROGRESS_DIALOG) - .commit(); + .commitAllowingStateLoss(); } public void dismissProgress() { @@ -158,7 +157,7 @@ public void dismissProgress() { if (manager == null) return; ProgressDialogFragment f = (ProgressDialogFragment) manager.findFragmentByTag(PROGRESS_DIALOG); if (f != null) { - getFragmentManager().beginTransaction().remove(f).commit(); + getFragmentManager().beginTransaction().remove(f).commitAllowingStateLoss(); } } From 6582a44eadd0302b083219b62f3e91f0614edd81 Mon Sep 17 00:00:00 2001 From: Issei Aoki Date: Tue, 26 Apr 2016 16:19:22 +0900 Subject: [PATCH 3/5] Fix bug can't parcel a recycled bitmap --- .../simplecropviewsample/ResultActivity.java | 1 - .../simplecropview/CropImageView.java | 22 +++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/simplecropview-sample/src/main/java/com/example/simplecropviewsample/ResultActivity.java b/simplecropview-sample/src/main/java/com/example/simplecropviewsample/ResultActivity.java index 9a73361..40794ec 100644 --- a/simplecropview-sample/src/main/java/com/example/simplecropviewsample/ResultActivity.java +++ b/simplecropview-sample/src/main/java/com/example/simplecropviewsample/ResultActivity.java @@ -81,7 +81,6 @@ public LoadScaledImageTask(Context context, Uri uri, ImageView imageView, int wi @Override public void run() { final int exifRotation = Utils.getExifOrientation(context, uri); - Log.d(TAG, "exifRotation = "+exifRotation); int maxSize = Utils.getMaxSize(); int requestSize = Math.min(width, maxSize); try { diff --git a/simplecropview/src/main/java/com/isseiaoki/simplecropview/CropImageView.java b/simplecropview/src/main/java/com/isseiaoki/simplecropview/CropImageView.java index ca8e06c..75bf8c4 100644 --- a/simplecropview/src/main/java/com/isseiaoki/simplecropview/CropImageView.java +++ b/simplecropview/src/main/java/com/isseiaoki/simplecropview/CropImageView.java @@ -1244,7 +1244,9 @@ private Bitmap decodeRegion() { cropped = decoder.decodeRegion(cropRect, new BitmapFactory.Options()); if (mAngle != 0) { Bitmap rotated = getRotatedBitmap(cropped); - cropped.recycle(); + if(cropped != getBitmap() && cropped != rotated){ + cropped.recycle(); + } cropped = rotated; } } catch (IOException e) { @@ -1303,7 +1305,7 @@ private Bitmap scaleBitmapIfNeeded(Bitmap cropped) { if (outWidth > 0 && outHeight > 0) { Bitmap scaled = Utils.getScaledBitmap(cropped, outWidth, outHeight); - if (cropped != scaled) { + if (cropped != getBitmap() && cropped != scaled) { cropped.recycle(); } cropped = scaled; @@ -1538,12 +1540,16 @@ public Bitmap getCroppedBitmap() { null, false ); - if (rotated != source) { + if (cropped != source && cropped != rotated) { rotated.recycle(); } if (mCropMode == CropMode.CIRCLE) { - cropped = getCircularBitmap(cropped); + Bitmap circle = getCircularBitmap(cropped); + if(cropped != getBitmap()){ + cropped.recycle(); + } + cropped = circle; } return cropped; } @@ -1572,8 +1578,6 @@ public Bitmap getCircularBitmap(Bitmap square) { canvas.drawCircle(halfWidth, halfHeight, Math.min(halfWidth, halfHeight), paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(square, rect, rect, paint); - - square.recycle(); return output; } @@ -1607,7 +1611,11 @@ public void run() { else { cropped = decodeRegion(); if (mCropMode == CropMode.CIRCLE) { - cropped = getCircularBitmap(cropped); + Bitmap circle = getCircularBitmap(cropped); + if(cropped != getBitmap()){ + cropped.recycle(); + } + cropped = circle; } } From 6bebf1b52ccb95c354ba424ff3680cbfac75302d Mon Sep 17 00:00:00 2001 From: Issei Aoki Date: Tue, 26 Apr 2016 17:14:13 +0900 Subject: [PATCH 4/5] Update CHANGELOG.md and README.md --- CHANGELOG.md | 4 ++++ README.md | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82d75f8..5e38817 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ Change Log ========= +## Version 1.1.2 +* Fix bug image ratio collapse +* Fix bug can't parcel a recycled bitmap + ## Version 1.1.1 * Fix bug EXIF orientation not applied diff --git a/README.md b/README.md index 7e47c6e..eb01e21 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ repositories { jcenter() } dependencies { - compile 'com.isseiaoki:simplecropview:1.1.1' + compile 'com.isseiaoki:simplecropview:1.1.2' } ``` From 05579caa9055f17fbe86bd11778509d24fc763b8 Mon Sep 17 00:00:00 2001 From: Issei Aoki Date: Tue, 26 Apr 2016 17:17:31 +0900 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e38817..80a1255 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ Change Log ========= ## Version 1.1.2 -* Fix bug image ratio collapse +* Fix bug image ratio collapse with FREE as cropMode * Fix bug can't parcel a recycled bitmap ## Version 1.1.1