是否有一种方法来创建xxhdpi, xhdpi, hdpi, mdpi和ldpi绘制从一个大规模的图像自动?例如,假设我有一个512x512的图像,我想在适当的文件夹中有这个图像的不同版本,用于Android支持的不同屏幕分辨率。


当前回答

更新:

旧的安装插件的方式已经不工作了,但是原始插件的一个分支仍然在这里发挥作用。在手动安装插件后,您仍然可以遵循这个答案。

如果你想要快速简单的方法,请访问https://www.img-bak.in/或https://appicon.co/,他们也支持iOS。

我将试着一步一步地解释这个过程,这样任何人都能容易理解。

1. 按照ReadME中提供的手动安装插件

2. 重启android studio

3.正如你在下面的屏幕截图中看到的,这里只有一个可绘制的

4. 现在右键单击可绘制文件夹并导航到新建>批量可绘制导入

5. 现在选择“单一”的图像,你想要不同的变化绘制。

6. 现在选择原始图像的维度。如果源图像是xxhdpi,就像我的例子一样,选择“xxhdpi”作为“源分辨率”。

7. 现在按ok再ok ..然后会花几秒钟然后你会神奇地得到所有的变量。

其他回答

一个bash脚本使用ImageMagick(转换)根据CommonsWare的答案:

增加了文件夹创建和参数检查多亏了Kishan Vaghela

#!/bin/sh
#---------------------------------------------------------------
# Given an xxhdpi image or an App Icon (launcher), this script
# creates different dpis resources and the necessary folders
# if they don't exist
#
# Place this script, as well as the source image, inside res
# folder and execute it passing the image filename as argument
#
# Example:
# ./drawables_dpis_creation.sh ic_launcher.png
# OR
# ./drawables_dpis_creation.sh my_cool_xxhdpi_image.png
#
# Copyright (c) 2016 Ricardo Romao.
# This free software comes with ABSOLUTELY NO WARRANTY and
# is distributed under GNU GPL v3 license. 
#---------------------------------------------------------------

if [ $# -eq 0 ]; then
    echo "No arguments supplied"
else if [ -f "$1" ]; then
    echo " Creating different dimensions (dips) of "$1" ..."
    mkdir -p drawable-xxxhdpi
    mkdir -p drawable-xxhdpi
    mkdir -p drawable-xhdpi
    mkdir -p drawable-hdpi
    mkdir -p drawable-mdpi

    if [ $1 = "ic_launcher.png" ]; then
        echo "  App icon detected"
        convert ic_launcher.png -resize 144x144 drawable-xxhdpi/ic_launcher.png
        convert ic_launcher.png -resize 96x96 drawable-xhdpi/ic_launcher.png
        convert ic_launcher.png -resize 72x72 drawable-hdpi/ic_launcher.png
        convert ic_launcher.png -resize 48x48 drawable-mdpi/ic_launcher.png
        rm -i ic_launcher.png
    else
        convert $1 -resize 75% drawable-xxhdpi/$1
        convert $1 -resize 50% drawable-xhdpi/$1
        convert $1 -resize 38% drawable-hdpi/$1
        convert $1 -resize 25% drawable-mdpi/$1
        mv $1 drawable-xxxhdpi/$1
    fi
echo " Done"
else
    echo "$1 not found."
fi
fi

选项#1:只发布-xxhdpi绘制图,让Android在运行时为你对它们进行采样(缺点:只能在最近的设备上工作,其中-xxhdpi是已知的)。

选项2:使用Android Asset Studio对它们进行采样。

选项3:根据ssantos的回答,在图形编辑器中自动化这个过程。

选项4:自己编写解决方案的脚本,使用ImageMagick之类的东西。

选项#5:使用图像烘焙器

Just use https://romannurik.github.io/AndroidAssetStudio/index.html. It can make a set of icons from an image, later you can download a zip-file. Or download a Windows application at https://github.com/redwarp/9-Patch-Resizer/releases (doesn't need to install) and open an icon. Also you can use a plugin Android Drawable Importer, see answers above. Because it is abandoned, install forks. See Why does Android Drawable Importer ignore selection in AS 3.5 onwards or https://github.com/Vincent-Loi/android-drawable-importer-intellij-plugin. https://appicon.co/#image-sets.

还可以将Vector Asset Studio与可缩放矢量图形(Scalable Vector Graphics, SVG)结合使用。Android Studio将为您处理其余的工作。正如官方文件所说:

矢量资产工作室帮助您添加材质图标和导入可缩放 矢量图形(SVG)文件到你的应用程序项目作为一个绘图 资源。与栅格图像相比,矢量绘图可以降低图像的分辨率 你的应用程序的大小,并在不损失图像质量的情况下调整大小。他们 帮助您更轻松地支持不同的Android设备与变化 屏幕大小和分辨率,因为你可以显示一个矢量 都可以画出来。

我认为这是未来的方法。

使用这个来生成启动器图标

https://appicon.co/

使用它来生成可绘制的图标

https://www.img-bak.in/