如何创建九个补丁并在我的应用程序中使用它?
我想创建一个九补丁图像并在我的应用程序中使用它,但我不知道如何创建它?
我在网上搜索了 Android 源代码,但似乎找不到任何这样的示例。我需要一个教程,以便我能够理解该过程。
I want to create a nine-patch image and use that in my App but I don't know how to create it?
I've searched through the Android source code on the Web and I can't seem to find any examples of this. I need a tutorial so that I can understand the process.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我刚刚发现了一个非常棒的替代 9patch 编辑器(由 Mikle Garin),我认为它比标准编辑器好 1000%在 sdk 中:
编辑器 JAR下载链接
编辑器源代码
编辑器官方页面
I just found that awesome alternative 9patch editor (by Mikle Garin) and I think it 1000% better than standard one built in sdk:
Editor JAR download link
Editor source code
Editor official page
android sdk 中包含一个工具来创建和测试九个补丁映像:
http://developer.android.com/guide/developing/tools/draw9patch.html
您还可以使用此处的创建指南,使用每个 gfx 包(photoshop、paint.net...)创建九个补丁文件:http://developer.android.com/guide/topics/graphics /2d-graphics.html#nine-patch
There's a tool included in the android sdk to create and test nine patch images:
http://developer.android.com/guide/developing/tools/draw9patch.html
You can also create a nine patch file using every gfx package out there ( photoshop, paint.net, ... ) using the creation guideline here: http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
我创建了一个工具,可以在可拉伸区域为 1 像素宽的简单情况下,从常规 PNG 图像自动创建 9 块图像。以下是示例输入和输出(以 400% 显示):
github 上的项目页面
I've created a tool that allows automatically create 9-patch images from regular PNG images for simple cases where stretchable areas are 1 pixel wide. Here's sample input and output (showed at 400%):
Project page on github
NinePatch 图像是使用 Photoshop、Illustrator、Paint...等创建的标准 PNG 图像。
要向其中添加 NinePatch 规则,只需将其拖放到 Android SDK 目录中的 draw9patch.bat 工具上即可。
如果您不使用draw9patch.bat工具,则必须包含额外的1px透明边框,以使用1px黑色绘制NinePatch规则(#000000) 保存之前的铅笔尺寸。
重要!!! 将扩展名为 myimage.9.png 的图像保存为透明 PNG-8/PNG-24。
图片:NinePatch 图形规则说明
A NinePatch image is a standard PNG image created with Photoshop, Illustrator, Paint... etc.
To add a NinePatch rule to it, just drag/drop it on the draw9patch.bat tool in your Android SDK directory.
IF you don't use the draw9patch.bat tool, you must include an extra 1px transparent border to draw the NinePatch rules with a 1px black (#000000) pencil size before you save it.
Important!!! Save the image with the extension myimage.9.png as a transparent PNG-8/PNG-24.
Image: Explanation of NinePatch graphic rules
我已经搜索了最好和最简单的答案来制作 9 块图像。现在制作 9 个补丁图像是最简单的任务。
从此处您可以制作只需单击一下即可获得适用于所有分辨率的 9 补丁图像 - XHDPI、HDPI、MDPI、LDPI。
如果您有任何疑问,请告诉我,如果对您有帮助,请投票。
I have searched the best and the simplest answer to make 9-patch image. Now to make the 9 patch image is the easiest task.
From HERE you can make a 9-patch image for all the resolutions - XHDPI,HDPI,MDPI,LDPI in just one click.
Let me know if you have any queries, and do upvote it, if it was helpful to you.