OutOfMemory exception: image compression will reduce heap size?

I have long wanted to ask about this. I create this game where I draw a very large background. But the problem (of course), when I add more elements to the game, I get an OutOfMemory exception.

What I wanted to ask would compress the image, reducing heap size allocation? For example, my PNG background (3000 x 2000 pixels in pixels) is about 1.5 MB. After a series of PNG compression (via software tools such as TinyPNG and PNGGauntlet) the background size was sharply reduced to 712 KB. The compressed image here is still the same size as the original (3000 to 2000).

Will the heap size distribution of the original background size (1.5 MB) be the same as the compressed (712 KB) one?

+5
source share
1 answer

Answer: yes, compressed and uncompressed images occupy the same amount of memory - they ultimately simply end with a grid of values ​​of R, G, B (, A). The only time you could save some memory if you use a compression form that the GPU supports (for example, S3TC compression for OpenGL textures).

Compression reduces two things: the size of the file on disk and the amount of I / O time required to download the file (although this saving can be offset by the decompression process).

However, you can see the image loading in a raster type other than ARGB_8888 (for example, RGB_565) - this will reduce the amount of memory needed to store the raster image (but the image quality will be reduced).

+1
source

All Articles