The first two days and the boss of the company had no intention to talk about the work, but also the way to the apk thin body. Image compression is mainly done by SVG to reduce the size of the app. Let me explain in detail how to implement SVG image compression.
Advantages of SVG
- SVG can be read and modified by a lot of tools (such as Notepad), because the use of XML format definition, so can be directly opened as a text file, look at the data inside;
- SVG is smaller and more compressible than JPEG and GIF images, which is equivalent to preserving key data points, such as displaying a circle and needing to know the center and radius, so SVG saves only the center coordinates and the radius data. The usual bitmap we used is to save the corresponding number of pixels according to the image size in pixels, so the svg size is smaller;
- SVG is scalable, the usual use of the hollow will be stretched, compression will be deformed, and SVG format picture to save data to display, no matter how much, can not be distorted display;
- SVG images can be printed with high quality at any resolution;
- SVG can be amplified in the case of the image quality is not reduced;
- The text in the SVG image is optional and searchable (well suited for making maps);
- SVG can be run with Java technology;
- SVG is an open standard;
- The SVG file is purely XML;
Use of SVG installation software
First we need to install a software Vector Magic
After the download is complete, unzip it as follows:
In keygen 1.15, we double-click to copy the fifth line to crack, because I have cracked this side will not show.
Slimming test
Now let's do a test, first of all, the original size is as follows:
1.34M, this background map is actually very small. Next we compress him into XML through SVG.
We open the software directly and open the image we want to compress.
Direct Click fully Automatic, of course you can also set your own.
So we can compress it. Click Done and we'll save him.
Remember that the suffix is set to SVG because the default does not seem to be it. Compressed. We looked at the size, but it was 2/3 less.
Finally we put him in Android studio or INTELLJ idea.
Then there is this:
Achieve a true slimming
Watch out. It's just a test. Or with a large map test, so more obvious, I now use the previous Gobang to complete the test. First of all, look at my picture resources are adapted.
Let's look at the size of the apk before we lose weight.
A Gobang 7M function is not much, estimated also no one download put. Here's the point. We compress all the resources through SVG. This is what happens when you compress. Because SVG is an XML file, we do not need to do the matching.
Want to know the size after slimming. I'll give you the answers below.
Yes, a 6.89M app is the image compression into 3M. Of course, we can also use other forms of image compression, but a personal hobby.
The adaptation of SVG
First of all we need to know that SVG is only suitable for more than 5.0 of mobile phones, but we do adapt to generally be compatible with 4.0. Although 4.0 of users are now very few. My mother's cell phone is 6.0 ~ Though mine is 5.0~~~
When you create vector xml, the vector Asset Studio tool generates the corresponding PNG image in a different dpi file.
This will not play the advantage of Vector drawable. (because it's actually a PNG image) it's time to use the support library. Use of the support library is explained below.
Two ways to use vector drawable
1. If your project minimum API level is greater than or equal to 21
Normal use does not have any relationship
2, if your project minimum API level is less than 21, you still need to use the vector drawable, you must use the Support library 23.2 or higher.
Here are a few things to note:
(1) First, your activity must inherit appcompatactivity.
(2) Next in your module's Build.gradle according to the Android Plugin Gradle version of the different need to add these sentences:
For Android Plugin for Gradle 2.0 or higher need to add:
{ defaultConfig { vectorDrawables.useSupportLibrary = true }{ compile ‘com.android.support:appcompat-v7:23.2.0‘}
For Android Plugin for Gradle 2.0 The following is required:
android { defaultConfig { // Stops the Gradle plugin’s automatic rasterization of vectors generatedDensities = [] } // Flag to tell aapt to keep the attribute ids around aaptOptions { "--no-version-vectors" }}
(3) When applying vector drawable, you need to write this, add a imageview to apply a vector called Test drawable:
<ImageView android:id="@+id/img_animated_vector" android:layout_width="match_parent" android:layout_height="400dp" app:srcCompat="@drawable/test"/>
So that our fitness is really done.
Of course, there are many kinds of slimming for the APK, and I will introduce it in the range I know later.
Android apk skinny Dafa--svg Picture slimming