diff --git a/simplecropview/src/main/java/com/isseiaoki/simplecropview/CropImageView.java b/simplecropview/src/main/java/com/isseiaoki/simplecropview/CropImageView.java index b515aa7..412ff7e 100644 --- a/simplecropview/src/main/java/com/isseiaoki/simplecropview/CropImageView.java +++ b/simplecropview/src/main/java/com/isseiaoki/simplecropview/CropImageView.java @@ -1003,13 +1003,12 @@ private boolean isHeightTooSmall() { // Frame aspect ratio correction /////////////////////////////////////////////////////////////// - private void recalculateFrameRect(int durationMillis) { + private void recalculateFrameRect(int durationMillis, final RectF newRect) { if (mImageRect == null) return; if (mIsAnimating) { getAnimator().cancelAnimation(); } final RectF currentRect = new RectF(mFrameRect); - final RectF newRect = calcFrameRect(mImageRect); final float diffL = newRect.left - currentRect.left; final float diffT = newRect.top - currentRect.top; final float diffR = newRect.right - currentRect.right; @@ -1023,7 +1022,7 @@ private void recalculateFrameRect(int durationMillis) { @Override public void onAnimationUpdated(float scale) { mFrameRect = new RectF(currentRect.left + diffL * scale, currentRect.top + diffT * scale, - currentRect.right + diffR * scale, currentRect.bottom + diffB * scale); + currentRect.right + diffR * scale, currentRect.bottom + diffB * scale); invalidate(); } @@ -1035,11 +1034,15 @@ private void recalculateFrameRect(int durationMillis) { }); animator.startAnimation(durationMillis); } else { - mFrameRect = calcFrameRect(mImageRect); + mFrameRect = newRect; invalidate(); } } + private void recalculateFrameRect(int durationMillis) { + recalculateFrameRect(durationMillis, calcFrameRect(mImageRect)); + } + private float getRatioX(float w) { switch (mCropMode) { case FIT_IMAGE: @@ -1960,6 +1963,20 @@ public void setCropMode(CropMode mode, int durationMillis) { } } + /** + * Set frame rectangle + * + * @param newRect new frame rectangle relative to mImageRect + */ + public void setFrameRect(RectF newRect) { + mCropMode = CropMode.FREE; + RectF absoluteRect = new RectF( + newRect.left + mImageRect.left, newRect.top + mImageRect.top, + newRect.right + mImageRect.left, newRect.bottom + mImageRect.top + ); + recalculateFrameRect(mAnimationDurationMillis, absoluteRect); + } + /** * Set getCroppedBitmap mode *