Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] - Getting uriContent as null in CropImageView.CropResult #180

Closed
cybertronjc opened this issue Aug 13, 2021 · 14 comments · Fixed by #185
Closed

[BUG] - Getting uriContent as null in CropImageView.CropResult #180

cybertronjc opened this issue Aug 13, 2021 · 14 comments · Fixed by #185
Assignees

Comments

@cybertronjc
Copy link

🚨🚨 Before open the ticket please check if you can reproduce the bug in the sample code

  • Lib Version [3.2.2]

Describe the bug
I have created a custom activity which includes CropImageView in my XML. Using DataBinding.
I am passing uri to cropImageView.setImageUriAsync(incomingUri) and getting uri in cropImageView.setOnSetImageUriCompleteListener().

For getting Cropped result I have used async method cropImageView.getCroppedImageAsync(), which gives me result in Bitmap but uriContent is Null.

Expected behavior
I should get the uriContent so that I can pass the uri back to fragment where I want to show the Cropped Image.

Media
When I click on the Center Check button I am calling cropImageView.getCroppedImageAsync()
android-image-cropper-issue

Smartphone (please complete the following information):

  • Device: [Xiomi A3, Android 11]
  • OS: [Android 11]

Additional context
Add any other context about the problem here.

@Canato
Copy link
Member

Canato commented Aug 13, 2021

Hey @cybertronjc thanks for the detailed issue, helps a lot to understand your case.

This is our sample code using crop image view

Maybe it can help.

You said:

cropImageView.getCroppedImageAsync(), which gives me result

But this method should no return any result.

did you override fun onCropImageComplete(view: CropImageView, result: CropResult) ?

Hope this piece of code can help:

