使用美图看看,做尺寸变换后,透明背景变成白色的。
使用PS来操作,比较麻烦。
使用PIL库和Python写一个简单尺寸缩小的程序。
为方便,把路径变量做了硬hardcode。
#coding: utf-8
from PIL import Image
import sys
import os
if __name__ == '__main__':
if len(sys.argv) == 2:
path = r"E:\MyExam\app\src\main\res"
file = sys.argv[1]
try:
im = Image.open(file)
_,name = os.path.split(file)
files = [{"size":72, "path":"drawable-xxhdpi"},{"size":48, "path":"drawable-xhdpi"},{"size":36, "path":"drawable-hdpi"},{"size":24, "path":"drawable-mdpi"}]
for f in files:
print(f)
file_2 = path + "\\" + f["path"] + "\\" + name
im_2 = im.resize((f["size"],f["size"]))
im_2.save(file_2, "PNG")
except Exception as e:
print(e)