1# Polygon 2 3多边形绘制组件。 4 5> **说明:** 6> 7> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 8 9 10## 权限列表 11 12无 13 14 15## 子组件 16 17无 18 19 20## 接口 21 22Polygon(options?: {width?: string | number, height?: string | number}) 23 24**参数:** 25 26| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | 27| -------- | -------- | -------- | -------- | -------- | 28| width | string \| number | 否 | 0 | 宽度。 | 29| height | string \| number | 否 | 0 | 高度。 | 30 31 32## 属性 33 34除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性: 35 36| 名称 | 类型 | 默认值 | 必填 | 描述 | 37| -------- | -------- | -------- | -------- | -------- | 38| points | Array<Point> | [] | 否 | 多边形的顶点坐标列表。 | 39| fill | [ResourceColor](ts-types.md#resourcecolor8) | Color.Black | 否 | 设置填充区域颜色。 | 40| fillOpacity | number \| string \| [Resource](ts-types.md#resource) | 1 | 否 | 设置填充区域透明度。 | 41| stroke | [ResourceColor](ts-types.md#resourcecolor8) | - | 否 | 设置边框颜色,不设置时,默认没有边框线条。 | 42| strokeDashArray | Array<Length> | [] | 否 | 设置边框间隙。 | 43| strokeDashOffset | number \| string | 0 | 否 | 边框绘制起点的偏移量。 | 44| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 否 | 设置边框端点绘制样式。 | 45| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | 否 | 设置边框拐角绘制样式。 | 46| strokeMiterLimit | number \| string | 4 | 否 | 设置斜接长度与边框宽度比值的极限值。斜接长度表示外边框外边交点到内边交点的距离,边框宽度即strokeWidth属性的值。<br/>**说明:**<br/>该属性取值需大于等于1,且在strokeLineJoin属性取值LineJoinStyle.Miter时生效。 | 47| strokeOpacity | number \| string \| [Resource](ts-types.md#resource) | 1 | 否 | 设置边框透明度。<br/>**说明:**<br/>该属性的取值范围是[0.0, 1.0],若给定值小于0.0,则取值为0.0;若给定值大于1.0,则取值为1.0。 | 48| strokeWidth | Length | 1 | 否 | 设置边框宽度。 | 49| antiAlias | boolean | true | 否 | 是否开启抗锯齿效果。 | 50 51## Point 52 53点坐标类型。 54 55| 名称 | 类型定义 | 描述 | 56| --------- | -------------------- | ------------------------------------------------------------ | 57| Point | [number, number] | 第一个参数为x轴坐标,第二个参数为y轴坐标(相对坐标)。 | 58 59 60## 示例 61 62```ts 63// xxx.ets 64@Entry 65@Component 66struct PolygonExample { 67 build() { 68 Column({ space: 10 }) { 69 // 在 100 * 100 的矩形框中绘制一个三角形,起点(0, 0),经过(50, 100),终点(100, 0) 70 Polygon({ width: 100, height: 100 }) 71 .points([[0, 0], [50, 100], [100, 0]]) 72 .fill(Color.Green) 73 // 在 100 * 100 的矩形框中绘制一个四边形,起点(0, 0),经过(0, 100)和(100, 100),终点(100, 0) 74 Polygon().width(100).height(100) 75 .points([[0, 0], [0, 100], [100, 100], [100, 0]]) 76 .fillOpacity(0) 77 .strokeWidth(5) 78 .stroke(Color.Blue) 79 // 在 100 * 100 的矩形框中绘制一个五边形,起点(50, 0),依次经过(0, 50)、(20, 100)和(80, 100),终点(100, 50) 80 Polygon().width(100).height(100) 81 .points([[50, 0], [0, 50], [20, 100], [80, 100], [100, 50]]) 82 .fill(Color.Red) 83 .fillOpacity(0.6) 84 }.width('100%').margin({ top: 10 }) 85 } 86} 87``` 88 89 90