I am about to create my first Android native (so not browser based) app and looking for some good practices regarding icon creating/provisioning. Since it s
I've never had much luck running Linux shell scripts in Cygwin on Windows. So here is a batch file that does what Nacho Coloma's bash script does. One small difference, is that this batch file requires both an input and an output file name, as in "svg2png -w24 input.svg output.png".
Set up an "svg" folder in your project's src/main directory and copy your SVG files and this batch file to that folder, per Stephan's instructions. Run the batch file from the svg folder. If you're on 32-bit Windows, then you will likely need to change the path to Inkscape to use "Program Files (x86)".
@echo off
echo Convert an SVG file to a PNG resource file with multiple resolutions.
rem Check the arguments
set temp=%1
set switch=%temp:~0,2%
set pixels=%temp:~2%
if not "%switch%"=="-w" (
if not "%switch%"=="-h" (
echo Error: Invalid image width or height switch. Use -w or -h, with target image size in dp appended.
goto :error
))
echo %pixels%| findstr /r /c:"^[1-9][0-9]*$" >nul
if errorlevel 1 (
echo Error: Invalid numeric image size. Image size must be a positive integer.
goto :error
)
if "%3"=="" (
echo Error: Not enough arguments.
goto :error
)
if not "%4"=="" (
echo Error: Too many arguments.
goto :error
)
call :export %1 %2 %3 mdpi
call :export %1 %2 %3 hdpi
call :export %1 %2 %3 xhdpi
call :export %1 %2 %3 xxhdpi
call :export %1 %2 %3 xxxhdpi
exit /b
:export
rem parameters:
set temp=%1
set switch=%temp:~0,2%
set pixels=%temp:~2%
if %4==mdpi set /a size=%pixels%
if %4==hdpi set /a size=%pixels%*3/2
if %4==xhdpi set /a size=%pixels%*2
if %4==xxhdpi set /a size=%pixels%*3
if %4==xxxhdpi set /a size=%pixels%*4
echo %size% pixels ../res/drawable-%4/%3
"C:\Program Files\Inkscape\inkscape.exe" %switch%%size% --export-background-opacity=0 --export-png=../res/drawable-%4/%3 %2
exit /b
:error
echo Synopsis: svg2png -w^^|-h^ ^ ^
echo Example: svg2png -w24 "wifi white.svg" wifi_connect_24dp.png
exit /b