Drawing Nine Patch onto Canvas (Android)

好久不见. 提交于 2019-11-30 10:25:37

问题


I'm trying to draw a nine patch onto a Canvas object on the Android. What seems strange is that although I generated my nine patch using the draw9patch tool, the constructor for NinePatch requires an additional byte array called the "chunk" to construct the nine patch.

Why isn't this simpler? What is the "chunk"? And if you have done this yourself, how did you go about it?

Any help appreciated.


回答1:


You can easily do it this way:

// Load the image as a NinePatch drawable
NinePatchDrawable npd = (NinePatchDrawable)Resources.getDrawable(R.drawable.my_nine_patch);

// Set its bound where you need
Rect npdBounds = new Rect(...);
npd.setBounds(npbBounds);

// Finally draw on the canvas
npd.draw(canvas);


来源:https://stackoverflow.com/questions/2127438/drawing-nine-patch-onto-canvas-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!