【问题标题】:Android Studio add padding to the icon ic_launcher.pngAndroid Studio 为图标 ic_launcher.png 添加填充
【发布时间】:2014-06-14 19:10:06
【问题描述】:

我是初学者的 android 开发人员。我不明白为什么 AS 会自动向我的 png 文件添加填充。我通过 res-New-Image Asset 添加了 png 文件-为 android 应用程序图标添加了我的 png 文件。 该文件没有填充。

【问题讨论】:

    标签: android icons android-studio padding


    【解决方案1】:

    尝试点击这个,我希望这会有所帮助;)

    【讨论】:

      【解决方案2】:

      我找到了两个解决方案来解决 Android Studio 在创建图标时添加的额外填充:

      1. 使用 [Windows] 批处理文件调整图像大小。这是我使用的一个,因为它对我来说是最简单的(在 Windows 上):

        一个。使用http://www.ianmcintyre.com/2014/06/c-resize-image-fit-image.html中的简单代码创建一个ResizeImage.exe

        b.将以下 ResizeAndroidLauncherImage.bat 文件保存在与 ResizeImage.exe 相同的目录中。这会将您的原始图像复制到各个目录并调整它们的大小:

        @echo off
        setlocal
        
        set subdir=%2
        set iconsize=512
        if not exist "%subdir%" mkdir "%subdir%"
        copy /Y %1 %subdir%\ic_launcher-web.png
        %~dp0ResizeImage.exe %subdir%\ic_launcher-web.png %iconsize% %iconsize%
        
        set subdir=%2\res\mipmap-xxxhdpi
        set iconsize=192
        if not exist "%subdir%" mkdir "%subdir%"
        copy /Y %1 %subdir%\ic_launcher.png
        %~dp0ResizeImage.exe %subdir%\ic_launcher.png %iconsize% %iconsize%
        
        set subdir=%2\res\mipmap-xxhdpi
        set iconsize=144
        if not exist "%subdir%" mkdir "%subdir%"
        copy /Y %1 %subdir%\ic_launcher.png
        %~dp0ResizeImage.exe %subdir%\ic_launcher.png %iconsize% %iconsize%
        
        set subdir=%2\res\mipmap-xhdpi
        set iconsize=96
        if not exist "%subdir%" mkdir "%subdir%"
        copy /Y %1 %subdir%\ic_launcher.png
        %~dp0ResizeImage.exe %subdir%\ic_launcher.png %iconsize% %iconsize%
        
        set subdir=%2\res\mipmap-hdpi
        set iconsize=72
        if not exist "%subdir%" mkdir "%subdir%"
        copy /Y %1 %subdir%\ic_launcher.png
        %~dp0ResizeImage.exe %subdir%\ic_launcher.png %iconsize% %iconsize%
        
        set subdir=%2\res\mipmap-mdpi
        set iconsize=48
        if not exist "%subdir%" mkdir "%subdir%"
        copy /Y %1 %subdir%\ic_launcher.png
        %~dp0ResizeImage.exe %subdir%\ic_launcher.png %iconsize% %iconsize%
        
        endlocal
        

        c。每次更新图标时执行批处理文件:

        ResizeAndroidLauncherImage.bat [YourIcon.png] [YourAndreoidSRCDir]
        
      2. 使用 Android Asset Studio (https://romannurik.github.io/AndroidAssetStudio/icons-launcher.html)。您必须修改源以删除额外的填充。有关如何做到这一点的讨论,请参阅 https://github.com/romannurik/AndroidAssetStudio/issues/73。我试过这个并使用“none”:

        const TARGET_RECTS_BY_SHAPE = { none: { x: 0, y: 0, w: 46, h: 46 }, circle: { x: 2, y: 2, w: 44, h: 44 }, square: { x: 5, y: 5, w: 38, h: 38 }, vrect: { x: 8, y: 2, w: 32, h: 44 }, hrect: { x: 2, y: 8, w: 44, h: 32 }, };
        

      如果我的开发机器上有 Photoshop,我也会尝试:

      1. 在 Photoshop 中录制和播放批处理脚本。 [请注意,我没有尝试过这个]

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-11-20
        • 1970-01-01
        • 2022-01-20
        • 1970-01-01
        • 2011-09-21
        • 2012-05-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多