41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
from PIL import Image
|
|
import os
|
|
|
|
# 新的图片路径
|
|
new_image_path = r"e:\project\flutter\f3\flutter_application_2\assets\IMG_20260402_172628.png"
|
|
|
|
# 安卓端图标目录
|
|
android_res_dir = r"e:\project\flutter\f3\flutter_application_2\android\app\src\main\res"
|
|
|
|
# 安卓端图标尺寸配置 (density: (width, height))
|
|
android_sizes = {
|
|
"mdpi": (48, 48),
|
|
"hdpi": (72, 72),
|
|
"xhdpi": (144, 144),
|
|
"xxhdpi": (96, 96),
|
|
"xxxhdpi": (192, 192),
|
|
}
|
|
|
|
try:
|
|
# 打开新图片
|
|
with Image.open(new_image_path) as img:
|
|
print(f"新图片尺寸: {img.size}")
|
|
|
|
# 为每个密度生成图标
|
|
for density, size in android_sizes.items():
|
|
# 调整尺寸
|
|
resized_img = img.resize(size, Image.Resampling.LANCZOS)
|
|
|
|
# 构建输出路径
|
|
output_dir = os.path.join(android_res_dir, f"mipmap-{density}")
|
|
os.makedirs(output_dir, exist_ok=True)
|
|
|
|
output_path = os.path.join(output_dir, "ic_launcher.png")
|
|
resized_img.save(output_path)
|
|
print(f"已保存 {density} ({size[0]}x{size[1]}) 图标到: {output_path}")
|
|
|
|
print("\n安卓端所有图标更新完成!")
|
|
|
|
except Exception as e:
|
|
print(f"处理图片时出错: {e}")
|