簡體   English   中英

有什么方法可以同時為兩者(android,ios)創建一個應用程序圖標?

[英]Is there any way to create an app icon in a flutter for both(android, ios)?

在 android 和 ios 中,有一個選項可以創建或自定義圖像形狀、背景等。對於應用程序圖標。 但在顫振中,這是不可能的。

我用過這個庫,

flutter_launcher_icons

但他們只設置圖標(不是為兩個 android ios 自定義)。

因為如果有可能的話,通過使用任何工具或插件。 更好。

我假設您想在兩個平台(android、ios)上顯示不同的啟動器圖標。 如果是,請看一下這篇文章

不久前,我寫了一個sh腳本來創建我的 Flutter 應用程序圖標。 現在可以分享了,不知道能不能滿足你的要求,你可以試試。

此腳本首先需要一個源 1024x1024 應用程序圖標。

將以下腳本的內容另存為.sh文件。 例如flutter_app_icon_convert.sh

不要忘記添加可執行權限。

chmod +x flutter_app_icon_convert.sh

如果您還沒有安裝ImageMagick圖像工具,請安裝它。

brew install imagemagick

然后使用腳本創建 flutter 應用程序圖標(Android 和 iOS)。

在您的顫振項目文件夾中:

sh your_path/flutter_app_icon_convert.sh your_source_app_icon_1024x1024.png .

#!/bin/sh

# echo font color
# https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux
#
# ANSI escape codes:
#
# Black        0;30     Dark Gray     1;30
# Red          0;31     Light Red     1;31
# Green        0;32     Light Green   1;32
# Brown/Orange 0;33     Yellow        1;33
# Blue         0;34     Light Blue    1;34
# Purple       0;35     Light Purple  1;35
# Cyan         0;36     Light Cyan    1;36
# Light Gray   0;37     White         1;37
#
#
RED='\033[0;31m'
GREEN='\033[0;32m'
NO_COLOR='\033[0m'

convertImage() {
  src=$1
  srcdir=$(dirname "$src")

  if test -d "$2"; then
    des="$(
      cd "$2" || exit
      pwd
    )"
    build512=0
  else
    build512=1
    des="$(
      cd "${srcdir}" || exit
      pwd
    )/AppIcons"
  fi

  echo "Icons will be saved to :${GREEN}${des}${NO_COLOR}"
  mkdir -p "$des"

  echo 'creating ios icons...'

  ios=${des}/ios/Runner/Assets.xcassets/AppIcon.appiconset
  mkdir -p "$ios"

  convert -resize 20x20 "$src" "$ios"/Icon-App-20x20@1x.png
  convert -resize 40x40 "$src" "$ios"/Icon-App-20x20@2x.png
  convert -resize 60x60 "$src" "$ios"/Icon-App-20x20@3x.png
  convert -resize 29x29 "$src" "$ios"/Icon-App-29x29@1x.png
  convert -resize 58x58 "$src" "$ios"/Icon-App-29x29@2x.png
  convert -resize 87x87 "$src" "$ios"/Icon-App-29x29@3x.png
  convert -resize 40x40 "$src" "$ios"/Icon-App-40x40@1x.png
  convert -resize 80x80 "$src" "$ios"/Icon-App-40x40@2x.png
  convert -resize 120x120 "$src" "$ios"/Icon-App-40x40@3x.png
  convert -resize 120x120 "$src" "$ios"/Icon-App-60x60@2x.png
  convert -resize 180x180 "$src" "$ios"/Icon-App-60x60@3x.png
  convert -resize 76x76 "$src" "$ios"/Icon-App-76x76@1x.png
  convert -resize 152x152 "$src" "$ios"/Icon-App-76x76@2x.png
  convert -resize 167x167 "$src" "$ios"/Icon-App-83.5x83.5@2x.png
  convert -resize 1024x1024 "$src" "$ios"/Icon-App-1024x1024@1x.png

  echo 'creating android icons...'

  android=${des}/android/app/src/main/res
  mkdir -p "$android"
  mkdir -p "$android"/mipmap-xxxhdpi
  mkdir -p "$android"/mipmap-xxhdpi
  mkdir -p "$android"/mipmap-xhdpi
  mkdir -p "$android"/mipmap-mdpi
  mkdir -p "$android"/mipmap-hdpi

  convert -resize 192x192 "$src" "$android"/mipmap-xxxhdpi/ic_launcher.png
  convert -resize 144x144 "$src" "$android"/mipmap-xxhdpi/ic_launcher.png
  convert -resize 96x96 "$src" "$android"/mipmap-xhdpi/ic_launcher.png
  convert -resize 48x48 "$src" "$android"/mipmap-mdpi/ic_launcher.png
  convert -resize 72x72 "$src" "$android"/mipmap-hdpi/ic_launcher.png

  echo ''
  if [ $build512 = 1 ]; then
    convert -resize 512x512 "$src" "$des"/Icon-App-512x512.png
  else
    echo 'if you want to create an extra 512x512 icon, use command:'
    echo "convert -resize 512x512 $src $srcdir/Icon-App-512x512.png"
    echo ''
  fi

  echo "${GREEN}Done${NO_COLOR}."
  echo ''
}

printHelp() {
  echo 'This script use "ImageMagick" image tool to convert 1024x1024 App Icon to flutter Android and iOS icons.'
  echo 'So you need install "ImageMagick" first: https://imagemagick.org/script/download.php'
  echo 'This script can accept 2 parameters. The first is your srouce App Icon, the size should be 1024x1024.'
  echo 'The second parameter is optional and specifies the save path of the generated icons. If not specified, it will be saved to the folder where the source icon is located, and an additional 512x512 icon will be generated.'
}

if command -v convert >/dev/null 2>&1; then
  if test "$1" = "-h" -o "$1" = "--help"; then
    printHelp
  elif test -f "$1"; then
    convertImage "$1" "$2"
  else
    echo "${RED}Error${NO_COLOR}: please provide your 1024x1024 source app icon file."
    echo ''
    printHelp
  fi
else
  echo "${RED}Error${NO_COLOR}:ImageMagick convert image tools not installed,you can use homebrew to intall it:"
  echo 'brew install imagemagick'
fi

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM