question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] - Unable to Crop image from Uri

See original GitHub issue
  • Lib Version [e.g. 3.0.0]

Describe the bug First of all I would like to thank everyone involved in this library for the great work you have done. Well done.

I am currently using this library in a project where I have a personalized interface where the user can take a photo. When he takes the picture I take this uri and send it to another screen to edit the image. On this screen I have a button to crop the image, which is where I call the CropImage.

This is the contract:

fun createCropImageContract(uri: Uri): ActivityResultContract<Any?, Uri?> {
            return object : ActivityResultContract<Any?, Uri?>() {
                override fun createIntent(context: Context, input: Any?): Intent {
                    return CropImage
                        .activity(uri)
                        .getIntent(context)
                }

                override fun parseResult(resultCode: Int, intent: Intent?): Uri? {
                    return CropImage.getActivityResult(intent)?.uriContent
                }
            }
        }

However, when I call the method, the CropImage’s Activity is called and is immediately closed returning the Uri as null.

This is what I was able to see in the log (I don’t know if it’s related but it appears every time I press the button) :

2021-04-14 09:48:08.723 3211-3211/? E/[IndicatorGarden]Presenter: onGardenApplyWindowInsets() New DisplayCutout is NULL!!
2021-04-14 09:48:08.725 3211-3211/? E/SystemUIImageView: set Image Drawable!!
2021-04-14 09:48:08.725 3211-3211/? E/SystemUIImageView: set Background Drawable!!
2021-04-14 09:48:08.729 3211-3211/? E/[IndicatorGarden]Presenter: onGardenApplyWindowInsets() New DisplayCutout is NULL!!
2021-04-14 09:48:08.786 3211-3211/? E/[IndicatorGarden]Presenter: onGardenApplyWindowInsets() New DisplayCutout is NULL!!
2021-04-14 09:48:08.788 3211-3211/? E/SystemUIImageView: set Image Drawable!!
2021-04-14 09:48:08.788 3211-3211/? E/SystemUIImageView: set Background Drawable!!
2021-04-14 09:48:08.792 3211-3211/? E/[IndicatorGarden]Presenter: onGardenApplyWindowInsets() New DisplayCutout is NULL!!

I have another feature which is the creation of a profile, there I call this contract and everything is working correctly:

fun createCropImageContract(): ActivityResultContract<Any?, Uri?> {
            return object : ActivityResultContract<Any?, Uri?>() {
                    override fun createIntent(context: Context, input: Any?): Intent {
                        return CropImage
                            .activity()
                            .getIntent(context)
                    }

                    override fun parseResult(resultCode: Int, intent: Intent?): Uri? {
                        return CropImage.getActivityResult(intent)?.uriContent
                    }
                }
        }

The problem is only when I already send Uri directly. Am I doing something wrong?

To Reproduce Call CropImage Passing the Uri from fragment:

CropImage
                        .activity(uri)
                        .getIntent(context)
                }

Expected behavior Open the CropImage activity to crop the provided Uri

Screenshots If applicable, add screenshots to help explain your problem.

Smartphone (please complete the following information):

  • Pixel 2 XL Android 11
  • Samsung Galaxy S9+ Android 10

Additional context

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:17 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
ashique-perumbavoorcommented, May 19, 2021

@Canato Okay I think I can reproduce it because I had the issue in the past. I will look into it after a few days😊

1reaction
Taogo-Hugocommented, Apr 29, 2021

Hi @Canato, I think this is enough, thank!

I try to use like the Glide library, want to load file path from getUriFilePath() into ImageView

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
            CropImage.ActivityResult result = CropImage.INSTANCE.getActivityResult(data);
            if (resultCode == Activity.RESULT_OK) {

// Is work
//                Uri resultUri = result.getUriContent();
//                Glide.with(this).load(resultUri).into(imageView); 

// Are the first cropped pictures
                File file = new File(result.getUriFilePath(this));
                Glide.with(this).load(file).into(imageView);
            } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {

            }
        }
    }

Sample video

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting uriContent as null in CropImageView.CropResult ...
For getting Cropped result I have used async method cropImageView.getCroppedImageAsync(), which gives me result in Bitmap but uriContent is Null ...
Read more >
Unable to continue after cropping a image in CropActivity
When you press the crop button and it comes back to the previous activity without crashing means it returns the data correctly, you...
Read more >
Error while cropping image - WordPress.org
I am getting the following error whenever I try to crop any image while uploading the header image: 'There has been an error...
Read more >
ImagePicker - Expo Documentation
expo-image-picker provides access to the system's UI for selecting images and videos from the phone's library or taking a photo with the camera....
Read more >
How to change the uri of an image with the uri of the cropped ...
Hello everyone I am cropping a photo but when I go to perform OCR the function still uses the full scale image and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found