Crop a fixed size image in Android

后端 未结 2 1199
萌比男神i
萌比男神i 2021-02-05 11:19

I am trying to crop an image but I want to be able to set the cropped area to exactly 640px x 640px. I want to prevent a user from cropping down to a really small area. So ba

2条回答
  •  庸人自扰
    2021-02-05 11:33

    I'd use one of these solutions:

    1. https://github.com/jdamcd/android-crop
    2. https://github.com/edmodo/cropper

    Both seems to be appropriate to solve your problem and for sure cover more edge cases, devices and other Android stuff just to be more stable and reliable.

    EDIT:
    I have introduced a few changes to android-crop and now you can use withFixedSize(int width, int height) to set fixed cropping area in pixels.

    Looks like this:

     private void beginCrop(Uri source) {
            Uri outputUri = Uri.fromFile(new File(getCacheDir(), "cropped"));
            new Crop(source).output(outputUri).withFixedSize(640, 640).start(this);
        }
    

    Here it's a pull request.

    Check full code at my github https://github.com/mklimek/android-crop/tree/newfeature_fied_size_crop.

    You can clone build and add it to your project afterwards.

    Hope it will help you.

提交回复
热议问题