suggerisco un po 'di scrittura di script in PowerShell per Inkscape.
Esempio:
Mettere Inkscape in "c: \ bin \ Inkscape" (dir senza spazi) e disegnare tutte le immagini in MDPI risoluzione (1x).
nella casella delle proprietà dell'oggetto Inkscape (ID id in xml), fornire un nome ID per ciascun oggetto che si desidera esportare in png.
Salva il tuo SVG in "C: \ users \ rone \ Pictures \ design-MyApps-forscript.svg"
Creare una directory "d:".
E mettere questo script in "\ Temp C: \ app \ scripts \"
PowerShell nome dello script è "inkscape_to_png.ps1" :
param (
$inkscape_dir="C:\bin\Inkscape\",
$inkscape_bin="inkscape.exe",
$img_id="",
$fichier_svg="C:\Users\rone\Pictures\design-MyMap-forscript.svg",
$tmp_dir="d:\temp\"
)
$inkscape=$(Resolve-Path "$inkscape_dir\$inkscape_bin")
function getWidthHeight($img_id) {
[email protected]{}
$old_pwd=$pwd.path
cd $inkscape_dir
write-host -foreground yellow "détermine la taille de $img_id"
$size.width=invoke-command {./inkscape --file=$fichier_svg --query-id=$img_id --query-width 2>$null}
$size.height=invoke-command {./inkscape --file=$fichier_svg --query-id=$img_id --query-height 2>$null}
write-host -foreground yellow "width : $($size.width)"
write-host -foreground yellow "height : $($size.height)"
cd $old_pwd
return $size
}
function convertTo($size, $format) {
[email protected]{}
if ($format -eq "MDPI") {
$rsize.width=[int]$size.width*1
$rsize.height=[int]$size.height*1
} elseif ($format -eq "LDPI") {
$rsize.width=[int]$size.width*0.75
$rsize.height=[int]$size.height*0.75
} elseif ($format -eq "HDPI") {
$rsize.width=[int]$size.width*1.5
$rsize.height=[int]$size.height*1.5
} elseif ($format -eq "XHDPI") {
$rsize.width=[int]$size.width*2
$rsize.height=[int]$size.height*2
} elseif ($format -eq "XXHDPI") {
$rsize.width=[int]$size.width*3
$rsize.height=[int]$size.height*3
} elseif ($format -eq "XXXHDPI") {
$rsize.width=[int]$size.width*4
$rsize.height=[int]$size.height*4
}
write-host -foreground yellow "après conversion : $format"
write-host -foreground yellow "width : $($rsize.width)"
write-host -foreground yellow "height : $($rsize.height)"
return $rsize
}
function inkscape_convert() {
$mdpi_size=getWidthHeight $img_id
write-host -foreground gray "----------------------------------------"
"MDPI,LDPI,HDPI,XHDPI,XXHDPI,XXXHDPI" -split ","|% {
$new_size=convertTo $mdpi_size $_
if ($new_size.width -eq 0 -or $new_size.height -eq 0) {
write-host -foreground red "erreur lors de la recherche de la taille de l'image"
exit
}
$w=$new_size.width
$h=$new_size.height
$dir="$tmp_dir\drawable-$($_.toLower())"
if (-not $(test-path $dir)) {
write-host -foreground yellow "création du répertoire $dir"
mkdir $dir
}
$new_file_name="$dir\$($img_id).png"
$cmd="$inkscape -z -i $img_id -j -f $fichier_svg -w $w -h $h -e $new_file_name"
write-host -foreground gray $cmd
invoke-expression -command $cmd
if ($? -eq $true) {
write-host -foreground yellow "conversion OK"
}
}
write-host -foreground gray "----------------------------------------"
}
inkscape_convert
ora, chiamare questo script come questo esempio:
012.351.
@("btn_button_name_1","btn_button_name_3","btn_other", "btn_zoom", "btn_dezoom", "btn_center", "btn_wouwou", "im_abcdef", "ic_half", "ic_star", "ic_full") | % { C:\app\scripts\inkscape_to_png.ps1 -img $_ -f design-MyMap-forscript.svg }
e lo script creerà tutte le vostre drawable in tutte le risoluzioni (ldpi, MDPI, hdpi, xhdpi, xxhdpi, xxxhdpi) in d: \ temp \ drawable-xyz ...
Quindi un confortevole che fa risparmiare tempo.
Per la generazione automatica di diverse dimensioni, consultare: http://stackoverflow.com/a/18516508/237858 – kape123
utilizzare questo studio di risorse Android http://romannurik.github.io/AndroidAssetStudio/ di Roman Nurik per progettare drawbles per tutte le taglie .. happy – goonerDroid
Ho creato una semplice app java che può automatizzare il ridimensionamento delle immagini per te. La cosa migliore è che non è necessario decomprimere i file zip e copiare manualmente i file generati nella cartella res. Basta selezionare la cartella res come output e tutte le immagini in tutte le risoluzioni verranno generate nelle sottocartelle corrette. Puoi scaricare l'app qui: https://github.com/kaladivo/android-icon-generator –