源代码
# -*- coding: utf-8 -*-
import sys
import os
import shutil
from PIL import Imagedef generateAndroidIcons():imageSource = 'icon.png'icon = Image.open(imageSource)sizes = [('android/drawable',512),('android/drawable-hdpi',72),('android/drawable-ldpi',36),('android/drawable-mdpi',48),('android/drawable-xhdpi',96),('android/drawable-xxhdpi',144),('android/drawable-xxxhdpi',192),('android/mipmap',512),('android/mipmap-hdpi',72),('android/mipmap-ldpi',36),('android/mipmap-mdpi',48),('android/mipmap-xhdpi',96),('android/mipmap-xxhdpi',144),('android/mipmap-xxxhdpi',192),]names = ['ic_launcher']for s in sizes:folder,size = simg = icon.resize((size//2,size//2))oFolder = folderif os.path.exists(oFolder):shutil.rmtree(oFolder)os.makedirs(oFolder)for name in names:oPath = oFolder+'/'+name+'.png'img.save(oPath, icon.format)print(oPath)generateAndroidIcons()
##运行
python3 gen.py