是否有一种方法来创建xxhdpi, xhdpi, hdpi, mdpi和ldpi绘制从一个大规模的图像?

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

250528 次浏览

不是100%自动的,但是我使用Photoshop的行为节省了很多时间。

例如,给定xhdpi资产,然后为hdpimdpi创建一个任务,分别扩展到66.66%和44.44%。然后我为文件夹xhdpi上的所有图像运行操作。

对于512x512的图像,所要做的就是计算缩放图像的百分比,以实现xxhpi、xhdpi、hdpi和mdpi。

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

选项#2:使用Android Asset Studio为你降低样本。

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

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

选项#5:使用图像贝克

我在Eclipse中使用一个名为Android Icon Set的工具来设置标准图标,如Launcher、ActionBar、Tab图标和通知图标。你可以从File -> New -> Other..——> Android——> Android Icon Set。最好的部分是,你可以从你的电脑选择任何文件,它会自动将所有标准大小的图像放入你的项目目录。

enter image description here

一个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

我写了一个Photoshop脚本,从PSD文件创建ic_launcher png文件。只要检查ic_launcher_exporter

要使用它,只需下载它,并从photoshop中使用脚本。

enter image description here

并配置要生成输出文件的位置。

enter image description here

更新:

之前提到的插件已经被放弃,但它显然有一个最新的fork 在这里

旧的答案:

我使用名为Android Drawable Importer的Android Studio插件:

enter image description here

要在安装后使用它,右键单击您的res/drawable文件夹并选择New > Batch Drawable Import:

然后通过+按钮选择你的图像,并将分辨率设置为xxhdpi(或任何源图像的分辨率)。

在新的Android Studio中找到了一个简单的方法:

enter image description here

enter image description here

  1. 只需使用https://romannurik.github.io/AndroidAssetStudio/index.html即可。它可以从一个图像制作一组图标,之后你可以下载一个压缩文件。
  2. 或者在https://github.com/redwarp/9-Patch-Resizer/releases下载一个Windows应用程序(不需要安装)并打开一个图标。
  3. 你也可以使用插件Android Drawable Importer,见上面的答案。因为是废弃的,所以安装分叉。参见为什么Android Drawable Importer在as3.5以后忽略选择https://github.com/Vincent-Loi/android-drawable-importer-intellij-plugin
  4. https://appicon.co/#image-sets

也有可能将Vector Asset Studio与可缩放矢量图形(SVG)结合使用。Android Studio将为您处理其余的工作。正如官方文档所说:

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

我认为这是未来的方法。

 Vector Asset Studio的菜单项

 Vector Asset Studio截图

更新:

旧的安装插件的方式不再工作,但原始插件的分支仍然是有效的在这里。在手动安装插件后,您仍然可以遵循这个答案。

如果你想要快速简单的方法访问https://www.img-bak.in/https://appicon.co/,它们也适用于iOS。

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

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

2. 重启android studio

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

enter image description here

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

enter image description here

8. 现在点击添加图标“></a> .</strong></p>


<h3>5. 现在选择<em>“单身”</em>图像,你想要不同的可绘制的变化。</h3>


<p><a href=enter image description here

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

7. 现在按ok再ok ..然后它将花费几秒钟,然后你将神奇地获得drawables的所有变量。__abc0

enter image description here

使用像图像贝克这样的在线服务。

image baker

这很简单。在Android和iOS上上传图片和下载处理过的资产。

 downloads images

注:Image Baker是我的朋友和我自己创建的免费服务。

使用Android Studio图像资产

至:

 Project>res --> right click


new> image asset

然后设置:

-Icon type: Launcher Icons
-Asset type: Image
-Path: the/path/to/your/image
-Trim: No
-Padding: 0%
-Shape: None
-Effect: None

选择:Next > Finish。

Now you will have your icon in the correct resolutions.

示例: .

编辑:我建议使用SVG图像来创建Vector Drawables,然后在画布中使用它们来调整它们的大小,或者简单地更改DP。

您可以从谷歌获取默认图标,也可以创建自己的图标

 Project>res --> right click
new> vector asset

然后设置:

-Asset type: Local file (SVG, PSD)
-Path: the/path/to/your/image
-Size: check Override to keep your aspect ratio.
-Chek enable auto mirroring for RTL Layout.

选择:Next > Finish。

现在你将有你的图标,你将能够改变大小,颜色等。 enter image description here < / p >

编辑:

该网站现在被称为appicon.co


我通常使用enter image description here

在这个线程中,我一直在使用解决方案,并且很容易使用插件Android Drawable Importer

如果你在MacOS上使用Android Studio,只需尝试以下步骤即可进入:

  • 点击菜单栏Android工作室,然后选择首选项或点击按钮Command +,
  • 然后选择插件
  • 单击浏览存储库
  • 在搜索列Android Drawable Importer中写入
  • 单击安装按钮
  • 然后重启对话框显示,重新启动Android Studio

成功安装插件后,只需单击创建新菜单,然后选择批量可绘制导入。然后点击加号按钮,也就是添加按钮,然后选择你的文件使可绘制。然后点击确定,确定绘图器已经全部完成了。

如果你对我的话感到困惑,请参阅learningmechine中的图像教程。

Android中的一个简单插件将帮助你 步骤1。进入设置 步骤2。点击插件 步骤3。搜索Android Drawable Importer 步骤4。安装插件和重启

如何使用?

进入“文件>新建>批量可绘制导入”

享受

最简单的方法是使用资源管理器

enter image description here

然后你可以选择每个密度

enter image description here

导入后,你可以看到这张图片的6个不同版本

enter image description here

选项#5:使用图像面包师是薄片。我转换了两张图像,它就停止了。 我设法转换10张图像:https://nsimage.brosteins.com/

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

< a href = " https://appicon。Co /" rel="nofollow noreferrer">https://appicon.co/

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

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

我用的是“Android Asset studio”。现在我正在使用IconKitchen, Android Asset Studio的继承者,以及一种伟大的新方法来为Android, iOS, web, Windows, Linux和Mac制作高度自定义的应用程序图标。