我嘗試在我的Android應用程序中集成九個修補功能,以使拉伸看起來更好。看起來九個補丁文件是具有1個像素邊界的基本PNG文件。然而,當我嘗試自己構建九個補丁文件時,android和eclipse都不會將文件作爲可繪製對象。您可以在帖子的末尾看到我使用ImageMagick進行DIY九貼片的腳本。DIY九修補沒有重新調整
如果我使用DIY ninepatch,它不起作用。如果我用draw9patch打開它並保存並退出,它就可以工作!是否有任何特定的需要做DIY九貼?
我希望你能幫助我!
非常感謝。
# 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
(對不起,我不能發表圖片呢!)
請執行項目在Eclipse乾淨,然後張貼錯誤沒有顯示在控制檯。還張貼最後的9png,以便我們可以看到實際繪製的內容。 – Theo 2012-03-29 17:35:09
後前及在draw9patch保存後9修補圖像。 – 2012-03-29 18:26:52