From e2ffc7125e60ab1a664272bc1e66aea4a67c155b Mon Sep 17 00:00:00 2001 From: ashiagr Date: Mon, 4 May 2020 13:28:23 +0530 Subject: [PATCH 1/2] Fix scale "display" percent --- .../java/com/yalantis/ucrop/UCropActivity.java | 5 ++++- .../java/com/yalantis/ucrop/UCropFragment.java | 5 ++++- .../com/yalantis/ucrop/view/CropImageView.java | 16 ++++++++++++---- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java b/ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java index 0b32aafe8..7ff314924 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java @@ -566,7 +566,10 @@ private void setAngleTextColor(int textColor) { private void setScaleText(float scale) { if (mTextViewScalePercent != null) { - mTextViewScalePercent.setText(String.format(Locale.getDefault(), "%d%%", (int) (scale * 100))); + float initialScale = mGestureCropImageView.getInitialMinScale(); + mTextViewScalePercent.setText( + String.format(Locale.getDefault(), "%.2f%%", (scale/ initialScale * 100)) + ); } } diff --git a/ucrop/src/main/java/com/yalantis/ucrop/UCropFragment.java b/ucrop/src/main/java/com/yalantis/ucrop/UCropFragment.java index 8ceea611b..8070a6198 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/UCropFragment.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/UCropFragment.java @@ -449,7 +449,10 @@ private void setAngleTextColor(int textColor) { private void setScaleText(float scale) { if (mTextViewScalePercent != null) { - mTextViewScalePercent.setText(String.format(Locale.getDefault(), "%d%%", (int) (scale * 100))); + float initialScale = mGestureCropImageView.getInitialMinScale(); + mTextViewScalePercent.setText( + String.format(Locale.getDefault(), "%.2f%%", (scale/ initialScale * 100)) + ); } } diff --git a/ucrop/src/main/java/com/yalantis/ucrop/view/CropImageView.java b/ucrop/src/main/java/com/yalantis/ucrop/view/CropImageView.java index 65d892d27..333c2ba44 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/view/CropImageView.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/view/CropImageView.java @@ -51,6 +51,7 @@ public class CropImageView extends TransformImageView { private Runnable mWrapCropBoundsRunnable, mZoomImageToPositionRunnable = null; private float mMaxScale, mMinScale; + private float mInitialMinScale; private int mMaxResultImageSizeX = 0, mMaxResultImageSizeY = 0; private long mImageToWrapCropBoundsAnimDuration = DEFAULT_IMAGE_TO_CROP_BOUNDS_ANIM_DURATION; @@ -109,6 +110,13 @@ public float getTargetAspectRatio() { return mTargetAspectRatio; } + /** + * @return - initial scale value for current image and crop ratio + */ + public float getInitialMinScale() { + return mInitialMinScale; + } + /** * Updates current crop rectangle with given. Also recalculates image properties and position * to fit new crop rectangle. @@ -485,13 +493,13 @@ private void setupInitialImagePosition(float drawableWidth, float drawableHeight float widthScale = mCropRect.width() / drawableWidth; float heightScale = mCropRect.height() / drawableHeight; - float initialMinScale = Math.max(widthScale, heightScale); + mInitialMinScale = Math.max(widthScale, heightScale); - float tw = (cropRectWidth - drawableWidth * initialMinScale) / 2.0f + mCropRect.left; - float th = (cropRectHeight - drawableHeight * initialMinScale) / 2.0f + mCropRect.top; + float tw = (cropRectWidth - drawableWidth * mInitialMinScale) / 2.0f + mCropRect.left; + float th = (cropRectHeight - drawableHeight * mInitialMinScale) / 2.0f + mCropRect.top; mCurrentImageMatrix.reset(); - mCurrentImageMatrix.postScale(initialMinScale, initialMinScale); + mCurrentImageMatrix.postScale(mInitialMinScale, mInitialMinScale); mCurrentImageMatrix.postTranslate(tw, th); setImageMatrix(mCurrentImageMatrix); } From 106d522fa4cb9a529a10b3db98294439849a29c3 Mon Sep 17 00:00:00 2001 From: ashiagr Date: Mon, 9 Nov 2020 11:30:41 +0530 Subject: [PATCH 2/2] Set initial min scale to 1 if zero --- ucrop/src/main/java/com/yalantis/ucrop/view/CropImageView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ucrop/src/main/java/com/yalantis/ucrop/view/CropImageView.java b/ucrop/src/main/java/com/yalantis/ucrop/view/CropImageView.java index 333c2ba44..acf8d4e7c 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/view/CropImageView.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/view/CropImageView.java @@ -114,7 +114,7 @@ public float getTargetAspectRatio() { * @return - initial scale value for current image and crop ratio */ public float getInitialMinScale() { - return mInitialMinScale; + return mInitialMinScale != 0 ? mInitialMinScale : 1; } /**