簡體   English   中英

DIY九補丁未調和

[英]DIY Nine-patch not reconized

我嘗試在我的Android應用程序中集成九種補丁功能,以使拉伸效果更好。 似乎9補丁文件是具有1像素邊框的基本png文件。 但是,當嘗試自己構建9個補丁文件時,android和eclipse都不會將文件重新繪制為可繪制文件。 您可以在文章末尾看到我使用ImageMagick進行DIY九補丁的腳本。

如果我按原樣使用DIY ninepatch,則無法使用。 如果我使用draw9patch打開它,然后保存並退出,它將起作用! DIY制作9個貼片是否有特定要求?

我希望你能幫幫我 !

非常感謝。

# make a rounded square background with 1 px border
convert -size 100x100 xc:lightblue ninepatch.9.png
convert ninepatch.9.png -format 'roundrectangle 1,1 %[fx:w],%[fx:h] 15,15' info: > tmp.mvg
convert ninepatch.9.png -border 1 -alpha transparent -background none -fill white -stroke none -strokewidth 0 -draw "@tmp.mvg" tmp.png
convert ninepatch.9.png -matte -bordercolor none -border 1 tmp.png -compose DstIn -composite ninepatch.9.png

# draw ninepatch info
convert ninepatch.9.png -format 'stroke-dasharray 1 1 line %[fx:w*0.25],0 %[fx:w*0.75],0' info: > tmp.mvg
convert ninepatch.9.png -format 'line 0,%[fx:h*0.25] 0,%[fx:h*0.75]' info: >> tmp.mvg
convert ninepatch.9.png -format 'fill black line %[fx:w*0.25],%[fx:h-1] %[fx:w*0.75],%[fx:h-1]' info: >> tmp.mvg
convert ninepatch.9.png -format 'line %[fx:w-1],%[fx:h*0.25] %[fx:w-1],%[fx:h*0.75]' info: >> tmp.mvg
convert ninepatch.9.png -fill none -stroke black -strokewidth 0.5 -draw "@tmp.mvg" ninepatch.9.png

注意這兩個文件在大小上的差異:

  • 此方法的九個補丁

http://dl.dropbox.com/u/16984035/ninepatch.9.png

  • 相同的九個補丁,使用draw9patch打開並保存

http://dl.dropbox.com/u/16984035/ninepatch-draw9patch.9.png

(對不起,我還不能發布圖片!)

您鏈接的前九個補丁無效。 一個像素邊界中的每個像素都必須完全透明或完全黑色。 當我放大底部邊框時,在左側的透明像素和右側的黑色像素之間有一個灰色像素。 那是無效的。

當您使用ImageMagick生成邊框時,邊框中黑色的位置最終可能像25.5一樣是半像素,因此ImageMagick將像素着色為灰色。 但是,它必須是透明的或全黑的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM