Added setter for OverlayView's cropViewRect in order to make possible to show custom cropping rect when uCrop starts #582
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Made possible to set the mCropViewRect from OverlayView to a custom value in order to present a custom cropping rect when uCrop starts.
Background: We wanted to integrate document scanning and cropping together. So instead of doing it in multiple steps, we wanted to be able to do it in one step. Basically we wanted to suggest our users what to crop when taking pictures of a document, so we needed a way to highlight the document inside the image.
Solution: In simple terms, the solution was to be able to set mCropViewRect from OverlayView, so I exposed a setter.
Problem was that scanning things from the image outside uCrop gives you coordinates/points in the image space. But the View does not necessarily have the same dimensions as the image you have passed. So RectUtils#convertImageSpaceRectToCropViewRect does exactly what it says, converts those points you have passed into points that correspond to the current view, so that the OverlayView's rect is rendered as it would have been on the image itself.
Only condition for this to work is that setCropViewRectInImageSpace must be used in combination with setMaxBitmapSize (large number), so that the image does not get downscaled. Because if the image gets downscaled, the points/coordinates won't work anymore.
Related issues (maybe more related issues that were closed):
#571
#569
#468
Screenshots:
Before, when you open uCrop, your view will look like this
Open uCrop after doing some edge detection on the above image and passing options.setCropViewRectInImageSpace(new RectF(...)); will result in the following
It would be a really wanted feature for us. I am waiting for questions or improvements. I expect some, since this is my first PR ever, but we kind of really need this functionality :)