App: [MEDIUM] [Android] Large images crashing the App - 'Canvas trying to draw too large'
Problem
The Android app crashes due to a Canvas OOM exception when the image dimensions are extremely large. This has been fixed in the past, but we recently switched to Expo Image so I believe we’ll need a new solution.
FATAL EXCEPTION: main
Process: com.expensify.chat, PID: 28882
java.lang.RuntimeException: Canvas: trying to draw too large(149730560bytes) bitmap.
at android.graphics.RecordingCanvas.throwIfCannotDraw(RecordingCanvas.java:266)
at android.graphics.BaseRecordingCanvas.drawBitmap(BaseRecordingCanvas.java:94)
at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:549)
at android.widget.ImageView.onDraw(ImageView.java:1446)
at expo.modules.image.ExpoImageView.onDraw(ExpoImageView.kt:204)
at android.view.View.draw(View.java:23900)
at expo.modules.image.ExpoImageView.draw(ExpoImageView.kt:200)
at android.view.View.updateDisplayListIfDirty(View.java:22767)
at android.view.View.draw(View.java:23631)
at android.view.ViewGroup.drawChild(ViewGroup.java:4559)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4320)
at android.view.View.updateDisplayListIfDirty(View.java:22758)
at android.view.View.draw(View.java:23631)
at android.view.ViewGroup.drawChild(ViewGroup.java:4559)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4320)
We have spent time on different image libraries and many related issues, and I am now trying to combine our current issues and resolve the remaining canvas OOM exception.
- Share a large image similar to this
- Attempt to view the image as either a receipt upload or a regular image attachment
Solution
Collect all past attempts, recent merged PRs, and determine the best path forward for resolving the crash:
- Here’s where we merged Expo-Image
- Here was a prior attempt to fix the image in
react-native-fast-image - Another PR which attempted to fix the issue with an upstream react-native-fast-image PR
- We introduced AttachmentGallary as an improvement to image scaling and a replacement to
ImageZoom
Next question: Do we need a fix in Expo Image?
About this issue
- Original URL
- State: closed
- Created 6 months ago
- Comments: 19 (19 by maintainers)
That sounds good, but let’s first see what Expo team says 👍
Nice stuff! Sorry for not replying fast enough 🥲 I think this solution is valid, as long as
expo-imagetakes care of the downsampling