uCrop icon indicating copy to clipboard operation
uCrop copied to clipboard

Support circle crop as an aspect ratio option

Open carstenz opened this issue 3 years ago • 2 comments

This allows you to add circle crop as one of the aspect ratio options.

When circle crop is selected/unselected, a protected function on UCropActivity/UCropFragment is called (setCircleCrop) - this allows a subclass to update the crop grid/frame/dimmed layer if so desired. This is also why I've changed some views to be protected rather than private, most importantly mOverlayView.

carstenz avatar Mar 11 '21 12:03 carstenz

@carstenz , thank you for the PR. Your idea seems to be promising. However, could you please provide some details about how do you see this API to be integrated and used? As I can see it doesn't work out of the box. Please add some details about this feature usage sample. Thank you.

dmitriy1morozov avatar Jan 25 '22 15:01 dmitriy1morozov

@carstenz , thank you for the PR. Your idea seems to be promising. However, could you please provide some details about how do you see this API to be integrated and used? As I can see it doesn't work out of the box. Please add some details about this feature usage sample. Thank you.

Hi! You're right - it doesn't work out of the box. In addition to this PR, what I do is subclass UcropActivity and override setCircleCrop(), like this:

protected void setCircleCrop(boolean circleCrop) {
        super.setCircleCrop(circleCrop);
        mOverlayView.setCircleDimmedLayer(circleCrop);
    }

That's it really. Perhaps calling mOverlayView.setCircleDimmedLayer(circleCrop) could be a part of KUCropActivity.setCircleCrop(), but I avoided doing that because:

  1. setCircleDimmedLayer() is existing functionality, and I wasn't sure of the ramifications of reusing it here.
  2. Calling setCircleDimmedLayer() by default would make this less flexible. I was thinking it could be up to users of the library to provide other ways of representing the circle (instead of using the existing circleDimmedLayer). But I see the point that not showing any circle by default makes this feature harder to use.

When it comes to the output (EXTRA_OUTPUT_CIRCLE_CROP), it's really up to the user of the feature how to use that flag. In my company, we store this flag as part of image metadata, and apply a circle mask to images that has it.

carstenz avatar Jan 25 '22 16:01 carstenz