Search code examples
androidimagebitmapscaleresolution

Memory Difference for Automatic Scale-Up vs. Larger Image with No Scale


I have a game with accidental occurrences of OutOfMemoryException when creating Bitmap.

For some resources I only use one image in the drawable folder (MDPI). That means there are no separate images for HDPI, XHDPI or XXHDPI.

Android up-scales them automatically when the resolution is higher.

My questions is: Is it more Memory efficient if I put inside the game initially upscaled images for each separate resolution - e.g. image for HDPI, image for XHDPI and relieve Android from the need to convert and rescale the Bitmap in memory, or is it better and more effiecent to use single image only for MDPI and Android to do the re-scale itself.

I think in that direction, because I don't know how much memory is needed internally for Android to re-scale the images when creating Bitmaps and if the Bitmap memory will be larger or smaller in each case. But it seems like a possible option.


Solution

  • In terms of efficiency and performance its almost always a better idea to provide scaled images instead of having Android to do it for you.

    With that being said: In Android- Auto-scaling instead of pre-scaling can be more CPU expensive, but uses less memory. Unless you don't change the the scale of the image within the same session then it should not be a problem.