Android Draw 9补丁工具:图外黑线是什么意思

发布于 2024-10-03 15:55:41 字数 601 浏览 1 评论 0原文

我已经尽力在 google & 中找到了安卓这个问题。还做了几次试验&错误,但无法得到这个问题。 我正在学习 Android 的“Draw Nine Patch”图像。我知道的一个基本原则是,您处理的任何图像都必须采用 .png 格式(如果它已经是 .9.png 那么它将被工具忽略)。但是,

  1. 我无法理解“可拉伸补丁”的字面意思是什么?
  2. 当您在 .png 图像之外绘制黑点时,到底会发生什么? (预览窗格显示发生的变化,但我不清楚它是如何实现这些变化的)
  3. 当我在图像的左侧/顶部绘制黑点时,它会在预览中显示一些变化;但是为什么当您在图像的右侧/底部执行相同操作时没有任何效果?
  4. 当我们尝试对图像本身进行处理时,为什么该工具主要用于背景?
  5. 我正在尝试修改一个简单的button.png(在android sdk中给出)。每当我使用这个工具时画黑线,它会缩小图像的大小而不是“拉伸”它!为什么 ?
  6. 下面给出的选项(如“显示锁定”、“显示内容”、“补丁比例”等)的意义是什么?

我很抱歉问了这么多问题,但在 Android 在线文档中,他们没有为新手很好地解释。如果有人能够回答这些问题,那么它将成为所有搜索本论坛的初学者的参考。

I tried enough to find in google & android this question. Also did several trials & errors, but couldn't get this question.
I was learning Android's "Draw Nine Patch" images. One basic I know is that, whatever image you process must be in .png format (if it's already in .9.png then it will be ignored by tool). However,

  1. I couldn't understand what it literally means by "stretchable patches" ?
  2. What exactly happens when you draw black dots outside the .png image ? (preview pane shows changes happening, but I am unclear on how it makes those)
  3. When I draw black dots in left/top sides of image it shows some changes in preview; but why isn't there any effect when you do the same on right/bottom side of the image ?
  4. Why this tool is used primarily for background, when we try to process on the image itself ?
  5. I am trying to modify a simple button.png (given in android sdk). Whenever I use this tool & draw black lines, it reduces the size of the image instead of 'stretching' it! Why ?
  6. What is the significance of options given below like, "show lock", "show content", "Patch scale" and so on ?

I apologize for asking so many questions, but in Android online docs they haven't explained well for novice. If someone can answer these, it will become ready reference for all the begineers who search this forum.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情泪▽动烟 2024-10-10 15:55:42

通过可拉伸补丁,您基本上是在告诉 Android 您想要重复图像中的哪些行和列的像素。当你拉伸标准图像时,有两种可能:一是按比例缩放,但由于插值仍然损失了清晰度;第二,它的比例不成比例,不仅失去了清晰度,而且也失去了形状。下面是不成比例缩放的示例:

stretched

所以黑线的目的是告诉 Android 图像的哪些区域可以安全重复。顶角定义了可以拉伸的列,而左上角定义了可以拉伸的行。底角和右上角仅定义实际内容区域(例如允许按钮放置文本的位置),您可以保留额外的空间来填充框架。在下图中,您可以看到框架外部的两个黑色像素定义了图像上的行,而顶部的黑色像素定义了列。

example

下面显示了 9 补丁拉伸到各种尺寸的结果。如果放大得更宽,则定义的可拉伸列左右两侧的图像将与新尺寸的左右对齐,并重复定义的列以填充之间的空间。定义的行也会发生同样的情况;如果你使用多个(我不相信你可以使用超过 2 个拉伸行/列),它只会用它们均匀地填充空间;在本例中,我用它来保持渐变在中间均匀分布。

拉伸图像结果

By stretchable patches, you're basically telling Android which rows and columns of pixels in the image that you want to repeat. When you stretch a standard image, there are two possibilities: One, it is scaled proportionally, but still loses sharpness due to interpolation; Two, it is scaled disproportionately, and loses not only its sharpness, but its shape as well. An example of a disproportionate scaling is below:

stretched

So the purpose of the black lines it tell Android what areas of the image are safe to repeat. The top corner defines the column(s) that it can stretch, while the left corner defines the row(s) that can stretch. The bottom and right corners just define the actual content area (e.g. where the button is allowed to place text), you can reserve extra space to pad the frame. In the image below, you can see that the two black pixels on the outside of the frame define rows on the image, while the one on top defines a column.

example

And below, this shows the result of a 9-patched stretched out to various sizes. If it's enlarged to be wider, the halves of the image on the left and right of the defined stretchable column are aligned to the left and right of the new size, and the defined column is repeated to fill the space in between. Same thing happens with the defined rows; if you use multiples (I don't believe you can use more than 2 stretch rows/columns) it just evenly pads the space with both of them; in this case I used it to keep the gradient evenly split down the middle.

stretched images result

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文