I am developing an android app that decodes a jpeg file and draws the bitmap on the canvas with canvas.drawBitmap(). I am decoding the jpeg into a bitmap using BitmapFactory.decodeStream().
Everything works fine when I work with images of resolutions such as 2560x1536. Recently, I did a stress test and tried to open a really big jpeg of resolution 5400x3600. My app crashed with error "java.lang.OutOfMemoryError".
Here is the stack trace:
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:720)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:696)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:734)
...
It is understandable since that is a large image and a decoded bitmap uses a lot of memory.
However, what I am trying to understand is on the same phone, if I use the gallery app, the gallery app can display the same big image without any problems.
On the same phone, if I also try to open the same big image with some picture editing tool that I think should also decode the jpeg into a bitmap, then everything works fine as well. It takes a bit more time for those apps to display the image, but the image is loaded and drawn on the screen.
I am trying to understand what I could be doing wrong and differently compared to those other apps ?