expo: expo-image-manipulator fails to decode bitmap on Android

Summary

Calling ImageManipulator.manipulateAsync on Android fails with java.lang.Exception: Loading bitmap failed

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

managed

What platform(s) does this occur on?

Android

SDK Version (managed workflow only)

40.0.1

Environment

Expo CLI 4.2.1 environment info: System: OS: macOS 10.15.7 Shell: 5.7.1 - /bin/zsh Binaries: Node: 12.16.2 - /usr/local/bin/node Yarn: 1.19.1 - /usr/local/bin/yarn npm: 6.14.4 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Managers: CocoaPods: 1.8.3 - /Users/ShaneMcNamara/.rvm/gems/ruby-2.2.0/bin/pod SDKs: iOS SDK: Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2 IDEs: Android Studio: 4.0 AI-193.6911.18.40.6821437 Xcode: 12.4/12D4e - /usr/bin/xcodebuild npmPackages: expo: ^40.0.0 => 40.0.1 react: 16.13.1 => 16.13.1 react-dom: 16.13.1 => 16.13.1 react-native: https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz => 0.63.2 react-native-web: ~0.13.12 => 0.13.18 npmGlobalPackages: expo-cli: 4.2.1 Expo Workflow: managed

Reproducible demo or steps to reproduce from a blank project

tbd

I’m trying to create image previews using ImageManipulator.manipulateAsync as follows:

const { uri } = await ImageManipulator.manipulateAsync(
   path, // `${FileSystem.cacheDirectory}photos/${filename}`;
   [{ 
      resize: {
         height:Layout.IMAGE_PREVIEW_SIZE, // 60
      } 
   }],
   {
      compress:0,
      format:ImageManipulator.SaveFormat.PNG
    }
);

I receive the following error in my console:

Error Could not get decoded bitmap of file:///data/user/0/host.exp.exponent/cache/ExperienceData/myapp/photos/myfile: java.lang.Exception: Loading bitmap failed

This seems to only happen for a specific photo, which happens to be the largest of the bunch (16.5 MB). manipulateAsync is successful with the same file on iOS and with all the smaller files on Android (up to ~7MB). Is there a size limit for this method?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 5
  • Comments: 18 (11 by maintainers)

Commits related to this issue

Most upvoted comments

@BrodaNoel I was having the same error on an old phone. I also noticed something similar with another library (react-native-image-resizer), it was throwing the following error: “Unable to resize image. Most likely due to not enough memory”. So I did what they suggested in this github issue: https://github.com/bamlab/react-native-image-resizer/issues/235

After adding android:largeHeap=“true” to my AndroidManifest.xml, both react-native-image-resizer and expo-image-manipulator started working again. It’s worth noting that my project is bare expo, not managed. I don’t know if expo users have access to the AndroidManifest, you may need to do something else in your case.