android png optimization - android

I have an app that using alot of .png fils, so to reduce app size I used PngOptimizer to optimze them. I was happy with the results and the file size of the png's went from alittle over 1mb to 300kb or so. but for some reason the app size only went down about about 100kb. doesn anyone know why? I would really like the file size reduction that I saw in my png files to carry over to my app size. please help

Your .APK application files already get compressed using the deflate algorithm. That is the same algorithm used by PNG files.
So the optimization you've done with the PngOptimizer has already been done to some extend by the .APK packer.
If you want to reduce the size of your application you should either reduce the color-depth of your PNG files (this helps a lot) or switch to .JPG files where possible. These could - depending on what the image contains - be smaller.

PNG files in res/drawable are automatically compressed using a palette if possible.
From http://developer.android.com/guide/topics/graphics/2d-graphics.html#drawables :
Note: Image resources placed in res/drawable/ 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.

Related

How much memory does a PNG image take up?

In my app, I am going to have 750 PNG images in my drawable folder. I am getting these images by taking screenshots from my computer.
When I built my app with all of the images, the app's file size was 140MB. Then, When I removed all of the images and rebuilt it, it went down to 2.75 MB.
Is there any way to reduce the amount of memory the PNG images take up? Would reducing the size of my screenshot be an effective solution?
I am going to have 750 PNG images in my drawable folder
Most likely, that is not what you want. res/drawable/ is a synonym for res/drawable-mdpi/. Your image will be resampled to match the density of the device, potentially taking up a lot more heap space. Usually, something like screenshots go in res/drawable-nodpi/, to indicate that the images should not be resampled based on density.
When I built my app with all of the images, the app's memory was 140MB. Then, When I removed all of the images and rebuilt it, it went down to 2.75 MB.
I am going to interpret this as meaning the size of the APK, which in turn controls the starting amount of disk space associated with your app. Please understand that Android does not have an "Application Manager", even though your specific device might have such an app.
Is there any way to reduce the amount of memory the PNG images take up? Would reducing the size of my screenshot be an effective solution?
If by "size" you mean "resolution", then that will reduce the file sizes of the PNG files and should reduce the file size of your APK.
As a now-deleted answer points out, you can also reduce the file size of the PNG files using tools like pngquant, that optimize the PNG in ways that your screenshot tool perhaps did not.
And, you can reduce the size of your APK by reducing the number of screenshots. How many of your users are really going to look at 750 screenshots? You might consider packaging a subset of those with the app, downloading additional ones as needed from some server.

For android development can I use JPG image instead of PNG image on image views?

The main purpose of this question is to know what is the best option to choose between PNG and JPG for android development considering the following scenarios
1) is it a good option to use jpg image as background?
2) Will .jpg image take more time to load compared to .png?
3) Will .jpg take more time for rendering/loading compare to .png?
I have seen big difference in image size when we are using png images.
One of my .png image size is 4.1 MBs and that same image with .jpg image format the size is reduced to 2.9MBs
Need suggestion from Experts specially.
Info: To reduce app size. i am still compressing images by using compress png and compress jpeg
Image size difference is huge. ie. 4.1 MBs png -> 2.9 MBs jpg after compressing it reduced to 654.6 KBs..
To set image as BACKGROUND i didn't found any issue...
It's just a question of quality and details.
Just for my opinion, for a big background resolution is better to use a JPG, if you don't need any transparency on the image, with the right compromise between quality and size of file,
PNG format is a lossless compression file format, which makes it a common choice for use on the Web. PNG is a good choice for storing line drawings, text, and iconic graphics at a small file size.
JPG format is a lossy compressed file format. This makes it useful for storing photographs at a smaller size than a BMP. JPG is a common choice for use on the Web because it is compressed. For storing line drawings, text, and iconic graphics at a smaller file size, GIF or PNG are better choices because they are lossless.
From:http://www.labnol.org/software/tutorials/jpeg-vs-png-image-quality-or-bandwidth/5385/
The main difference is image quality. The PNG format uses a lossless compression, while JPEG uses a lossy one optimized for photos. It depends what is shown on the image if JPEG is a valid alternative. In artificially generated images of geometric figures like logos the artifacts coming from JPEG compression can be easily seen.
It's a question of quality of the images. If you're ok with the loss of quality just use it instead.
A bitmap file is a .png, .jpg, or .gif file. Android creates a Drawable resource for any of these files when you save them in the res/drawable/ directory.

Drawable image type to minimize the apk size

In my app there are 180 images in drawable folder & I will display them at the background of textview covering the entire screen.
Android documentation states that Android supports bitmap files in a three formats: .png (preferred), .jpg (acceptable), .gif (discouraged).
It also states that 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.
I dont want the apk size to exceed 50 MB, Can *.png images minimize the apk size as compared to other extensions(.jpg,.gif)?
As you already read in the documentation, the images are already compressed a great deal. However, you might want to try other compression tools available to reduce the size of images.
It's generally a better idea to save images as jpegs rather than pngs. As pngs are bigger in size because of the alpha channel (transparency). Not always though. So, in case you dont need transparency in images it'd be a better idea to switch to jpegs.
I generally use this : https://tinypng.com/
Better you compress the .jpg files as much as possible, this should greatly reduce the size of your .apk file. And there is a tool such as Paint.NET and refer APK too It has great resizing options.
Yes, and this is from what i know from using photoshop,
here is a very well explanation of why to use each:
PNG vs. GIF vs. JPEG vs. SVG - When best to use?
it can help you reduce the apk size... honestly i think it would be best for you to download photoshop (even the 30 day ver.) and simply load and save and see to comparison yourself.

Where to place my drawable to maintain high-quality?

I am testing my Apps on Galaxy Note3, and while reading a book I found the below posted table, and the questions occurred to my mind are,
1)which folder should I use to maintain the drawable or it does not matter using any of them?
2)According to the table below, does placing my drawables in, for a example, ldpi folder cause it to be of low-quality?
You should paste your images with best resolution in drawable-hdpi. Android will automatically optimize it down to the required resolution according to the density of device.
Android documentation states that Android supports bitmap files in a three formats: .png (preferred), .jpg (acceptable), .gif (discouraged).
It also states that 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.
So, we should also care about the image type used !

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?
.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.
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.
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.
Do you use 9-patches for backgrounds? Also you can use imagemagick or anything similar to compress a batch or images.
Try and use ".png".
Use 9-patch images for backgrounds.
If you have title bars, headers with vertical gradients, always use 1-pixel width gradient images. This is a super saver.
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.
If u r supporting multiple devices, maintain different versions of the images only for those that are really necessary.

Categories

Resources