java 在画布上绘制九个补丁 (Android)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2127438/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Drawing Nine Patch onto Canvas (Android)
提问by Tom R
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.
我正在尝试在 Android 上的 Canvas 对象上绘制九个补丁。奇怪的是,虽然我使用 draw9patch 工具生成了我的九个补丁,但 NinePatch 的构造函数需要一个额外的字节数组,称为“块”来构造九个补丁。
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.
任何帮助表示赞赏。
回答by Mark B
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);

