在运行时创建 NinePatch
我有一个在运行时创建 NinePatchDrawable 对象的业务需求,即从服务器接收外部 .png 图像,并且必须将其作为九个补丁应用到按钮的背景(例如)中。
我尝试创建 NinePatchDrawable 对象,但构造函数要求我提供描述补丁的“byte[] chunk”。问题是,我不知道如何从没有 9patch 信息的位图构建这个块。
关于这个话题有什么想法吗?我是否从错误的角度看待问题?
I have a business need to create the NinePatchDrawable objects at runtime, this is, an exterior .png image is received from a server and it has to be applied in a button's background (for example) as a nine patch.
I have tried to create the NinePatchDrawable object, but the constructor asks me for a "byte[] chunck" that describes the patch. The thing is, I have no idea on how to build this chunk from a bitmap that does not have the 9patch information in it.
Any ideas on this topic? Am I seeing the problem from a wrong perspective?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅我的答案 在运行时创建 NinePatch/NinePatchDrawable
我开发了一个工具来从(未编译的)NinePatch 位图创建 NinePatchDrawable。
请参阅 https://gist.github.com/knight9999/86bec38071a9e0a781ee 。
方法
NinePatchDrawable createNinePatchDrawable(Resources res, Bitmap bitmap)
对你有帮助。
例如,
在
本例中,
my_nine_patch_image.9.png
位于 asset 目录下。See my answer for Create a NinePatch/NinePatchDrawable in runtime
I develop a tool to create NinePatchDrawable from (uncompiled) NinePatch bitmap.
See https://gist.github.com/knight9999/86bec38071a9e0a781ee .
The method
NinePatchDrawable createNinePatchDrawable(Resources res, Bitmap bitmap)
helps you.
For example,
where
In this case, the
my_nine_patch_image.9.png
is under the assets directory.我已经在问题5519768回答了这个问题。请记住“源”和“编译”ninepatch 图像之间的差异。
I've answered this over at question 5519768. Keep in mind the differences between "source" and "compiled" ninepatch images.