源代码
# -*- 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()
##运行文章来源:https://www.toymoban.com/news/detail-739495.html
python3 gen.py
文章来源地址https://www.toymoban.com/news/detail-739495.html
到了这里,关于Python 生成Android不同尺寸的图标的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!