Tôi đề nghị một chút kịch bản ghi trong PowerShell cho Inkscape.
Ví dụ:
Đặt Inkscape trong "c: \ bin \ inkscape" (dir mà không cần bất kỳ không gian) và vẽ tất cả hình ảnh của bạn trong mdpi (1x) độ phân giải.
trong hộp thuộc tính đối tượng Inkscape (ví dụ id trong xml), đặt tên Id cho từng đối tượng mà bạn muốn xuất trong png.
Lưu SVG của bạn thành "C: \ users \ rone \ Pictures \ design-MyApps-forscript.svg"
Tạo một thư mục "d:".
Và đưa kịch bản này trong "\ temp C: \ ứng dụng \ scripts \"
tên kịch bản Powershell là "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
bây giờ, gọi kịch bản này như ví dụ sau:
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 }
Và kịch bản sẽ tạo mọi drawables của bạn trong tất cả các độ phân giải (ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi) trong d: \ temp \ drawable-xyz ...
Vì vậy, một confortable tiết kiệm thời gian.
Để tạo tự động tạo các kích thước khác nhau, hãy xem: http://stackoverflow.com/a/18516508/237858 – kape123
sử dụng studio tài sản android này http://romannurik.github.io/AndroidAssetStudio/ bởi Roman Nurik để thiết kế các hình vẽ cho tất cả các kích cỡ ..njoy – goonerDroid
Tôi đã tạo một ứng dụng java đơn giản có thể tự động thay đổi kích thước hình ảnh cho bạn. Điều tốt nhất về nó là bạn không phải giải nén bất kỳ tệp zip nào và sao chép thủ công tệp đã tạo vào thư mục res. Bạn chỉ cần chọn thư mục res là đầu ra và tất cả các hình ảnh trong tất cả các độ phân giải sẽ được tạo ra cho các thư mục con bên phải. Bạn có thể tải xuống ứng dụng tại đây: https://github.com/kaladivo/android-icon-generator –