是否有一种方法来创建xxhdpi, xhdpi, hdpi, mdpi和ldpi绘制从一个大规模的图像自动?例如,假设我有一个512x512的图像,我想在适当的文件夹中有这个图像的不同版本,用于Android支持的不同屏幕分辨率。
当前回答
不是100%自动,但我用Photoshop动作节省了很多时间。
例如,给定xhdpi资产,然后为hdpi和mdpi创建一个任务,其规模分别为66.66%和44.44%。然后运行文件夹xhdpi上所有图像的操作。
对于512x512的图像,所要做的就是计算缩放图像的百分比,以实现xxhpi、xhdpi、hdpi和mdpi。
其他回答
一个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
我在这个线程中使用解决方案,它很容易与插件Android Drawable Importer一起工作
如果你在MacOS上使用Android Studio,只需尝试以下步骤即可进入:
点击菜单栏Android Studio然后选择首选项或点击按钮Command +, 然后选择插件 单击浏览存储库 在搜索栏中写入Android Drawable Importer 点击安装按钮 然后重启对话框显示,重新启动Android Studio
成功安装插件后,只需单击创建新菜单,然后选择批量可绘制导入。然后点击加号按钮,也就是添加按钮,然后选择你的文件使可绘制。然后点击确定,确定绘图器已经全部完成了。
如果你不明白我说的话,可以看看学习机里的图片教程。
使用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。
现在你将有你的图标,你将能够改变大小,颜色等。
选择#5:使用图像面包师是片状的。我转换了两张图像,它就停止了。 我成功地转换了10张图片:https://nsimage.brosteins.com/
更新:
旧的安装插件的方式已经不工作了,但是原始插件的一个分支仍然在这里发挥作用。在手动安装插件后,您仍然可以遵循这个答案。
如果你想要快速简单的方法,请访问https://www.img-bak.in/或https://appicon.co/,他们也支持iOS。
我将试着一步一步地解释这个过程,这样任何人都能容易理解。
1. 按照ReadME中提供的手动安装插件
2. 重启android studio
3.正如你在下面的屏幕截图中看到的,这里只有一个可绘制的
4. 现在右键单击可绘制文件夹并导航到新建>批量可绘制导入
5. 现在选择“单一”的图像,你想要不同的变化绘制。
6. 现在选择原始图像的维度。如果源图像是xxhdpi,就像我的例子一样,选择“xxhdpi”作为“源分辨率”。
7. 现在按ok再ok ..然后会花几秒钟然后你会神奇地得到所有的变量。
推荐文章
- 警告:API ' variable . getjavacompile()'已过时,已被' variable . getjavacompileprovider()'取代
- 安装APK时出现错误
- 碎片中的onCreateOptionsMenu
- TextView粗体通过XML文件?
- 如何使线性布局的孩子之间的空间?
- DSL元素android.dataBinding。enabled'已过时,已被'android.buildFeatures.dataBinding'取代
- ConstraintLayout:以编程方式更改约束
- PANIC: AVD系统路径损坏。检查ANDROID_SDK_ROOT值
- 如何生成字符串类型的buildConfigField
- Recyclerview不调用onCreateViewHolder
- Android API 21工具栏填充
- Android L中不支持操作栏导航模式
- 如何在TextView中添加一个子弹符号?
- PreferenceManager getDefaultSharedPreferences在Android Q中已弃用
- 在Android Studio中创建aar文件