private fun handleCropResult(result: CropResult?) {
        if (result != null && result.error == null) {
            val imageBitmap =
                if (binding.cropImageView.cropShape == CropImageView.CropShape.OVAL)
                    result.bitmap?.let { CropImage.toOvalBitmap(it) }
                else result.bitmap
            context?.let { Log.v("File Path", result.getUriFilePath(it).toString()) }
            SCropResultActivity.start(this, imageBitmap, result.uriContent, result.sampleSize)
        } else {
            Log.e("AIC", "Failed to crop image", result?.error)
            Toast
                .makeText(activity, "Crop failed: ${result?.error?.message}", Toast.LENGTH_SHORT)
                .show()
        }
    }
    ```

@cybertronjc
Copy link
Author

Hey @Canato
I really appreciate the quick response.

this is the centered check image (refer screenshot). On click of this check image I am calling cropImageView.getCroppedImageAsync(). and receiving the result in onCropImageComplete.

okayImg.setOnClickListener {
           viewBinding.progressCircular.visibility = View.VISIBLE
           cropImageView.getCroppedImageAsync()

       }

I have implemented the override function onCropImageComplete like this.

cropImageView.setOnCropImageCompleteListener(object : CropImageView.OnCropImageCompleteListener {
            override fun onCropImageComplete(
                view: CropImageView,
                result: CropImageView.CropResult
            ) {
                viewBinding.progressCircular.visibility = View.GONE
                handleCropResult(result)
            }

        })
private fun handleCropResult(result: CropImageView.CropResult) {
        if (result.isSuccessful && result.error == null) {
//            val imageBitmap =
//                if (viewBinding.cropImageView.cropShape == CropImageView.CropShape.OVAL)
//                    result.bitmap?.let { CropImage.toOvalBitmap(it) }
//                else result.bitmap
            Log.v("File Path",result.getUriFilePath(this).toString() )
            Log.v("File result", "result : ${result.bitmap.toString()} , ${result.cropRect.toString()}, ${result.uriContent.toString()} , :bimap , ${result.error}" )

            logger.d(ImageCropFragment.logTag, "cropped result  : ${result.uriContent.toString() }")
            //SCropResultActivity.start(this, imageBitmap, result.uriContent, result.sampleSize)
            val resultIntent = Intent()
            resultIntent.putExtra("croppedImage", result.uriContent.toString())
            setResult(Activity.RESULT_OK, resultIntent)
            finish()

        } else {
            Log.e("AIC", "Failed to crop image", result?.error)
         logger.d(ImageCropFragment.logTag, "Failed to crop image", result?.error.toString())

         Toast.makeText(this@ImageCropActivity, "Crop failed: ${result?.error?.message}", Toast.LENGTH_SHORT)
        }
    }

Still I get the uriContent as null but I am receiving the Bitmap which I don't want to use. check the debug screenshot below
Screenshot 2021-08-13 at 9 55 10 PM

@Canato
Copy link
Member

Canato commented Aug 13, 2021

Interesting bug, we need to take a look. What are you receiving from the UriFilePath?

And can you reproduce on the sample code?
Maybe is the device?

@cybertronjc
Copy link
Author

cybertronjc commented Aug 13, 2021

Hey @Canato
Thanks for the response.
I am receiving result?.getUriFilePath(this) as null as well.

Allow me some time to reproduce it on the sample code.
Let me also try this on another device. This maybe because of Android 11 introduced scoped storage (not sure).

@Canato
Copy link
Member

Canato commented Aug 13, 2021

I fix the scope storage last November. But let's keep investigating, I'm going for the weekend, but back on Monday

@cybertronjc
Copy link
Author

Hey @Canato
I have reproduced the bug on the sample code in crop_image_view.
I am attaching a screenshot of the debug which shows uriContent value null on breakpoint line number 181 in SCropImageViewFragment.kt
The result?.getUriFilePath(this) is also null. Let's investigate more on Monday. thanks
Screenshot 2021-08-14 at 12 41 46 AM

@Canato
Copy link
Member

Canato commented Aug 16, 2021

Found it, is not exactly a bug, but something this library need improvement, since we come from Java, we have strange stuff and not so good documentation, like CropImageView has 3 methods getCroppedImageAsync the problem, is that any of it will give you a uriContent value as return. Just bitmap.

For getting uri you would need to use saveCroppedImageAsync method. This receive the uri so it know where to save the cropped image.

The library activity CropImageActivity create it own outputUri. This is the value that the library return later
(what make no sense... you need to pass the uri and will receive is same value later, but now we saved something on it)

For sure something that need refactor @@.

@Canato
Copy link
Member

Canato commented Aug 16, 2021

Besides the fact we can use without any change, the code can be refactor and improve.

I'm working on this here: #185

Something still wrong, so is a draft by now.

@cybertronjc
Copy link
Author

cybertronjc commented Aug 18, 2021

Hey @Canato
Sorry for the delay.
Previously I was saving the bitmap and then passing the uri, in that case the image was clear when I clicked image from camera, but when I selected the image from gallery it didn't give me the bitmap., the bitmap was null.
I am using the updated PR code and now when I am passing the uriContent , the image is blurred.
After using the latest PR code, the bitmap is null in every case and uriContent is blurred image.
Any solution for that?

@Canato
Copy link
Member

Canato commented Aug 18, 2021

Any solution for that?

Hey @cybertronjc the PR is WIP state, not ready yet =D

@cybertronjc
Copy link
Author

Cool, No worries. As of now I have changed the default compression format to PNG. After that I am not getting the blurred image. thanks

@Avishek1989
Copy link

Hey @Canato , when this will be fixed? I'm in the middle of the development process, suffering with same bug.

@cybertronjc
Copy link
Author

@Avishek1989 Hi I was also in the development process. I imported the library as a module and changes the files which @Canato has updated in the PR.

@Canato
Copy link
Member

Canato commented Aug 19, 2021

Hey @Avishek1989 welcome =D

Hey @Canato , when this will be fixed? I'm in the middle of the development process, suffering with same bug.

Important to make clear that I don't win anything with this library, I just handover the project because was without update for too long and is very useful. That said I do my best to fix the bugs and add features when I have time. But a lot of important contributions come from the community it self. Sadly I cannot answer you with a deadline so I don't commit to something I may not be able to keep. I mostly need to focus on my job that pays me hahahah (but we have the sponsor button in this library for this)

In other vision, please feel free to open the PR and suggest a solution for the case, I will take the time to review and we merge, like many others did already, what make our lib better and better.

Right know you can do a workaround like I suggest here or can use the default library activity until this is improved.
Or use the PR, like @cybertronjc is doing, I just do not recommend this, since I cannot guarantee is stable =/.

I maybe have time this weekend after pack some boxes (I'm on moving houses process)

@Canato Canato self-assigned this Sep 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants