Yalantis / uCrop

Image Cropping Library for Android
https://yalantis.com/blog/introducing-ucrop-our-own-image-cropping-library-for-android/
11.88k stars 2.16k forks source link

Please add a flip photo #785

Open alirezabashi98 opened 3 years ago

HuuNguyen312 commented 2 years ago

I added flip feature. You can try it at https://github.com/HuuNguyen312/uCrop

SweetD3v commented 1 year ago

@HuuNguyen312 Thanks for the feature implementation, but is has a bug. Image don't flip when you don't rotate it and just flip it directly and then save.

Here is what you need to do,

Just put this line in shouldCrop() method located in BitmapCropTask.Java.

if (flipHorizontally) return true;

The complete code would be:

private boolean shouldCrop(int width, int height) {
        int pixelError = 1;
        pixelError += Math.round(Math.max(width, height) / 1000f);
        if (flipHorizontally) return true;
        return (mMaxResultImageSizeX > 0 && mMaxResultImageSizeY > 0)
                || Math.abs(mCropRect.left - mCurrentImageRect.left) > pixelError
                || Math.abs(mCropRect.top - mCurrentImageRect.top) > pixelError
                || Math.abs(mCropRect.bottom - mCurrentImageRect.bottom) > pixelError
                || Math.abs(mCropRect.right - mCurrentImageRect.right) > pixelError
                || mCurrentAngle != 0;
    }