`
kanwoerzi
  • 浏览: 1645088 次
文章分类
社区版块
存档分类
最新评论

个性缩放图片NinePatchDrawable

 
阅读更多
NinePatchDrawable<wbr style="line-height:25px"><br style="line-height:25px"><span style="color:#000080; line-height:25px"><wbr style="line-height:25px">A</wbr></span><span style="color:#ff00ff; line-height:25px">NinePatchDrawable</span><span style="color:#000080; line-height:25px">graphicisastretchablebitmapimage,<br style="line-height:25px"> whichAndroidwillautomaticallyresizetoaccommodatethecontentsoftheViewinwhichyouhaveplaceditasthebackground.</span><wbr style="line-height:25px"><br style="line-height:25px"> AnexampleuseofaNinePatchisthebackgroundsusedbystandardAndroidbuttons—<br style="line-height:25px"> buttonsmuststretchtoaccommodatestringsofvariouslengths.<br style="line-height:25px"> ANinePatchdrawableisastandardPNGimagethatincl?sanextra1-pixel-wideborder.<br style="line-height:25px"> Itmustbesavedwiththeextension.9.png,andsavedintotheres/drawable/directoryofyourproject.<br style="line-height:25px"><br style="line-height:25px"> Theborderisusedtodefinethestretchableandstaticareasoftheimage.<br style="line-height:25px"> Youindicateastretchablesectionbydrawingone(ormore)1-pixel-wideblackline(s)intheleftandtoppartoftheborder.<br style="line-height:25px"> (Youcanhaveasmanystretchablesectionsasyouwant.)Therelativesizeofthestretchablesectionsstaysthesame,<br style="line-height:25px"> sothelargestsectionsalwaysremainthelargest.<br style="line-height:25px"><br style="line-height:25px"> Youcanalsodefineanoptionaldrawablesectionoftheimage(effectively,thepaddinglines)<br style="line-height:25px"> bydrawingalineontherightandbottomlines.IfaViewobjectsetstheNinePatchasitsbackground<br style="line-height:25px"> andthenspecifiestheView'stext,itwillstretchitselfsothatallthetextfitsinsideonly<br style="line-height:25px"> theareadesignatedbytherightandbottomlines(ifincl?d).Ifthepaddinglinesarenotincl?d,<br style="line-height:25px"> Androidusestheleftandtoplinestodefinethisdrawablearea.<br style="line-height:25px"><br style="line-height:25px"> Toclarifythedifferencebetweenthedifferentlines,<br style="line-height:25px"> theleftandtoplinesdefinewhichpixelsoftheimageareallowedtobereplicatedinordertostretchtheimage.<br style="line-height:25px"> ThebottomandrightlinesdefinetherelativeareawithintheimagethatthecontentsoftheViewareallowedtoliewithin.<br style="line-height:25px"><span style="color:#003366; line-height:25px"><wbr style="line-height:25px">A</wbr></span><span style="color:#ff00ff; line-height:25px">NinePatchDrawable</span><span style="color:#003366; line-height:25px">相对于</span><span style="color:#ff9900; line-height:25px">Bitmap Drawable</span><span style="color:#003366; line-height:25px">主要有增加了两个属性。他主要定义了图片的两类可区域。<br style="line-height:25px"> 一类是一般的可扩展(放大)区域区域,他主要用来填充控件的空白区域。<br style="line-height:25px"> 另一类区域主要用于填充内容区域(比如对于button来说内容区域就是其文本区域)<wbr style="line-height:25px">。</wbr></span><br style="line-height:25px"> 注意:<br style="line-height:25px"> ThisNinePatchdefinesonestretchableareawiththeleft<br style="line-height:25px"> andtoplinesandthedrawableareawiththebottomandrightlines.<br style="line-height:25px"> Inthetopimage,thedottedgreylinesidentifytheregionsoftheimagethatwillbereplicatedinordertostretchtheimage.<br style="line-height:25px"> ThepinkrectangleinthebottomimageidentifiestheregioninwhichthecontentsoftheViewareallowed.<br style="line-height:25px"> Ifthecontentsdon'tfitinthisregion,thentheimagewillbestretchedsothattheydo.<br style="line-height:25px"><wbr style="line-height:25px"><span style="color:#000080; line-height:25px">使用</span><span style="color:#ff6600; line-height:25px">Draw9-patch</span><span style="color:#000080; line-height:25px">创建</span><span style="color:#ff00ff; line-height:25px">NinePatchDrawable</span><span style="color:#000080; line-height:25px">形式的图(.9.png)</span><wbr style="line-height:25px"><br style="line-height:25px"><br style="line-height:25px"> theDraw9-patchtoolallowsyoutoeasilycreateaNinePatchgraphicusingaWYSIWYGeditor.<br style="line-height:25px"> Foranintrod tiontoNine-patchgraphicsandhowtheywork,<br style="line-height:25px"> pleasereadthesectiononNine-patchintheNinepatchImagestopic.<br style="line-height:25px"> Here'saquickguidetocreateaNine-patchgraphicusingtheDraw9-patchtool.You'llneedthePNGimagewithwhichyou'dliketocreateaNinePatch.<br style="line-height:25px"><br style="line-height:25px"> 1.Fromaterminal,launchthedraw9patchapplicationfromyour<span style="color:#000080; line-height:25px">SDK/toolsdirectory</span>.<br style="line-height:25px"> 2.DragyourPNGimageintotheDraw9-patchwindow(orFile&gt;Open9-patch...tolocatethefile).Yourworkspacewillnowopen.<br style="line-height:25px"> Theleftpaneisyourdrawingarea,inwhichyoucaneditthelinesforthestretchablepatchesandcontentarea.<br style="line-height:25px"> Therightpaneisthepreviewarea,whereyoucanpreviewyourgraphicwhenstretched.<br style="line-height:25px"> 3.Clickwithinthe1-pixelperimetertodrawthelinesthatdefinethestretchablepatchesand(optional)contentarea.<br style="line-height:25px"> Right-click(orholdShiftandclick,onMac)toerasepreviouslydrawnlines.<br style="line-height:25px"><wbr style="line-height:25px"><span style="color:#003366; line-height:25px">可以在图片的框的四边上,按下鼠标左键并拖动可以画黑线,按下shift键的同时按鼠标左键并拖动可清除画的黑线。</span><wbr style="line-height:25px"><br style="line-height:25px"><wbr style="line-height:25px"><span style="line-height:25px">A,</span><span style="color:#003366; line-height:25px">左边那条黑色线代表图片垂直拉伸的区域,上边的那条黑色线代表水平拉伸区域。</span><wbr style="line-height:25px"><br style="line-height:25px"><span style="color:#000080; line-height:25px">他们的交集就区域代表就垂直拉伸和水平拉伸都可以进行的区域。</span><br style="line-height:25px"> 注意:我开始因为它是表达的只是他们的交集区域。<br style="line-height:25px"> 其实不是,它要表达的垂直拉伸和水平拉伸区域,不能只是交集区域。<br style="line-height:25px"> 因为如果只是交集区域的话,图片一放大,就不是长方形了。<br style="line-height:25px"><wbr style="line-height:25px"><span style="line-height:25px">B,</span><span style="color:#000080; line-height:25px">右边的黑色线代表内容绘制的垂直区域,下边的黑色线代表内容绘制的水平区域</span><wbr style="line-height:25px"><br style="line-height:25px"><span style="color:#000080; line-height:25px">他们交集的区域就是内容所要绘制到的区域。<br style="line-height:25px"> 对于button来说就是文本的区域,这样就可以控制文本显示的区域。<br style="line-height:25px"><wbr style="line-height:25px">如果</wbr></span><span style="color:#0000ff; line-height:25px">下边</span><span style="color:#000080; line-height:25px">和</span><span style="color:#0000ff; line-height:25px">右边</span><span style="color:#000080; line-height:25px">的黑线不是连续的,那它按</span><span style="color:#0000ff; line-height:25px">最左端(上端)和最右端(下端)</span><span style="color:#000080; line-height:25px">组成的线段来算内容区域<wbr style="line-height:25px">。</wbr></span><br style="line-height:25px"> 注意:右边和下边的线是<span style="line-height:25px"><wbr style="line-height:25px">可选</wbr></span><wbr style="line-height:25px">的,左边和上边的线<span style="line-height:25px"><wbr style="line-height:25px">不能省略</wbr></span><wbr style="line-height:25px">。<br style="line-height:25px"><br style="line-height:25px"> 4.Whendone,selectFile&gt;Save9-patch...<br style="line-height:25px"> Yourimagewillbesavedwiththe.9.pngfilename.<br style="line-height:25px"> Draw9-patch的使用,<br style="line-height:25px"> NinePatchDrawable的使用和一般的Drawable一样,也是放在目录drawable下,<br style="line-height:25px"> xml中引用如<span style="color:#0000ff; line-height:25px">android:background="@drawable/test"</span>的形式,其中"test"为文件名<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">参考资料:</wbr></span><a target="_blank" rel="nofollow" href="http://www.coolapk.com/docs/guide/developing/tools/draw9patch.html" style="color:rgb(207,121,28); line-height:25px; text-decoration:none">http://www.coolapk.com/docs/guide/developing/tools/draw9patch.html</a><br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px"><br style="line-height:25px"> NinePatch</wbr></span><wbr style="line-height:25px"><br style="line-height:25px"> TheNinePatchclasspermitsdrawingabitmapinninesections.<br style="line-height:25px"> Thefourcornersareunscaled;thefouredgesarescaledinoneaxis,<br style="line-height:25px"> andthemiddleisscaledinbothaxes.Normally,<br style="line-height:25px"> themiddleistransparentsothatthepatchcanprovideaselectionaboutarectangle.<br style="line-height:25px"> Essentially,itallowsthecreationofcustomgraphicsthatwillscalethewaythatyoudefine,<br style="line-height:25px"> whencontentaddedwithintheimageexceedsthenormalboundsofthegraphic.<br style="line-height:25px"> ForathoroughexplanationofaNinePatchimage,readthediscussioninthe2DGraphicsdocument.<br style="line-height:25px"> TheDraw9-PatchtooloffersanextremelyhandywaytocreateyourNinePatchimages,usingaWYSIWYGgraphicseditor.<br style="line-height:25px"><wbr style="line-height:25px"><span style="color:#003366; line-height:25px">他可以让我们在运行时定制stretchable的区域和区域的填充方式<wbr style="line-height:25px">。</wbr></span><br style="line-height:25px"> 它的构造函数只有一个。<br style="line-height:25px"><span style="line-height:normal; color:rgb(51,51,51); font-family:arial,sans-serif; font-size:13px"></span> <table id="pubctors" style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:1em; margin-left:1em; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; font-size:0.9em; border-collapse:collapse; empty-cells:show; width:933px"><tbody style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <tr style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial"> <th colspan="12" style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:6px; padding-right:12px; padding-bottom:6px; padding-left:12px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); text-align:left; vertical-align:top; background-color:rgb(222,232,241)"> Public Constructors</th> </tr> <tr style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:0px; padding-right:0px; padding-bottom:0px; padding-left:0px; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; background-color:rgb(246,246,246)"> <td style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:6px; padding-right:12px; padding-bottom:6px; padding-left:12px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); text-align:right; vertical-align:top; background-color:inherit"> <nobr style="line-height:21px"></nobr> </td> <td width="100%" style="line-height:21px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:6px; padding-right:12px; padding-bottom:6px; padding-left:12px; border-top-width:1px; border-right-width:1px; border-bottom-width:1px; border-left-width:1px; border-style:initial; border-color:initial; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-top-color:rgb(204,204,204); border-right-color:rgb(204,204,204); border-bottom-color:rgb(204,204,204); border-left-color:rgb(204,204,204); text-align:left; vertical-align:top; background-color:inherit"> <nobr style="line-height:21px"><span style="line-height:21px; margin-right:2px"><a rel="nofollow" href="http://developer.android.com/reference/android/graphics/NinePatch.html#NinePatch(android.graphics.Bitmap,%20byte%5B%5D,%20java.lang.String)" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">NinePatch</a></span>(<a rel="nofollow" href="http://developer.android.com/reference/android/graphics/Bitmap.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">Bitmap</a>bitmap, byte[] chunk,<a rel="nofollow" href="http://developer.android.com/reference/java/lang/String.html" style="color:rgb(0,102,153); line-height:21px; text-decoration:none">String</a>srcName)</nobr><div style="line-height:25px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; padding-top:3px; padding-right:1em; padding-bottom:0px; padding-left:1em; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial; border-style:initial; border-color:initial"> Create a drawable projection from a bitmap to nine patches.</div> </td> </tr> </tbody></table></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>它的jni函数在frameworks\base\core\jni\android\graphics\NinePatch.cpp
这里的byte[]chunk数据的格式一直不明白。
最后参看Android源码总算明白了。
chunk在jni(NinePatch.cpp)中主要用来构造Res_png_9patch这个结构体
chunk的至少有个sizeof(Res_png_9patch)大,即32个字节
Res_png_9patch的申明在

frameworks\base\incl?\utils\ResourceTypes.h
网上地址:http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=incl?/utils/ResourceTypes.h
Res_png_9patch的定义在frameworks\base\libs\utils\ResourceTypes.cpp中。
/**
44*Thischunkspecifieshowtosplitanimageintosegmentsfor
45*scaling.
46*
47*ThereareJhorizontalandKverticalsegments.Thesesegmentsdivide
48*theimageintoJ*Kregionsasfollows(whereJ=4andK=3):
49*
50*F0S0F1S1
51*+-----+----+------+-------+
52*S2|0|1|2|3|
53*+-----+----+------+-------+
54*|||||
55*|||||
56*F2|4|5|6|7|
57*|||||
58*|||||
59*+-----+----+------+-------+
60*S3|8|9|10|11|
61*+-----+----+------+-------+
62*
63*Eachhorizontalandverticalsegmentisconsideredtobyeither
64*stretchable(markedbytheSxlabels)orfixed(markedbytheFy
65*labels),inthehorizontalorverticalaxis,respectively.Inthe
66*aboveexample,thefirstishorizontalsegment(F0)isfixed,the
67*nextisstretchableandthentheycontintoalternate.Notethat
68*thesegmentlistforeachaxiscanbeginorendwithastretchable
69*orfixedsegment.
70*
71*Therelativesizesofthestretchysegmentsindicatestherelative
72*amountofstretchinessoftheregionsborderedbythesegments.For
73*example,regions3,7and11abovewilltakeupmorehorizontalspace
74*thanregions1,5and9sincethehorizontalsegmentassociatedwith
75*thefirstsetofregionsislargerthantheothersetofregions.The
76*ratiosoftheamountofhorizontal(orvertical)spacetakenbyany
77*twostretchableslicesisexactlytheratiooftheircorresponding
78*segmentlengths.
79*
80*xDivsandyDivspointtoarraysofhorizontalandverticalpixel
81*indices.ThefirstpairofDivs(ineitherarray)indicatethe
82*startingandendingpointsofthefirststretchablesegmentinthat
83*axis.Thenextpairspecifiesthenextstretchablesegment,etc.So
84*intheaboveexamplexDiv[0]andxDiv[1]specifythehorizontal
85*coordinatesfortheregionslabeled1,5and9.xDiv[2]and
86*xDiv[3]specifythecoordinatesforregions3,7and11.Notethat
87*theleftmostslicesalwaysstartatx=0andtherightmostslices
88*alwaysendattheendoftheimage.So,forexample,theregions0,
89*4and8(whicharefixedalongtheXaxis)startatxval0and
90*gotoxDiv[0]andslices2,6and10startatxDiv[1]andendat
91*xDiv[2].
92*
93*Thearraypointedtobythecolorsfieldlistscontainshintsfor
94*eachoftheregions.Theyareorderedaccordingleft-to-rightand
95*top-to-bottomasindicatedabove.Foreachsegmentthatisasolid
96*colorthearrayentrywillcontainthatcolorval;otherwiseit
97*willcontainNO_COLOR.Segmentsthatarecompletelytransparent
98*willalwayshavethevalTRANSPARENT_COLOR.
99*
100*ThePNGchunktypeis"npTc".
101*/
102str tRes_png_9patch
103{
104Res_png_9patch():wasDeserialized(false),xDivs(NULL),
105yDivs(NULL),colors(NULL){}
106
107int8_twasDeserialized;
108int8_tnumXDivs;
109int8_tnumYDivs;
110int8_tnumColors;
111
112//Thesetellwherethenextsectionofapatchstarts.
113//Forexample,thefirstpatchincl?sthepixelsfrom
114//0toxDivs[0]-1andthesecondpatchincl?sthepixels
115//fromxDivs[0]toxDivs[1]-1.
116//Note:allocation/freeofthesepointersislefttothecaller.
117int32_t*xDivs;
118int32_t*yDivs;
119
120int32_tpaddingLeft,paddingRight;
121int32_tpaddingTop,paddingBottom;
122
123enum{
124//The9patchsegmentisnotasolidcolor.
125<wbr style="line-height:25px">NO_COLOR=0x00000001,</wbr><wbr style="line-height:25px"><br style="line-height:25px"> 126127//The9patchsegmentiscompletelytransparent.<br style="line-height:25px"> 128<span style="line-height:25px"><wbr style="line-height:25px">TRANSPARENT_COLOR=0x00000000</wbr></span><wbr style="line-height:25px"><br style="line-height:25px"> 129};<br style="line-height:25px"> 130//Note:allocation/freeofthispointerislefttothecaller.<br style="line-height:25px"> 131uint32_t*colors;<br style="line-height:25px"> 132<br style="line-height:25px"> 133//ConvertdatafromdevicerepresentationtoPNGfilerepresentation.<br style="line-height:25px"> 134voiddeviceToFile();<br style="line-height:25px"> 135//ConvertdatafromPNGfilerepresentationtodevicerepresentation.<br style="line-height:25px"> 136voidfileToDevice();<br style="line-height:25px"> 137//Serialize/Marshallthepatchdataintoanewlymalloc-edblock<br style="line-height:25px"> 138void*serialize();<br style="line-height:25px"> 139//Serialize/Marshallthepatchdata<br style="line-height:25px"> 140voidserialize(void*outData);<br style="line-height:25px"> 141//Deserialize/Unmarshallthepatchdata<br style="line-height:25px"> 142staticRes_png_9patch*deserialize(constvoid*data);<br style="line-height:25px"> 143//Computethesizeoftheserializeddatastr ture<br style="line-height:25px"> 144size_tserializedSize();<br style="line-height:25px"> 145};<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">注意1</wbr></span><wbr style="line-height:25px">:Res_png_9patch的大小为32<br style="line-height:25px"> //Thesizeofthisstr tis32bytesonthe32-bittargetsystem<br style="line-height:25px"> //4*int8_t<br style="line-height:25px"> //4*int32_t<br style="line-height:25px"> //3*pointer<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">注意2</wbr></span><wbr style="line-height:25px">:xDivs和yDivs用于确定可stretchable区域。<br style="line-height:25px"> 比如:<br style="line-height:25px"> xDivs[0]和xDivs[1]确定一块可stretchable区域,<br style="line-height:25px"> 然后xDivs[2]和xDivs[3]又确定一块可stretchable区域<br style="line-height:25px"> yDivs和xDivs一样。<br style="line-height:25px"> 注意2:colors指明了每个区域的填充颜色。<br style="line-height:25px"> 这里的区域并不区分非stretchable区域和stretchable区域<br style="line-height:25px"> 其中NO_COLOR=0x00000001,表示用图片的填充<br style="line-height:25px"> TRANSPARENT_COLOR=0x00000000表示完全透明。<br style="line-height:25px"> 区域的顺序是从左到右,再从下到下。<br style="line-height:25px"><span style="color:#003366; line-height:25px">下<wbr style="line-height:25px">面详细说明byte[]chunk的和Res_png_9patch中变量的对应关系</wbr></span><wbr style="line-height:25px">。<br style="line-height:25px"><span style="color:#000080; line-height:25px">第0个字节wasDeserialized备注<br style="line-height:25px"> 第1个字节numXDivsX方向可stretchable的区域数量<br style="line-height:25px"> 第2个字节numYDivsY方向可stretchable的区域数量<br style="line-height:25px"> 第3个字节numColorscolor数(每个区域对应一个color)<br style="line-height:25px"> 第4,5,6,7字节xDivsz指针在chunk中没意义<br style="line-height:25px"> 第8,9,10,11字节yDivsz指针在chunk中没意义<br style="line-height:25px"> 第12,13,14,15字节paddingLeft没发现有什么用<br style="line-height:25px"> 第16,17,18,19字节paddingRight没发现有什么用<br style="line-height:25px"> 第20,21,22,23字节paddingTop没发现有什么用<br style="line-height:25px"> 第24,25,26,27字节paddingBottom没发现有什么用<br style="line-height:25px"> 第28,29,30,31字节colors指针在chunk中没意义</span><br style="line-height:25px"> 从sizeof(Res_png_9patch)开始的数据(即第32个字节开始):<br style="line-height:25px"> 首先是xDivsz指针指向的内容,其大小为numXDivs个int32_t<br style="line-height:25px"> 然后是yDivs指针指向的内容,其大小为numYDivs个int32_t<br style="line-height:25px"> 最后是colors指针指向的内容,其大小为numColors个int32_t(ARGB格式)<br style="line-height:25px"> 注意:对于int32_t这种多字节的类型是高字节在内存的高位<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">示例1</wbr></span><wbr style="line-height:25px">:<span style="line-height:25px"><wbr style="line-height:25px"><br style="line-height:25px"> 代码1</wbr></span><wbr style="line-height:25px"><br style="line-height:25px"><span style="color:#3366ff; line-height:25px">BitmapDrawablebitmapDrawable=(BitmapDrawable)context.getResources().getDrawable(R.drawable.icon);<br style="line-height:25px"> Bitmapbitmap=bitmapDrawable.getBitmap();<br style="line-height:25px"> intwidth=bitmap.getWidth();<br style="line-height:25px"> System.out.println("width:"+width);<br style="line-height:25px"></span><span style="color:#0000ff; line-height:25px">bytenumXDivs=4;<br style="line-height:25px"> bytenumYDivs=4;<br style="line-height:25px"> bytenumColors=numXDivs;<br style="line-height:25px"> intpaddingLeft=10;<br style="line-height:25px"> intoffset=0;<br style="line-height:25px"> numColors=(byte)((numColors+1)*(numYDivs+1));</span><br style="line-height:25px"><span style="color:#3366ff; line-height:25px"></span><span style="color:#993300; line-height:25px">int</span><span style="color:#3366ff; line-height:25px">size=32+(numXDivs+numYDivs+numColors)*4;<br style="line-height:25px"> bytechunk[]=newbyte[size];<br style="line-height:25px"> chunk[0]=0;<br style="line-height:25px"> chunk[1]=numXDivs;<br style="line-height:25px"> chunk[2]=numYDivs;<br style="line-height:25px"> chunk[3]=numColors;<br style="line-height:25px"> bytepVal=0;<br style="line-height:25px"> chunk[4]=pVal;<br style="line-height:25px"> chunk[5]=pVal;<br style="line-height:25px"> chunk[6]=pVal;<br style="line-height:25px"> chunk[7]=pVal;<br style="line-height:25px"><br style="line-height:25px"> chunk[8]=pVal;<br style="line-height:25px"> chunk[9]=pVal;<br style="line-height:25px"> chunk[10]=pVal;<br style="line-height:25px"> chunk[11]=pVal;<br style="line-height:25px"> offset=12;<br style="line-height:25px"> putInt(chunk,offset,paddingLeft);<br style="line-height:25px"> offset+=4;<br style="line-height:25px"> offset=32;<br style="line-height:25px"> putInt(chunk,offset,10);<br style="line-height:25px"> offset+=4;<br style="line-height:25px"> putInt(chunk,offset,30);<br style="line-height:25px"> offset+=4;<br style="line-height:25px"> putInt(chunk,offset,40);<br style="line-height:25px"> offset+=4;<br style="line-height:25px"> putInt(chunk,offset,width);<br style="line-height:25px"> offset+=4;<br style="line-height:25px"><br style="line-height:25px"> putInt(chunk,offset,11);<br style="line-height:25px"> offset+=4;<br style="line-height:25px"> putInt(chunk,offset,18);<br style="line-height:25px"> offset+=4;<br style="line-height:25px"> putInt(chunk,offset,30);<br style="line-height:25px"> offset+=4;<br style="line-height:25px"> putInt(chunk,offset,56);<br style="line-height:25px"> offset+=4;<br style="line-height:25px"> intcolor=0x00000F;<br style="line-height:25px"> intcolor2=0xFFFFF0;<br style="line-height:25px"> intcolorInc=(color2-color)/numColors;<br style="line-height:25px"></span><span style="color:#993300; line-height:25px">for</span><span style="color:#3366ff; line-height:25px">(inti=0;i&lt;numColors;i++)<br style="line-height:25px"> {<br style="line-height:25px"> putInt(chunk,offset,0x2F000000|color);<br style="line-height:25px"> offset+=4;<br style="line-height:25px"> color+=colorInc;<br style="line-height:25px"> }<br style="line-height:25px"></span><span style="color:#0000ff; line-height:25px">img9Patch=newNinePatch(bitmap,chunk,null);</span><br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">代码2</wbr></span><wbr style="line-height:25px">:<br style="line-height:25px"><span style="color:#3366ff; line-height:25px"></span><span style="color:#993300; line-height:25px">staticvoid</span><span style="color:#3366ff; line-height:25px"></span><span style="color:#993300; line-height:25px">putInt</span><span style="color:#3366ff; line-height:25px">(bytearray[],intoffset,intval)<br style="line-height:25px"> {<br style="line-height:25px"> array[offset]=(byte)(val&amp;0xFF);<br style="line-height:25px"> val=val&gt;&gt;8;<br style="line-height:25px"> array[offset+1]=(byte)(val&amp;0xFF);<br style="line-height:25px"> val=val&gt;&gt;8;<br style="line-height:25px"> array[offset+2]=(byte)(val&amp;0xFF);<br style="line-height:25px"> val=val&gt;&gt;8;<br style="line-height:25px"> array[offset+3]=(byte)(val&amp;0xFF);<br style="line-height:25px"> }</span><br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">代码3</wbr></span><wbr style="line-height:25px">:<br style="line-height:25px"><span style="color:#0000ff; line-height:25px">RectFrect=newRectF(0,0,Game.width,Game.height);<br style="line-height:25px"> img9Patch.draw(canvas,rect);</span><br style="line-height:25px"><span style="line-height:25px">注意1</span>:rect是要把img9Patch画到的区域。 </wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
分享到:
评论

相关推荐

    NinePatchDrawable读取非资源图片

    NinePatchDrawable读取非资源图片,经本人测试过,正常读取,解决了check[]为空造成activity崩溃的现象。分是高了点,但是对于苦苦找不到解决方法的情况下,绝对是物超所值的。

    读取非资源图片转化成 NinePatchDrawable

    读取非资源图片转化成 NinePatchDrawable,好用本人请测试过。解决网络下载的9.png放到sd卡上,再用那个来源于sd读取就出问题的情况。

    TestNinePatchDrawable.rar

    工程里面用的.9.png在打包的时候,经过了aapt的处理,成为了一张包含有特殊信息的.png图片。而不是直接加载的.9.png这种图片。所以一般情况下我们需要自己手动的调用aapt命令来处理点9图。这是一个不用调aapt命令...

    Android学习系列教程实例.pdf

    目录 Android 学习文档总结 ................... 1 DevDiv 推荐资源 ........................ 2 Windows 8 ..............................................................iOS .......................................

    代码.zip代码.zip代码数据分析代码.zip代码.zip代码数据分析

    代码.zip代码.zip代码数据分析

    STM32数字示波器+详细注释+上位机程序+硬件

    功能: 1、波形发生器:使用STM32一路DA实现正弦,三角波,方波,白噪声输出。 任意一种波形幅值在0-3.3V任意可调、频率在一定范围任意可调、方波占空比可调。调节选项可以通过触摸屏完成设置。 2、SD卡存储: SD卡波形存储输出,能够对当前屏幕截屏,以JPG格式存储在SD卡上。能够存储1S内的波形数据,可以随时调用查看。 3、数据传输: 用C#编写上位机,通过串口完成对下位机的控制。(1)实现STOP/RUN功能(2)输出波形电压、时间参数(3)控制截屏(4)控制波形发生器(5)控制完成FFT(6)波形的存储和显示 4、图形接口: UCGUI 2、水平扫速: 250 ns*、500ns、1μs、5 μs、10μs、50μs、500 μs、5ms 、50ms 3、垂直电压灵敏度:10mV/div, 20mV/div, 50mV/div, 0.1V/div, 0,2V/div, 0.5V/div, 1V/div, 2V/div, 5V/div 4、被测信号的各种参数屏幕显示,包括频率、电压峰峰值等。

    粗格栅及进水提升泵房计算书.xlsx

    污水处理计算书

    氧化沟工艺在污水处理中的应用.doc

    课程设计污水处理

    node-v11.10.0-linux-arm64.tar.xz

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

    JSP企业电子投票系统(源代码+设计说明书+调研报告++文献综述).zip

    JSP企业电子投票系统(源代码+设计说明书+调研报告++文献综述).zip

    node-v10.18.1-linux-s390x.tar.xz

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

    node-v12.22.7-linux-armv7l.tar.xz

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

    node-v10.22.0-darwin-x64.tar.xz

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

    基于matlab实现的能够计算配电网中的潮流,只需在里面填入参数即可运行 .rar

    基于matlab实现的能够计算配电网中的潮流,只需在里面填入参数即可运行。.rar

    基于matlab实现的随机粗糙表面对微气体轴承内气体压强分布的影响.rar

    基于matlab实现的随机粗糙表面对微气体轴承内气体压强分布的影响.rar

    基于使用microPython的开发单片机设计源码.zip

    我们在单片机开发中常会遇到需要将UTF-8转换为GBK编码的需求。在了解各种编码格式的情况下可知, UFT-8不能直接转成GBK,需中转成unicode再转换为gbk。而unicode和gbk之间没有算法可以直接计算,需要查表方式获取。 网上有一些C语言实现的代码,我这里分享一种microPython的实现代码 接下来就是要考虑表的存储方式了,刚开始我想着把表存到代码里直接通过索引实现编码转换。但是gb2312有七千多个字符全部存储要耗费很大内存,即使是32位的esp32也只有512k的内存,加上其他资源的消耗,剩余的内存不足以存储编码转换表。 于是只能将表保存成一个文件(转化成bin文件会比较好,方法类似),通过读写文件来减少内存开销。 具体的查表就是简单的二分法

    基于matlab实现的实现信号的frft变换

    基于matlab实现的实现信号的frft变换,傅立叶变换是将观看角度从时域转变到频域,分数阶傅立叶变换就是以观看时频面的角度去旋转时频面的坐标轴,然后再从观察频域的角度去分析信息。.rar

    node-v11.10.0-linux-ppc64le.tar.xz

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

    杏鲍菇70m3d废水处理工程设计方案.doc

    课程设计污水处理

    node-v10.23.1-darwin-x64.tar.xz

    Node.js,简称Node,是一个开源且跨平台的JavaScript运行时环境,它允许在浏览器外运行JavaScript代码。Node.js于2009年由Ryan Dahl创立,旨在创建高性能的Web服务器和网络应用程序。它基于Google Chrome的V8 JavaScript引擎,可以在Windows、Linux、Unix、Mac OS X等操作系统上运行。 Node.js的特点之一是事件驱动和非阻塞I/O模型,这使得它非常适合处理大量并发连接,从而在构建实时应用程序如在线游戏、聊天应用以及实时通讯服务时表现卓越。此外,Node.js使用了模块化的架构,通过npm(Node package manager,Node包管理器),社区成员可以共享和复用代码,极大地促进了Node.js生态系统的发展和扩张。 Node.js不仅用于服务器端开发。随着技术的发展,它也被用于构建工具链、开发桌面应用程序、物联网设备等。Node.js能够处理文件系统、操作数据库、处理网络请求等,因此,开发者可以用JavaScript编写全栈应用程序,这一点大大提高了开发效率和便捷性。 在实践中,许多大型企业和组织已经采用Node.js作为其Web应用程序的开发平台,如Netflix、PayPal和Walmart等。它们利用Node.js提高了应用性能,简化了开发流程,并且能更快地响应市场需求。

Global site tag (gtag.js) - Google Analytics