1
votes

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): Comparison of the emulator output of the same file 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.

1
user external libraries, either Picasso or Glide to load your images.Haider Saleem
Thanks Haider for your answer. As I am new to Android programming I have to admit that I do not understand why to use an external library for loading images. So far loading images has not been a problem for me if I put them into the mipmap directory. I can just directly refer to them in the XML code. What use is it to use Picasso or Glide?VanessaF
Well, you can put them in drawable-anydpi, but handling them with external libraries can serve you better as they offer other options too.Haider Saleem
Thanks Haider for your answer. What other options do I have when using such external libararies?VanessaF
you get options like, image center crop, center round and others. here's a link to glide github.com/bumptech/glideHaider Saleem

1 Answers

1
votes

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.