icon优化
This commit is contained in:
40
resize_android_icons.py
Normal file
40
resize_android_icons.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from PIL import Image
|
||||
import os
|
||||
|
||||
# 原始图片路径
|
||||
original_image_path = r"e:\project\flutter\f3\flutter_application_2\assets\audios\IMG_20260402_170051.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(original_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}")
|
||||
Reference in New Issue
Block a user