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

为君一笑 提交于 2019-12-23 07:31:36

问题


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?


回答1:


.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.



回答2:


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.




回答3:


Always use PNG (.png) images. And compress it online by uploading your images to

https://tinypng.com/

Simple and sober, always work. You are welcome. :)

There is also a better way to use AndEngine, it saves you from making layout for each phone. And there is no need to use different images for different dpi phones.




回答4:


Do you use 9-patches for backgrounds? Also you can use imagemagick or anything similar to compress a batch or images.




回答5:


  1. Try and use ".png".
  2. Use 9-patch images for backgrounds.
  3. If you have title bars, headers with vertical gradients, always use 1-pixel width gradient images. This is a super saver.
  4. If you manage to get hold of Photoshop, they have the option to save images for web/mobile devices. Helps in making really small sized images with good quality.
  5. If u r supporting multiple devices, maintain different versions of the images only for those that are really necessary.


来源:https://stackoverflow.com/questions/7913138/large-app-size-due-to-images-how-to-compress-png-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!