Convert .9 images to png format in Android

Reference for this article: https://www.cnblogs.com/lixiangyang521/p/11060887.html

Why conversion is needed

Many times, we will use some icons that need to be stretched in projects, such as dialog boxes, labels, etc. Some of them can be solved by directly drawing the drawable.xml file, while others require the UI to draw the corresponding .9 diagram. , and then we can store the corresponding image in our local resource library, but this has two problems: first, it will increase the size of the apk; second, if the image resource is not fixed, the UI needs to be updated frequently ( For example, QQ member bubble box), then this will cause the problem of frequent resource replacement.
To solve these two problems, our solution is to put the resource image on the server, but if you directly put the .9 image and use the glide framework to load it, an error will be reported, then we need to convert the .9 image into a png image, and the conversion The after effect is the same as the original effect.

Conversion steps

1. Preparation

Since it is conversion, then we definitely need a .9 picture and the corresponding conversion tool. The conversion tool is build-tools/28.0.3(version, here is an example, this version is not necessarily required)/aapt.exe in the sdk

2. Start conversion

The use of the conversion tool needs to be coordinated with the command, so we need to enter the command through cmd:

Enter cmd and enter the folder corresponding to the tool

Then enter the command:

single conversion

aapt s -i [path to .9 image] -o [path to output file, including name and suffix]

example:aapt s -i D:\baigui.9.png -o D:\baigui2.png

Batch conversion

aapt c -S inputDir -C outputDir
inputDir is the original .9 picture folder, outputDir is the output folder

Suggestion: It is best to create two new folders to store the .9 pictures and output files respectively to avoid confusion.

Summarize

Here is the file description, which may be a bit abstract. You can go here to view the original text, which has detailed picture descriptions.

Guess you like

Origin blog.csdn.net/qq_39734865/article/details/96997104