Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Large app size due to images. How to compress .PNG images?

I am developing an app which has a lot of images to work on due to which the size of my app has become very large. I want to compress or something like that to reduce the size of app. Any idea?

like image 743
Khawar Raza Avatar asked Oct 27 '11 08:10

Khawar Raza


People also ask

Why is my PNG so large?

A PNG file saved in Truecolor is going to have a larger file size than one that is saved as Grayscale or Indexed-color. If an image is in black and white or only has a few colors, such as with a logo, it's a good idea to save it with the lowest color option.

How do I reduce the size of a PNG file on my phone?

Reduce PNG in Android Android has an app for everything. To reduce PNG file size in Android we are going to use a free app called Photoczip. This free app lets you compress, resize, and zip all your images. To start off, install Photoczip from Play Store and launch it.

Are PNG photos compressed?

In contrast, PNG files benefit from lossless compression. This means no data is lost when the image is compressed — the quality stays the same no matter how many times you edit and save the file.


2 Answers

.png-files which are placed in the res/drawable are automatically optimized when compiling your app:

Bitmap files may be automatically optimized with lossless image compression by the aapt tool during the build process. For example, a true-color PNG that does not require more than 256 colors may be converted to an 8-bit PNG with a color palette. This will result in an image of equal quality but which requires less memory. So be aware that the image binaries placed in this directory can change during the build. If you plan on reading an image as a bit stream in order to convert it to a bitmap, put your images in the res/raw/ folder instead, where they will not be optimized.

That being said, you have some more options to try. There is a good talk on this topic from Google I/O 2016 called "Image Compression for Android Developers", which outlines the possibilities, explains their up and downsides and gives some general best practices.


If the size of your application is to high to be published on the market, you'll can either

  • ship your app without the images and load them from the internet to the phones SD-card when the app is first started
  • Use Androids own APK Extension Files, which is basically the same but you don't have to do everything yourself.
like image 167
Lukas Knuth Avatar answered Nov 04 '22 09:11

Lukas Knuth


Use pngquant or posterizer to reduce size of PNG images (these tools are lossy, but give significant savings).

You can also optimize them with PNGOUT, which is one of the best lossless optimizers.

I've written Mac GUI for those.

like image 24
Kornel Avatar answered Nov 04 '22 09:11

Kornel