react-native-image-crop-picker icon indicating copy to clipboard operation
react-native-image-crop-picker copied to clipboard

Android only: "Cannot find image data" crashes on webp images

Open Pauly24 opened this issue 4 years ago • 9 comments

Version

Tell us which versions you are using:

  • react-native-image-crop-picker v0.32.2
  • react-native v0.62.0

Platform

Issue only happens on Android, iOS working as expected.

Expected behaviour

When selecting an image from openPicker it should return without error

Actual behaviour

After calling ImagePicker.openPicker and selecting the image, it gives below error

Cannot find image data
    at Object.promiseMethodWrapper [as openPicker] (NativeModules.js:103)
    at HomeScreen.loadImageGallery (homescreen.js:107)
    at Object.onPress (homescreen.js:75)
    at onAction (Alert.js:92)
    at MessageQueue.__invokeCallback (MessageQueue.js:472)
    at MessageQueue.js:136
    at MessageQueue.__guard (MessageQueue.js:373)
    at MessageQueue.invokeCallbackAndReturnFlushedQueue (MessageQueue.js:135)
    at RNDebuggerWorker.js:2

Steps to reproduce

  1. Install module

  2. Run this code

    ImagePicker.openPicker({
      width: 300,
      height: 400,
      cropping: true,
    }).then(image => {
      console.log(image);
    }).catch(e => console.log('er', e));

Attachments

I have added android:requestLegacyExternalStorage="true" so my manifest looks like this

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.isofit">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="com.android.vending.BILLING" />

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme"
      android:requestLegacyExternalStorage="true">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    </application>

</manifest>

My build script is

buildToolsVersion = "29.0.3"
minSdkVersion = 16
compileSdkVersion = 29 //28
targetSdkVersion = 29

Any help is greatly appreciated, thank you.

EDIT: It turns out that this only happens when a *.webp image is selected on Android, I'm happy to exclude them but there is no way to prevent the user from selecting a webp image so the app continues to crash unexpectedly.

Pauly24 avatar Aug 07 '20 05:08 Pauly24

How did you solve it? How can I exclude *.webp images?

ehijon avatar Sep 03 '20 15:09 ehijon

I haven't solved it. The issue still exists.

Pauly24 avatar Sep 04 '20 02:09 Pauly24

and will be... because of https://github.com/Yalantis/uCrop/issues/166#issuecomment-245606245 and https://github.com/Yalantis/uCrop/issues/624

oxyii avatar Sep 30 '20 23:09 oxyii

A possible workaround is to call openPicker or openCamera without the cropping enabled and to then call openCropper with the picked image, since this library already converted it at that point.

birgernass avatar May 14 '21 16:05 birgernass

A possible workaround is to call openPicker or openCamera without the cropping enabled and to then call openCropper with the picked image, since this library already converted it at that point.

really works,this helped a lot, thanks

chuhangyu avatar Jun 02 '21 09:06 chuhangyu

I have the same error, the application crashes when the user chooses a .webp image.

mauriciogallego avatar Dec 17 '21 23:12 mauriciogallego

A possible workaround is to call openPicker or openCamera without the cropping enabled and to then call openCropper with the picked image, since this library already converted it at that point.

perfect solution, thanks very much. I fixed the samilar bug "cannot find image data" on xiaomi、HONOR device when selecting some pic to crop by the way ImagePicker.openPicker({ cropping: true... }).

use as below

let selectedImage = await ImagePicker.openPicker({
      mediaType: "photo",
      cropping: false,
    });
console.log('selectedImage:::', selectedImage);
let croppedImage = await ImagePicker.openCropper({
  path: selectedImage.path,
  width: props.width, 
  height: props.height, 
})
console.log('croppedImage:::', croppedImage);

wustzhy avatar Jan 16 '23 03:01 wustzhy

A possible workaround is to call openPicker or openCamera without the cropping enabled and to then call openCropper with the picked image, since this library already converted it at that point.

perfect solution, thanks very much. I fixed the samilar bug "cannot find image data" on xiaomi、HONOR device when selecting some pic to crop by the way ImagePicker.openPicker({ cropping: true... }).

use as below

let selectedImage = await ImagePicker.openPicker({
      mediaType: "photo",
      cropping: false,
    });
console.log('selectedImage:::', selectedImage);
let croppedImage = await ImagePicker.openCropper({
  path: selectedImage.path,
  width: props.width, 
  height: props.height, 
})
console.log('croppedImage:::', croppedImage);

what if i opening shared image directly to openCropper??

SMARTMICROWORLD avatar Nov 20 '23 10:11 SMARTMICROWORLD

A possible workaround is to call openPicker or openCamera without the cropping enabled and to then call openCropper with the picked image, since this library already converted it at that point.

perfect solution, thanks very much. I fixed the samilar bug "cannot find image data" on xiaomi、HONOR device when selecting some pic to crop by the way ImagePicker.openPicker({ cropping: true... }). use as below

let selectedImage = await ImagePicker.openPicker({
      mediaType: "photo",
      cropping: false,
    });
console.log('selectedImage:::', selectedImage);
let croppedImage = await ImagePicker.openCropper({
  path: selectedImage.path,
  width: props.width, 
  height: props.height, 
})
console.log('croppedImage:::', croppedImage);

what if i opening shared image directly to openCropper??

Thanks you very much. you have saved me.

phucph1998 avatar Dec 29 '23 06:12 phucph1998