Android Studio将填充添加到图标ic_launcher.png

时间:2014-04-29 02:55:27

标签: android icons android-studio padding

enter image description here

enter image description here

我是初学Android开发者。我无法弄清楚为什么AS会自动为我的png文件添加填充。我通过res-New-Image Asset添加了png文件 - 为Android app图标添加我的png文件。 文件没有填充。

2 个答案:

答案 0 :(得分:1)

点击这个,我希望这会有所帮助;)enter image description here

答案 1 :(得分:1)

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

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

    一个。使用http://www.ianmcintyre.com/2014/06/c-resize-image-fit-image.html

    中的简单代码创建ResizeImage.exe

    湾将以下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
    

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

    ResizeAndroidLauncherImage.bat [YourIcon.png] [YourAndreoidSRCDir]
    
  2. 使用Android资产工作室(https://romannurik.github.io/AndroidAssetStudio/icons-launcher.html)。您必须修改源以删除额外的填充。有关如何执行此操作的讨论,请参阅https://github.com/romannurik/AndroidAssetStudio/issues/73。我试过这个并使用“无”:

    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 }, };
    
  3. 如果我的开发机器上有Photoshop,我也会尝试:

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