Yalantis / uCrop

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

java.lang.IllegalArgumentException: Bitmap could not be decoded from the Uri on version 2.2.5 #665

Open abedsh opened 4 years ago

abedsh commented 4 years ago

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

UCropActivity throws an exception and closes as soon as it opens onLoadFailure is triggered on TransofmrImageListener with the following exception message: java.lang.IllegalArgumentException: Bitmap could not be decoded from the Uri: [/data/user/0/com.app.test/cachetempImage] .

/data/user/0/com.app.test/cachetempImage is the provided destinationUri to Ucrop

What is the expected behavior?

UCropActivity shouldn't throw an exception

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

Update library to release 2.2.5, then open Ucrop with a source and cached destination url

 String localString = mActivity.getCacheDir().getAbsolutePath().concat("tempImage");
                UCrop.of(uri, Uri.parse(localString))
                        .withAspectRatio(16, 9)
                        .withMaxResultSize(maxWidth, maxHeight)
                        .start(mActivity);

Please attach any image files, URL and stack trace that can be used to reproduce the bug. java.lang.IllegalArgumentException: Bitmap could not be decoded from the Uri: [/data/user/0/com.app.test/cachetempImage]

Which versions of uCrop, and which Android API versions are affected by this issue? Did this work in previous versions of uCrop? android 7.0+ are affected, it works with previous the version of Ucrop (2.2.4)

nolan1024 commented 4 years ago

facing the same issue on Android 10

offlineprogrammer commented 4 years ago

Same issue on Android 10

offlineprogrammer commented 4 years ago

I fixed the issue by adding

android:requestLegacyExternalStorage="true"

to the manifest file Example

 <application
        android:name=".myApp"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        **android:requestLegacyExternalStorage="true"**
        android:theme="@style/Theme.myApp.myTheme">
jonasN5 commented 4 years ago

android:requestLegacyExternalStorage="true" is only a temporary measure since as of Android 11, this will be ignored. Any idea how to fix this?

hijamoya commented 4 years ago

Same issue here

Drjacky commented 3 years ago

Same issue on 2.2.6

Drjacky commented 3 years ago

If you want an Image Picker: https://github.com/Drjacky/ImagePicker/ And if you only need the fix for the mentioned issue: https://github.com/Drjacky/ImagePicker/blob/c8477e8ec5f8dc1bc86d0681dd5f58c40f9cff48/imagepicker/src/main/kotlin/com/github/drjacky/imagepicker/provider/CropProvider.kt#L114-L195

kemruto commented 1 year ago

My problem is happened on Android 13 (target SDK 33). Whenever I pick image from Gallery, then Ucrop activity will crash and log exception "Bitmap could not be decoded from the Uri" and requestLegacyStorage is deprecated on android 13. So here is the solution I found out: https://developer.android.com/about/versions/13/features#photo-picker