uCrop
uCrop copied to clipboard
How to reset all options in CropImageView?
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 , 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.
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 , you are welcome! Thank you too. You can create pull request with your changes. May be this improvement will be useful for someone
@KucherenkoIhor I have pushed PR with this fix.
@Sirelon , thank you
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.
The simple way is: just remove the UcropView and add a new one
public void reset() {
setTargetAspectRatio(0f);
setImageToWrapCropBounds(false);
zoomInImage(getMinScale());
setImageToWrapCropBounds();
}
this is work for me