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..acf8d4e7c 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 != 0 ? mInitialMinScale : 1; + } + /** * 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); }