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

Allow to set CroppedRegion in ImageCropper #2846

Merged
merged 7 commits into from
Apr 9, 2019

Conversation

arcadiogarcia
Copy link
Member

@arcadiogarcia arcadiogarcia commented Mar 6, 2019

Issue: #2845

PR Type

What kind of change does this PR introduce?

What is the current behavior?

The ImageCropper control doesn't allow to set the CroppedRegion

What is the new behavior?

The ImageCropper allows to set the CroppedRegion, so the app can specify a default crop region.

PR Checklist

Please check if your PR fulfills the following requirements:

Other information

@dnfclas
Copy link

dnfclas commented Mar 6, 2019

CLA assistant check
All CLA requirements met.

@dnfclas
Copy link

dnfclas commented Mar 6, 2019

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

❌ arcadiogarcia sign now
You have signed the CLA already but the status is still pending? Let us recheck it.


set
{
_currentCroppedRect = value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to check the value of _currentCroppedRect to ensure it is valid (related to _restrictedCropRect and MinCropSize), otherwise the saved image will be incorrect.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition, we have to consider AspectRatio(KeepAspectRatio and UsedAspectRatio are used in the code).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. What do you suggest to do when the provided rect doesn't satisfy the requisites?

Thinking out loud: We could modify it so it respects the minimum size and aspect ratio, but it would be hard for the user of the control to predict what the resulting rect will be. Maybe we should just drop it when the value is not valid? But since this is a setter there will be no failure indication, unless we throw and exception which might be too aggressive.

What do you think about discarding the setter and replacing it with

bool TrySetCroppedRegion(Rect r)

returning true if the rect satisfies the requirements, and false if the rect is discarded?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. It's a great idea!

@michael-hawker michael-hawker added this to the 6.0 milestone Mar 6, 2019
}

// Reject regions larger than the original picture
if (rect.Width > _restrictedCropRect.Width || rect.Height > _restrictedCropRect.Height)
Copy link
Contributor

@HHChaos HHChaos Mar 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, but don't forget to check rect.X and rect.Y.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops right didn't realize they can have different offsets, fixing this line

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arcadiogarcia did this piece get resolved properly? Is that the next section with the Left and Bottom checks? Just wanted to make sure before approving.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michael-hawker Yes, that new condition should reject all regions that step outside the original picture.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants