Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve #29, Crop rectangle based on coordinate #160

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}

Expand All @@ -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:
Expand Down Expand Up @@ -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
*
Expand Down