CanHub / Android-Image-Cropper

Image Cropping Library for Android, optimised for Camera / Gallery.
Apache License 2.0
1.25k stars 259 forks source link

[BUG] - No actions available to crop an image or continue. #250

Closed SergeKozhCxagroup closed 2 years ago

SergeKozhCxagroup commented 2 years ago

Hi!. I can't crop an image after I picked it. After image is chosen I see a cropping screen, but there are no actions to do after the area is selected. Can you help with this please?

My code is:

private ActivityResultLauncher<CropImageContractOptions> cropImageResultLauncher = registerForActivityResult(new CropImageContract(), result -> {
        if (result.isSuccessful()){
            Uri resultUri = result.getUriContent();
            mPresenter.onGetImage(resultUri, null);
        } else {
            Exception error = result.getError();
            mPresenter.onGetImage(null, error);
        }
    });

    @Override
    public void startTakePhoto() {
        CropImageContractOptions options = new CropImageContractOptions(null, new CropImageOptions())
                .setGuidelines(CropImageView.Guidelines.ON)
                .setMinCropResultSize(300,300);

        cropImageResultLauncher.launch(options);
    }

Screenshot_20211023-182851_1

Smartphone :

Lib Version [3.3.5]

Canato commented 2 years ago

Hey @SergeKozhCxagroup welcome, can you reproduce on the sample app?

And/or did you have this?

<activity android:name="com.canhub.cropper.CropImageActivity"
  android:theme="@style/Base.Theme.AppCompat"/> <!-- optional (needed if default theme has no action bar) -->
SergeKozhCxagroup commented 2 years ago

Hi @Canato, it was needed to replace the old library activity (com.theartofdev.edmodo.cropper.CropImageActivity) and it does show the crop action now, thanks! But now I can't get the result of the cropping, can it be because I am using the 3.2.2 lib version?

Canato commented 2 years ago

@SergeKozhCxagroup try to use the latest version of the library

and create a activity contract so you can get the result

class MainActivity {
   private val cropImage = registerForActivityResult(CropImageContract()) { result ->
           if (result.isSuccessful) {
               // use the returned uri
               val uriContent = result.uriContent 
               val uriFilePath = result.getUriFilePath(context) // optional usage
           } else {
               // an error occurred
               val exception = result.error
           }
       }

   private fun startCrop() {
       // start picker to get image for cropping and then use the image in cropping activity
       cropImage.launch(
           options {
               setGuidelines(Guidelines.ON)
           }
       )

       //start picker to get image for cropping from only gallery and then use the image in
       //cropping activity
       cropImage.launch(
           options {
               setImagePickerContractOptions(
                   PickImageContractOptions(includeGallery = true, includeCamera = false)
               )
           }
       )

       // start cropping activity for pre-acquired image saved on the device and customize settings
       cropImage.launch(
           options(uri = imageUri) {
               setGuidelines(Guidelines.ON)
               setOutputCompressFormat(CompressFormat.PNG)
           }
       )
   }
}
stale[bot] commented 2 years ago

Let's keep this mess organised! This issue has been automatically marked as stale because it has not had recent activity. =( It will be closed if no further activity occurs. Thank you for your contributions.