首页 文章

有没有办法从大尺寸图像创建xxhdpi,xhdpi,hdpi,mdpi和ldpi drawables?

提问于
浏览
195

有没有办法自动从大尺寸图像创建xxhdpi,xhdpi,hdpi,mdpi和ldpi drawables?例如,假设我有一个512x512的图像,我希望在适当的文件夹中为Android支持的不同屏幕分辨率提供不同版本的此图像 .

16 回答

  • 1

    我在Eclipse中使用了一个名为Android Icon Set的工具,用于标准图标,如Launcher,ActionBar,Tab图标和通知图标 . 您可以从文件 - >新建 - >其他.. - > Android - > Android图标集启动它 . 最好的部分是您可以从计算机中选择任何文件,它会自动将标准尺寸的所有图像放入项目目录中 .

    enter image description here

  • 5

    选项#1:只需发送 -xxhdpi drawables并让Android在运行时为您下采样(缺点:仅适用于最近的设备,其中 -xxhdpi 已知) .

    选项#2:使用Android Asset Studio为您下采样 .

    选项#3:根据ssantos的回答,在图形编辑器中自动完成该过程 .

    选项#4:使用ImageMagick之类的东西为自己编写解决方案 .

    选项#5:使用image baker

  • 0

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

    enter image description here

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

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

  • 7

    I will try to explain the process in step wise basis, so that it will be simple to understand to anyone.

    1. Go to Setting > Plugins
    enter image description here

    2.Search " Android Drawable Importer " in the search bar
    enter image description here

    3.It will not show the plugin by default, to search it online click in "Browse" Link
    enter image description here

    4.Then install the plugin , it will show downloading .... sometimes it may not show downloading, so make sure to check at the bottom of the android studio, it shows downloading.
    enter image description here

    5. Now restart android studio

    6. As you can see in the following screencap, there is only one drawable here
    enter image description here

    7. now right click on drawable folder and navigate to New>Batch Drawable Import
    enter image description here


    9. Now select "the Single " image you want different variations of drawables.

    enter image description here

    10.Now select which dimension the origin image is. If the origin image is xxhdpi like in my case select "xxhdpi " as "Source Resoultion".

    11.现在按OK然后再次确定..然后它将需要几秒钟然后你将神奇地获得drawables的所有变量 .
    enter image description here

    enter image description here

  • 0

    使用像Image Baker这样的在线服务 .

    image baker

    这很简单 . 上传图像并下载Android和iOS的已处理资源 .

    Downloaded images

  • 10

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

    由于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
    #---------------------------------------------------------------
    
    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
    
  • 132

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

    enter image description here

    enter image description here

  • 10

    我通常使用assets.codly.io
    它在您的浏览器中本地生成资产,无需上传,无需下载 .

    enter image description here

  • 3

    我认为Redwarp提供的工具是最好的! https://github.com/asystat/Final-Android-Resizer

    在另一个问题中找到它:https://stackoverflow.com/questions/10754523/is-there-any-tool-which-can-a-resize-png-image-into-a-image-for-ldpi-mdpi-hdp

    由于这是Google上的第一个结果,我想在此处添加此信息 .

  • 78

    我写了一个Photoshop脚本来从PSD文件创建ic_launcher png文件 . 只需检查ic_launcher_exporter .

    要使用它,只需下载它并使用photoshop中的脚本 .

    enter image description here

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

    enter image description here

  • 1

    我很幸运使用这个插件用于photoshop:

    check here

    有一些工作可以正确命名图层和按钮状态 . 但是,一旦你这样做,内置的宏是非常好的 .

    否则,如果您有相关知识,可以在photoshop中编写自己的宏 .

  • 2

    不是100%自动,但我使用Photoshop Actions节省了大量时间 .

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

    对于512x512图像,您所要做的就是计算缩放图像的百分比,以达到xxhpi,xhdpi,hdpi和mdpi .

  • 128
  • 54

    使用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
    

    选择:下一步>完成 .

    Now you will have your icon in the correct resolutions.
    

    Visual Example:

    编辑:我建议使用SVG图像来创建Vector Drawables,然后在画布中使用它们将它们调整到正确的大小或只是更改DP .

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

    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.
    

    选择:下一步>完成 .

    现在你将拥有你的图标,你将能够改变大小,颜色等 .
    enter image description here

  • 1

    还可以将Vector Asset Studio与Scalable Vector Graphics (SVG)结合使用 . Android Studio将为您处理剩下的事情 . 正如official documentation所说:

    Vector Asset Studio可帮助您添加材质图标并将可缩放矢量图形(SVG)文件作为可绘制资源导入到您的应用项目中 . 与光栅图像相比,矢量绘图可以减小应用程序的大小,并且可以在不损失图像质量的情况下调整大小 . 它们可以帮助您更轻松地支持具有不同屏幕尺寸和分辨率的不同Android设备,因为您可以在所有设备上显示一个可绘制的矢量 .

    我认为这是未来的方法 .

    Menu entry of the Vector Asset Studio

    Screenshot of the Vector Asset Studio

  • 27

    我在这里一直使用解决方案线程,它很容易使用插件 Android Drawable Importer

    如果您在MacOS上使用Android Studio,只需尝试此步骤即可:

    • 单击栏菜单 Android Studio 然后选择 Preferences 或点击按钮 Command + ,

    • 然后选择 Plugins

    • 点击 Browse repositories

    • 在搜索列表中写入 Android Drawable Importer

    • 单击 Install 按钮

    • 然后显示对话框重启,只需重启Android Studio即可

    安装插件成功后,要使用此插件,只需单击“创建新菜单”,然后选择 Batch Drawable Import . 然后单击加号按钮a.k.a添加按钮,然后选择您的文件以使其可绘制 . 然后只需单击确定,然后确定drawable已完成所有这些操作 .

    如果你对我的话感到困惑,只需看看learningmechine的图像教程 .

相关问题