Issue
I have moved all my images from the folder mipmap to drawable because here it was said that the mipmap folder is only for app icons to lanch the app Mipmaps vs. drawable folders (the answer got 841 likes). However, when I now want to start my app I get an error message
FATAL EXCEPTION: main
Process: com.example.td.barapp, PID: 4331
java.lang.RuntimeException: Canvas: trying to draw too large(188394348bytes) bitmap.
at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:260)
In several realted questions people tell to store the pictures in different drawable folders (see Android : Understanding drawable folder) like drawable-xxhdpi or drawable-xxxhdpi.
Update: I was told by someone in this post (who later deleted his answers) to store the image (which has a size of 1,7 MB) in the folder drawable-anydpi. I did as he said but the outcome on the Emulator looks quite bad for an imageview (see screenshot): Then I moved the same file back into the folder mipmap-xxxhdpi and now it looks good again. So my question now is, whether it is also okay to have the image in the mipmap-xxxhdpi folder instead of the drawable folder? I'd be happy for every advice because I am quite confused now.
Solution
java.lang.RuntimeException: Canvas: trying to draw too large(188394348bytes) bitmap
This exception mainly because you are trying to display a big image ~ 188MB which will have a high resolution, and android puts limitation on that, This also reported here.
One of the reasons is to save device resources; for instance you might get java.lang.OutOfMemory
, so the system save device memory from that.
1, 2, 3 may guide you thoroughly on that.
Normally you can use a few mega bytes image in your app ~0-3MBs. Third party libraries like Glide & Picasso offer disk, network, & memory management techniques while displaying images on your ImageViews.
One of the options you may consider is to resize images before loading them, so can have look on this question.
Keep in mind that android puts limitaion on your apk file on the app store, so you need to minimize images for that reason, or load them from a back-end server.
As you mentioned, you can only put app icons in res\mipmap. And if you decide to put the images on your app, it's efficient to create them in different densities (hdpi, xhdpi, xxhdpi, xxxhdpi...), so they can match all the variety of device resolutions, and lets you avoid distorted images or high processing by android OS to match your image to the device resolution before displaying them.
Answered By - Zain
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.