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

Cut break, TransformImageView: onFailure: setImageUri #669

Open liukefu2050 opened 4 years ago

liukefu2050 commented 4 years ago

Do you want to request a feature or report a bug? bug What is the current behavior? There was an error when cutting. I don't know why. I chose the photo taken by my mobile phone and reported an error It's normal to download pictures from the Internet What is the expected behavior? There was an error when cutting. I don't know why. I chose the photo taken by my mobile phone and reported an error If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. check out my code:https://github.com/shijingsh/RxGalleryFinal run sample chose the photo taken by your phone Please attach any image files, URL and stack trace that can be used to reproduce the bug. E/TransformImageView: onFailure: setImageUri java.lang.IllegalArgumentException: Bounds for bitmap could not be retrieved from the Uri: [file:///storage/emulated/0/Pictures/1593499654172.jpg] at com.yalantis.ucrop.task.BitmapLoadTask.doInBackground(BitmapLoadTask.java:104) at com.yalantis.ucrop.task.BitmapLoadTask.doInBackground(BitmapLoadTask.java:36) at android.os.AsyncTask$3.call(AsyncTask.java:378) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:919) Which versions of uCrop, and which Android API versions are affected by this issue? Did this work in previous versions of uCrop?

v2.2.5

liukefu2050 commented 4 years ago

It's not about ucrop.I have solved the problem and recorded it here, because there is a problem with the code of taking photos, and there is no permission to set

like this

                //This sentence is very important
                captureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                //Getting URI using fileprovider7
                pictureUri = FileProvider7.getUriForFile(this.getActivity(), fileImagePath);

The complete code: check out my code:https://github.com/shijingsh/RxGalleryFinal I hope I can help some people

      boolean b = PermissionCheckUtils.checkCameraPermission(mMediaActivity, requestStorageAccessPermissionTips, MediaActivity.REQUEST_CAMERA_ACCESS_PERMISSION);
        if (b) {
            boolean image = mConfiguration.isImage();

            Intent captureIntent = image ? new Intent(MediaStore.ACTION_IMAGE_CAPTURE) : new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
            if (captureIntent.resolveActivity(context.getPackageManager()) == null) {
                Toast.makeText(getContext(), R.string.gallery_device_camera_unable, Toast.LENGTH_SHORT).show();
                return;
            }
            if(mConfiguration.isMultipleShot() && image){
                captureIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
            }

            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss", Locale.CHINA);
            String filename = String.format(image ? IMAGE_STORE_FILE_NAME : VIDEO_STORE_FILE_NAME, dateFormat.format(new Date()));

            File fileImagePath = new File(mImageStoreDir, filename);
            mImagePath = fileImagePath.getAbsolutePath();

            Uri pictureUri = null;

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                //This sentence is very important
                captureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                //Getting URI using fileprovider7
                pictureUri = FileProvider7.getUriForFile(this.getActivity(), fileImagePath);
            } else {
                pictureUri = Uri.fromFile(fileImagePath);
            }

            captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri);        
            if(!image){
                captureIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, mConfiguration.getVideoQuality());
            }

            startActivityForResult(captureIntent, TAKE_IMAGE_REQUEST_CODE);
        }
usama1050 commented 3 years ago

Resolved this issue after adding android:requestLegacyExternalStorage="true" in my Manifest.

chanhbc commented 3 years ago

I received a similar error. After retrieving the photo from the gallery I got Uri but Ucrop was stopped. You can add "android: requestLegacyExternalStorage =" true "in AndroidManifest.xml". But Google has restricted this permission on Android 11 devices and advised to remove it. So I debugged and edited his library a bit. Class: BitmapLoadTask.java. I noticed an error when granting READ_EXTERNAL_STORAGE permission, if not then the app works fine. So I deleted this part, although I don't know why he should be. From Line 174 to 184 image

saymumsany commented 2 years ago

I am facing this issue while crop the image. I am using com.github.yalantis:ucrop:2.2.8 . I am facing this issue in Xiaomi Redmi note 8A device and some Realme devices.

2022-04-03 14:26:00.332 23053-23053/com.apps.main E/TransformImageView: onFailure: setImageUri java.lang.IllegalArgumentException: Bounds for bitmap could not be retrieved from the Uri: [content://apps.main.provider/images/JPEG_20220403_142558_4239916797258029201.jpg] at wb.b.b(SourceFile:111) at wb.b.doInBackground(SourceFile:36) at android.os.AsyncTask$3.call(AsyncTask.java:378) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:919)