uCrop icon indicating copy to clipboard operation
uCrop copied to clipboard

Added setter for OverlayView's cropViewRect in order to make possible to show custom cropping rect when uCrop starts

Open andreiolar opened this issue 4 years ago • 2 comments

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

Screenshot_20191023_130249_no tripletex debug

Open uCrop after doing some edge detection on the above image and passing options.setCropViewRectInImageSpace(new RectF(...)); will result in the following

Screenshot_20191023_135233_no tripletex debug

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 :)

andreiolar avatar Oct 21 '19 07:10 andreiolar