开发者

Drawing Nine Patch onto Canvas (Android)

开发者 https://www.devze.com 2022-12-17 04:27 出处:网络
I\'m trying to draw a nine patch onto a Canva开发者_开发知识库s object on the Android. What seems strange is that although I generated my nine patch using the draw9patch tool, the constructor for Nine

I'm trying to draw a nine patch onto a Canva开发者_开发知识库s 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.


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消