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 !
Related
I got Lottie files from the designer and it contains png files.
The size are small. However, it seems low quality. And I added it into the view and built and launched my app and It looks blurry.
What I guess is, The parts Lottie can't vectorize remains as PNG files. And the others are in json.
Is that right?
If yes, The second question is, Lottie has some functionality to use PNG files like vectorized image source with its connected json file?
I need to correspond the device screens(resolutions). Does json+PNG can correspond all the resolutions or not? If it is not, Should I separate them and for the PNG part, I need mdpi, hdpi, xdpi, ... ones like in Zeplin?
Lottie Library supports PNG files but I think your designer made a mistake, it's better to use Vectors ONLY Lottie cannot convert PNG images into the vectors, so you have to include them into your project
Lottie has some functionality to use PNG files like vectorized image source with its connected JSON file?
NO
Lottie doesn't make the PNG vectorized. However, your animation will run normally just like it's demo, there is no problem with functionality. Since it is not vectorized, the image can look blurry or broken.
I need to correspond the device screens(resolutions). Does json+PNG can correspond all the resolutions or not? If it is not, Should I separate them and for the PNG part, I need mdpi, hdpi, xdpi, ... ones like in Zeplin?
NO
I think you will be in trouble with multiple screen resolutions, after all, the PNG is just a PNG
For using images in my android application, I will use this technique :
I put all of my images into "drawable-xhdpi" folder to let the application scale the images down for various resolutions.
I wondering does it make sense ? What is your experiences ?
Thanks for sharing...
UPDATE:
Maybe this method is a nice one, But an another question raises here which is :
Does this technique causes a memory leak for ldpi devices? I don't want to solve the problem by using svg images, Suppose there are bit-mapped images which are not vector based and there is no choice or alternative to replace. using a bitmap is the only choice.however using this method has a cons which will affect the overall layout and in some devices the position of relevant controls will be changed.
While this will work, it's not ideal and not recommended. Please look at the official documentation for Supporting Multiple Screens:
Although the system performs scaling and resizing to make your application work on different screens, you should make the effort to optimize your application for different screen sizes and densities. In doing so, you maximize the user experience for all devices and your users believe that your application was actually designed for their devices—rather than simply stretched to fit the screen on their devices.
And:
Provide different bitmap drawables for different screen densities
By default, Android scales your bitmap drawables (.png, .jpg, and .gif files) and Nine-Patch drawables (.9.png files) so that they render at the appropriate physical size on each device. For example, if your application provides bitmap drawables only for the baseline, medium screen density (mdpi), then the system scales them up when on a high-density screen, and scales them down when on a low-density screen. This scaling can cause artifacts in the bitmaps. To ensure your bitmaps look their best, you should include alternative versions at different resolutions for different screen densities.
You can use the File / New / Image Asset to automatically generate the scaled assets.
Best way is use SVG files instead of PNG and import them to project in Androis studio: File -> New -> Vector Asset or use icon fonts like https://github.com/mikepenz/Android-Iconics
SVG file is inserted to drawable and converted to PNG files while compile time for back compatibility, but you don't need to maintain a pack of files, but just one vector file.
I use inkscape to create svg drawings and also to convert to png I think the conversion has better quality and supports all svg functions.
With inkscape and a script it is possible to do batch conversion, I have not tried it yet, until now I convert them one by one
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.
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.
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.