uCrop icon indicating copy to clipboard operation
uCrop copied to clipboard

How to reset all options in CropImageView?

Open Sirelon opened this issue 7 years ago • 8 comments

Hi! Thank you for this library) I have a question. How to reset all options for CropImageView ? I mean the rotation, scale, translation? I want to reuse the view, but with new Image and without transformations which I early did.

When I use postRotate and postScale than the next image which I set won't crop. the error is java.lang.IllegalArgumentException: x + width must be <= bitmap.width() in BitmapCropTask.java:151 The same occurs if I setImageMatrix(new Matrix())

How can I reuse CropImageView with initial options?

Sirelon avatar Mar 20 '17 13:03 Sirelon

@Sirelon , Hi Thank u for pointing this out. Our team will research it. And we will try to provide you our feedback as soon as possible.

KucherenkoIhor avatar Apr 03 '17 10:04 KucherenkoIhor

I have implemented some trick for this option. Just recreate UCropImageView :-) I am sure, that it is not good solution, but if anyone want to achieve this now, than he can use this approach. I published gist with ReusableUCropView

And thank you for this great library 👍

Sirelon avatar Apr 03 '17 11:04 Sirelon

@Sirelon , you are welcome! Thank you too. You can create pull request with your changes. May be this improvement will be useful for someone

KucherenkoIhor avatar Apr 03 '17 12:04 KucherenkoIhor

@KucherenkoIhor I have pushed PR with this fix.

Sirelon avatar Apr 03 '17 13:04 Sirelon

@Sirelon , thank you

KucherenkoIhor avatar Apr 03 '17 13:04 KucherenkoIhor

You can add this method to your extension of CropImageView to reset both scale and rotation:

public void reset() {
        final Drawable drawable = getDrawable();
        if (drawable == null) {
            return;
        }

        float drawableWidth = drawable.getIntrinsicWidth();
        float drawableHeight = drawable.getIntrinsicHeight();

        setupInitialImagePosition(drawableWidth, drawableHeight);
    }

Of course, there's no clean way to just extend CropImageView, you will need to extend UCropView, OverlayView, GestureCropImageView as well.

This reset feature for both rotation and scaling is very handy (can prevent unintentional cropping) so I hope it would get included in the next version.

vxhviet avatar Apr 07 '17 05:04 vxhviet

The simple way is: just remove the UcropView and add a new one

litang0908 avatar May 03 '19 01:05 litang0908

public void reset() {
        setTargetAspectRatio(0f);
        setImageToWrapCropBounds(false);
        zoomInImage(getMinScale());
        setImageToWrapCropBounds();
    }

this is work for me

mikaelzero avatar Dec 10 '21 07:12 mikaelzero