元服务上架时启动图标和应用图标

元服务上架的时候,必须要使用dev生成的图标,使用UI做出来的图,会被打回审核,而且生成的时候还会生成两张图,有没有外部生成的工具啊,非得下个dev,为什么啊?????????????我觉得挺离谱的。必须要下dev

HarmonyOS
4天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
特立独行的猫a

有个脚本,分享给你。希望对你有帮助!

自动生成图标和替换字符串,自动编译打包,python脚本如下:

详细使用,参加博客,搜 特立独行的猫a

# 使用说明
# 1. 安装PIL库,使用pip install pillow安装
# 2. 将icon.py文件放到 [ 项目目录,注意根目录下 ] 目录下,如 TangShi 项目目录,该目录下为 各个 开发项目
# 3. 打开项目,手动替换 "AppScope\\resources\\base\\element\\string.json" 对应app 名称,以及 元服务图片生成
# 4. 在目录下运行 icon.py 文件,会在对应目录下生成 icon.png、startIcon.png  以及 EntryCard 图片
# 5. 正常打包项目

import os
import shutil
import json
from PIL import Image,ImageDraw,ImageFont

def merge_images(app_icon, temp_icon, output_ec_icon,app_name):
    # 打开图片
    image_icon = Image.open(app_icon)
    image_temp_icon = Image.open(temp_icon)
    #Image.open(temp_icon)
    
    resized_image = image_icon.resize((80,80))
    #resized_image.save("rtemp.png")
    smaller_image = image_temp_icon.crop((30,2,110,82));
    #smaller_image.save("stemp.png")
    image_process = Image.new('RGBA', (80,80))

    print(resized_image.size)
    print(smaller_image.size)

    image_process = Image.alpha_composite(image_process,smaller_image.convert('RGBA'))
    image_process = Image.alpha_composite(image_process,resized_image.convert('RGBA'))

    #new_image.save('temp.png')

    image_result = Image.new('RGBA', (140,140))
    image_result.paste(image_temp_icon, (0, 0))
    image_result.paste(image_process, (30, 2))

    draw = ImageDraw.Draw(image_result)
    font = ImageFont.truetype('simhei.ttf', 14)
    draw.text(((140-len(app_name)*14)/2,88),app_name,font=font,fill=(36,54,71))
    image_result.save(output_ec_icon)

# 名称处理
def write_string(app_name,tag):
    entry_string_url = "entry\\src\\main\\resources\\"+ tag +"\\element\\string.json"
    esurl =  os.path.join(current_dir,entry_string_url)
    print('string 目录: ', esurl)

    with open(esurl, 'r',encoding='utf-8') as f:
        sdata = json.load(f)

    for d in sdata['string']:
        if d['name'] == 'EntryAbility_label':
            d['value'] = app_name
        elif d['name'] == 'entrance_desc':
            d['value'] = app_name
        elif d['name'] == 'entrance_display_name':
            d['value'] = app_name
# 将修改后的数据写回 JSON 文件
    with open(esurl, 'w',encoding='utf-8')  as file:
        json.dump(sdata, file, indent=4,ensure_ascii=False)

    print( tag +' string  修改成功')

# 原始 PNG 图片路径 
current_dir = os.getcwd()
print('当前目录: ', current_dir)

source_png_path = "AppScope\\resources\\base\\media\\app_icon.png"
# 目标目录
target_dir = "entry\\src\\main\\resources\\base\\media\\"
target_icon= "icon.png"
target_startIcon= "startIcon.png"
# app名称
app_name_url = "AppScope\\resources\\base\\element\\string.json"

with open(os.path.join(current_dir, app_name_url), 'r',encoding='utf-8') as f:
    sdata = json.load(f)
app_name = sdata['string'][0]["value"]

print('应用程序名称:', app_name)

sp=  os.path.join(current_dir,source_png_path)# 复制文件
print('原始目录: ', sp)
#复制文件
shutil.copy(sp, target_dir + target_icon)
shutil.copy(sp, target_dir + target_startIcon)
print('复制成功')

#处理 EntryCard
ec_url = "EntryCard\\entry\\base\\snapshot\\entrance-2x2.png"
tmp_url = os.path.join(current_dir,"..","template.png")
merge_images(sp, tmp_url,ec_url,app_name)

#修改 string.json 文件
write_string(app_name,"base")
write_string(app_name,"en_US")
write_string(app_name,"zh_CN")

# 打包
clearn ="hvigorw -p product=default clean --analyze=normal --parallel --incremental --daemon"
os.system(clearn)
print('清理成功')
cmd="hvigorw --mode project -p product=default assembleApp --analyze=normal --parallel --incremental --daemon"
os.system(cmd)
print('打包成功')
b_path =os.path.join(current_dir,"build\\outputs\\default")

b_name = os.path.basename(current_dir) + "-default-signed.app"

#把app_icon文件也复制过去
sp=  os.path.join(current_dir,"app_icon.png")# 复制文件
shutil.copy(sp, os.path.join( b_path,"app_icon.png"))
print('复制成功')

os.system(f'explorer /select , { os.path.join( b_path,b_name)}')
print('打开输出目录:' + b_path)
print('输出文件名:' + b_name)
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
分享
微博
QQ
微信
回复
4天前
相关问题
HarmonyOS 服务问题?
788浏览 • 1回复 待解决
HarmonyOS 服务怎么
676浏览 • 1回复 待解决
如何配置桌面图标的快速启动图标
2180浏览 • 1回复 待解决
HarmonyOS 设置的应用图标名称无效
511浏览 • 1回复 待解决
HarmonyOS 应用图标规范
577浏览 • 1回复 待解决
HarmonyOS 应用图标不显示
780浏览 • 1回复 待解决
HarmonyOS 应用图标格式
791浏览 • 1回复 待解决
HarmonyOS 安装应用桌面没有图标
2027浏览 • 2回复 待解决
HarmonyOS 如何正确配置应用图标
618浏览 • 1回复 待解决
如何修改应用的icon图标
2869浏览 • 1回复 待解决