I'm writing game with a large amount of PNG pictures. All worked fine. Than I added new activity with WebView
and got memory shortage. After that I made some experiment - replace game PNG images with ones that just fully filled with some color. As result memory shortage had gone.
But I suppose that Bitmap
internally hold each pixel separately so such changes should have no effect. Maybe this because of initial images have alpha channel and my test images have not it?
But actually question is: Will decreasing PNG images files sizes make some effect on decreasing usage of VM application heap or not?
You should look into the bitmap configuration you're decoding your images into. I don't know specifically what the configuration files mean, but for example, you can decode into ARGB_8888 or simply RGB_565. RGB_565 uses less memory, presumably because it doesn't have an alpha (transparency) channel and uses less bits for each colour. In your case what's problably happening is that the simple images are being decoded into RGB_565 whereas the more complicated ones were decoded into ARGB_8888.
The way to change which configuration is being used is during the decoding of your image files, as follows:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.RGB_565;
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon, options);
Experiment with that and see if it helps. Doing that certainly helped me with my game.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With