Brush API
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Brush
API 为您提供了定义笔画视觉样式的工具。您可以创建具有不同颜色、大小和系列的画笔,以实现各种外观。
创建画笔
如需创建 Brush,请使用 Brush
工厂方法,例如 createWithColorIntArgb()
类。您可以使用工厂方法设置以下属性:
- family:笔刷的样式,类似于文本中的字体或字体。
如需了解可用的
BrushFamily
值,请参阅 StockBrushes
。
- color:画笔的颜色。您可以使用
ColorLong
或 ColorInt
设置颜色。
- size:使用画笔创建的笔画的总粗细。
- epsilon:在笔触生成几何图形方面,应将两点视为视觉上不同的最小距离。 epsilon 和笔触点的比率控制着笔触可以放大到多大程度,而不会产生伪影,但会增加内存用量。描边单位的理想起点为 1px, Epsilon 的起点为 0.1。较高的 epsilon 值会使用更少的内存,但在出现三角形伪影之前允许的缩放程度较小;请进行实验,找出适合您的用例的正确值。
val brush = Brush.createWithColorIntArgb(
family = StockBrushes.pressurePenLatest,
colorIntArgb = Color.Black.toArgb(),
size = 5F,
epsilon = 0.1F
)
修改画笔属性
您可以使用 copy()
方法创建现有 Brush 的副本。您可以通过此方法更改 Brush 的任何属性。
val redBrush = Brush.createWithColorIntArgb(
family = StockBrushes.pressurePenLatest,
colorIntArgb = Color.RED.toArgb(),
size = 5F,
epsilon = 0.1F
)
val blueBrush = redBrush.copy(colorIntArgb = Color.BLUE.toArgb())
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Brush APIs\n\nThe [`Brush`](/reference/kotlin/androidx/ink/brush/Brush) APIs provide you with\nthe tools to define the visual style of your strokes. You can create brushes\nwith different colors, sizes, and families to achieve a variety of looks.\n\nCreate a brush\n--------------\n\nTo create a brush, use the [`Brush`](/reference/kotlin/androidx/ink/brush/Brush)\nfactory methods such as\n[`createWithColorIntArgb()`](/reference/kotlin/androidx/ink/brush/Brush#createWithColorIntArgb(androidx.ink.brush.BrushFamily,kotlin.Int,kotlin.Float,kotlin.Float))\nclass. The factory methods let you set the following properties:\n\n- **family** : The style of the brush, analogous to a typeface or font in text. See [`StockBrushes`](/reference/kotlin/androidx/ink/brush/StockBrushes) for available [`BrushFamily`](/reference/kotlin/androidx/ink/brush/BrushFamily) values.\n- **color** : The color of the brush. You can set the color using a [`ColorLong`](/reference/kotlin/androidx/annotation/ColorLong) or [`ColorInt`](/reference/androidx/annotation/ColorInt).\n- **size**: The overall thickness of strokes created with the brush.\n- **epsilon**: The smallest distance for which two points should be considered visually distinct for stroke generation geometry purposes. The ratio of epsilon and stroke points control how much a stroke can be zoomed in without artifacts at the cost of memory. A good starting point for stroke units is 1px, and a good starting point for epsilon is 0.1. Higher epsilon values use less memory but allow for less zoom before triangle artifacts appear; experiment to find the right value for your use case.\n\n val brush = Brush.createWithColorIntArgb(\n family = StockBrushes.pressurePenLatest,\n colorIntArgb = Color.Black.toArgb(),\n size = 5F,\n epsilon = 0.1F\n )\n\nModify brush properties\n-----------------------\n\nYou can create a copy of an existing brush using the\n[`copy()`](/reference/kotlin/androidx/ink/brush/Brush#copy(androidx.ink.brush.BrushFamily,kotlin.Float,kotlin.Float))\nmethod. This method lets you change any of the brush's properties. \n\n val redBrush = Brush.createWithColorIntArgb(\n family = StockBrushes.pressurePenLatest,\n colorIntArgb = Color.RED.toArgb(),\n size = 5F,\n epsilon = 0.1F\n )\n\n val blueBrush = redBrush.copy(colorIntArgb = Color.BLUE.toArgb())"]]