Python 生成Android不同尺寸的图标

源代码

# -*- coding: utf-8 -*-
import sys
import os
import shutil
from PIL import Image

def 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 = s
        img = icon.resize((size//2,size//2))
        oFolder = folder
        if 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

Python 生成Android不同尺寸的图标_第1张图片

你可能感兴趣的:(python,android,开发语言)