1e41f4b71Sopenharmony_ci# Shape
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci绘制组件的父组件,父组件中会描述所有绘制组件均支持的通用属性。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci1、绘制组件使用Shape作为父组件,实现类似SVG的效果。
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci2、绘制组件单独使用,用于在页面上绘制指定的图形。
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci>  **说明:**
10e41f4b71Sopenharmony_ci>
11e41f4b71Sopenharmony_ci>  该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci## 子组件
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci包含[Rect](ts-drawing-components-rect.md)、[Path](ts-drawing-components-path.md)、[Circle](ts-drawing-components-circle.md)、[Ellipse](ts-drawing-components-ellipse.md)、[Polyline](ts-drawing-components-polyline.md)、[Polygon](ts-drawing-components-polygon.md)、[Image](ts-basic-components-image.md)、[Text](ts-basic-components-text.md)、[Column](ts-container-column.md)、[Row](ts-container-row.md)、Shape子组件。
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci## 接口
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ciShape(value?: PixelMap)
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci从API version 9开始,该接口支持在ArkTS卡片中使用,卡片中不支持使用PixelMap对象。
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci**参数:**
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 |
32e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
33e41f4b71Sopenharmony_ci| value | [PixelMap](../../apis-image-kit/js-apis-image.md#pixelmap7) | 否 | 绘制目标,可将图形绘制在指定的PixelMap对象中,若未设置,则在当前绘制目标中进行绘制。 |
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci## 属性
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci### viewPort
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_civiewPort(value: { x?: number | string; y?: number | string; width?: number | string; height?: number | string })
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci设置形状的视口。 
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci**参数:** 
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 |
55e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
56e41f4b71Sopenharmony_ci| value | {<br/>x?:&nbsp;number \| string,<br/>y?:&nbsp;number \| string,<br/>width?:&nbsp;number \| string,<br/>height?:&nbsp;number \| string<br/>} | 是 | 形状的视口。 <br/>默认值:{ x:0, y:0, width:0, height:0 } |
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci### fill
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_cifill(value: ResourceColor)
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ci设置填充区域颜色。异常值按照默认值处理。
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci**参数:** 
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci| 参数名 | 类型                                       | 必填 | 说明                                   |
73e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | -------------------------------------- |
74e41f4b71Sopenharmony_ci| value  | [ResourceColor](ts-types.md#resourcecolor) | 是   | 填充区域颜色。<br/>默认值:Color.Black |
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci### fillOpacity
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_cifillOpacity(value: number | string | Resource)
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci设置填充区域透明度。取值范围是[0.0, 1.0],若给定值小于0.0,则取值为0.0;若给定值大于1.0,则取值为1.0,其余异常值按1.0处理。
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci**参数:** 
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci| 参数名 | 类型                                                         | 必填 | 说明                           |
91e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------ |
92e41f4b71Sopenharmony_ci| value  | number&nbsp;\|&nbsp;string&nbsp;\|&nbsp;[Resource](ts-types.md#resource) | 是   | 填充区域透明度。<br/>默认值:1 |
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci### stroke
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_cistroke(value: ResourceColor)
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci设置边框颜色,不设置时,默认没有边框。异常值不会绘制边框。
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci**参数:** 
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci| 参数名 | 类型                                       | 必填 | 说明       |
109e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | ---------- |
110e41f4b71Sopenharmony_ci| value  | [ResourceColor](ts-types.md#resourcecolor) | 是   | 边框颜色。 |
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ci### strokeDashArray
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_cistrokeDashArray(value: Array&lt;any&gt;)
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci设置边框间隙。异常值按照默认值处理。
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci**参数:** 
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci| 参数名 | 类型             | 必填 | 说明                      |
127e41f4b71Sopenharmony_ci| ------ | ---------------- | ---- | ------------------------- |
128e41f4b71Sopenharmony_ci| value  | Array&lt;any&gt; | 是   | 边框间隙。<br/>默认值:[] |
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ci### strokeDashOffset
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_cistrokeDashOffset(value: number | string)
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ci设置边框绘制起点的偏移量。异常值按照默认值处理。
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ci**参数:** 
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ci| 参数名 | 类型                       | 必填 | 说明                                 |
145e41f4b71Sopenharmony_ci| ------ | -------------------------- | ---- | ------------------------------------ |
146e41f4b71Sopenharmony_ci| value  | number&nbsp;\|&nbsp;string | 是   | 边框绘制起点的偏移量。<br/>默认值:0 |
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ci### strokeLineCap
149e41f4b71Sopenharmony_ci
150e41f4b71Sopenharmony_cistrokeLineCap(value: LineCapStyle)
151e41f4b71Sopenharmony_ci
152e41f4b71Sopenharmony_ci设置边框端点绘制样式。
153e41f4b71Sopenharmony_ci
154e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
157e41f4b71Sopenharmony_ci
158e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
159e41f4b71Sopenharmony_ci
160e41f4b71Sopenharmony_ci**参数:** 
161e41f4b71Sopenharmony_ci
162e41f4b71Sopenharmony_ci| 参数名 | 类型                                              | 必填 | 说明                                             |
163e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------- | ---- | ------------------------------------------------ |
164e41f4b71Sopenharmony_ci| value  | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | 是   | 边框端点绘制样式。<br/>默认值:LineCapStyle.Butt |
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ci### strokeLineJoin
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_cistrokeLineJoin(value: LineJoinStyle)
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci设置边框拐角绘制样式。
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci**参数:** 
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci| 参数名 | 类型                                                | 必填 | 说明                                               |
181e41f4b71Sopenharmony_ci| ------ | --------------------------------------------------- | ---- | -------------------------------------------------- |
182e41f4b71Sopenharmony_ci| value  | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | 是   | 边框拐角绘制样式。<br/>默认值:LineJoinStyle.Miter |
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci### strokeMiterLimit
185e41f4b71Sopenharmony_ci
186e41f4b71Sopenharmony_cistrokeMiterLimit(value: number | string)
187e41f4b71Sopenharmony_ci
188e41f4b71Sopenharmony_ci设置斜接长度与边框宽度比值的极限值。斜接长度表示外边框外边交点到内边交点的距离,边框宽度即strokeWidth属性的值。该属性取值需在strokeLineJoin属性取值LineJoinStyle.Miter时生效。 
189e41f4b71Sopenharmony_ci
190e41f4b71Sopenharmony_ci该属性的合法值范围应当大于等于1.0,当取值范围在[0,1)时按1.0处理,其余异常值按默认值处理。
191e41f4b71Sopenharmony_ci
192e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。
193e41f4b71Sopenharmony_ci
194e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
195e41f4b71Sopenharmony_ci
196e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
197e41f4b71Sopenharmony_ci
198e41f4b71Sopenharmony_ci**参数:** 
199e41f4b71Sopenharmony_ci
200e41f4b71Sopenharmony_ci| 参数名 | 类型                       | 必填 | 说明                                           |
201e41f4b71Sopenharmony_ci| ------ | -------------------------- | ---- | ---------------------------------------------- |
202e41f4b71Sopenharmony_ci| value  | number&nbsp;\|&nbsp;string | 是   | 斜接长度与边框宽度比值的极限值。<br/>默认值:4 |
203e41f4b71Sopenharmony_ci
204e41f4b71Sopenharmony_ci### strokeOpacity
205e41f4b71Sopenharmony_ci
206e41f4b71Sopenharmony_cistrokeOpacity(value: number | string | Resource)
207e41f4b71Sopenharmony_ci
208e41f4b71Sopenharmony_ci设置边框透明度。该属性的取值范围是[0.0, 1.0],若给定值小于0.0,则取值为0.0;若给定值大于1.0,则取值为1.0,其余异常值按1.0处理 。
209e41f4b71Sopenharmony_ci
210e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。
211e41f4b71Sopenharmony_ci
212e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
213e41f4b71Sopenharmony_ci
214e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
215e41f4b71Sopenharmony_ci
216e41f4b71Sopenharmony_ci**参数:** 
217e41f4b71Sopenharmony_ci
218e41f4b71Sopenharmony_ci| 参数名 | 类型                                                         | 必填 | 说明                       |
219e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | -------------------------- |
220e41f4b71Sopenharmony_ci| value  | number&nbsp;\|&nbsp;string&nbsp;\|&nbsp;[Resource](ts-types.md#resource) | 是   | 边框透明度。<br/>默认值:1 |
221e41f4b71Sopenharmony_ci
222e41f4b71Sopenharmony_ci### strokeWidth
223e41f4b71Sopenharmony_ci
224e41f4b71Sopenharmony_cistrokeWidth(value: number | string)
225e41f4b71Sopenharmony_ci
226e41f4b71Sopenharmony_ci设置边框宽度。该属性若为string类型, 暂不支持百分比,百分比按照1px处理。
227e41f4b71Sopenharmony_ci
228e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。
229e41f4b71Sopenharmony_ci
230e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
231e41f4b71Sopenharmony_ci
232e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
233e41f4b71Sopenharmony_ci
234e41f4b71Sopenharmony_ci**参数:** 
235e41f4b71Sopenharmony_ci
236e41f4b71Sopenharmony_ci| 参数名 | 类型                         | 必填 | 说明                     |
237e41f4b71Sopenharmony_ci| ------ | ---------------------------- | ---- | ------------------------ |
238e41f4b71Sopenharmony_ci| value  | number&nbsp;\|&nbsp;string | 是   | 边框宽度。<br/>默认值:1 |
239e41f4b71Sopenharmony_ci
240e41f4b71Sopenharmony_ci### antiAlias
241e41f4b71Sopenharmony_ci
242e41f4b71Sopenharmony_ciantiAlias(value: boolean)
243e41f4b71Sopenharmony_ci
244e41f4b71Sopenharmony_ci设置是否开启抗锯齿效果。
245e41f4b71Sopenharmony_ci
246e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。
247e41f4b71Sopenharmony_ci
248e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
249e41f4b71Sopenharmony_ci
250e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
251e41f4b71Sopenharmony_ci
252e41f4b71Sopenharmony_ci**参数:** 
253e41f4b71Sopenharmony_ci
254e41f4b71Sopenharmony_ci| 参数名 | 类型    | 必填 | 说明                                  |
255e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------- |
256e41f4b71Sopenharmony_ci| value  | boolean | 是   | 是否开启抗锯齿效果。<br/>默认值:true |
257e41f4b71Sopenharmony_ci
258e41f4b71Sopenharmony_ci### mesh<sup>8+</sup>
259e41f4b71Sopenharmony_ci
260e41f4b71Sopenharmony_cimesh(value: Array&lt;number&gt;, column: number, row: number)
261e41f4b71Sopenharmony_ci
262e41f4b71Sopenharmony_ci设置mesh效果。
263e41f4b71Sopenharmony_ci
264e41f4b71Sopenharmony_ci**卡片能力:** 从API version 9开始,该接口支持在ArkTS卡片中使用。
265e41f4b71Sopenharmony_ci
266e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
267e41f4b71Sopenharmony_ci
268e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
269e41f4b71Sopenharmony_ci
270e41f4b71Sopenharmony_ci**参数:** 
271e41f4b71Sopenharmony_ci
272e41f4b71Sopenharmony_ci| 参数名 | 类型                | 必填 | 说明                                                         |
273e41f4b71Sopenharmony_ci| ------ | ------------------- | ---- | ------------------------------------------------------------ |
274e41f4b71Sopenharmony_ci| value  | Array&lt;number&gt; | 是   | 长度(column + 1)* (row + 1)* 2的数组,它记录了扭曲后的位图各个顶点位置。 |
275e41f4b71Sopenharmony_ci| column | number              | 是   | mesh矩阵列数。                                               |
276e41f4b71Sopenharmony_ci| row    | number              | 是   | mesh矩阵行数。                                               |
277e41f4b71Sopenharmony_ci
278e41f4b71Sopenharmony_ci## 示例
279e41f4b71Sopenharmony_ci
280e41f4b71Sopenharmony_ci```ts
281e41f4b71Sopenharmony_ci// xxx.ets
282e41f4b71Sopenharmony_ci@Entry
283e41f4b71Sopenharmony_ci@Component
284e41f4b71Sopenharmony_cistruct ShapeExample {
285e41f4b71Sopenharmony_ci  build() {
286e41f4b71Sopenharmony_ci    Column({ space: 10 }) {
287e41f4b71Sopenharmony_ci      Text('basic').fontSize(11).fontColor(0xCCCCCC).width(320)
288e41f4b71Sopenharmony_ci      // 在Shape的(-2, -2)点绘制一个 300 * 50 带边框的矩形,颜色0x317AF7,边框颜色黑色,边框宽度4,边框间隙20,向左偏移10,线条两端样式为半圆,拐角样式圆角,抗锯齿(默认开启)
289e41f4b71Sopenharmony_ci      // 在Shape的(-2, 58)点绘制一个 300 * 50 带边框的椭圆,颜色0x317AF7,边框颜色黑色,边框宽度4,边框间隙20,向左偏移10,线条两端样式为半圆,拐角样式圆角,抗锯齿(默认开启)
290e41f4b71Sopenharmony_ci      // 在Shape的(-2, 118)点绘制一个 300 * 10 直线路径,颜色0x317AF7,边框颜色黑色,宽度4,间隙20,向左偏移10,线条两端样式为半圆,拐角样式圆角,抗锯齿(默认开启)
291e41f4b71Sopenharmony_ci      Shape() {
292e41f4b71Sopenharmony_ci        Rect().width(300).height(50)
293e41f4b71Sopenharmony_ci        Ellipse().width(300).height(50).offset({ x: 0, y: 60 })
294e41f4b71Sopenharmony_ci        Path().width(300).height(10).commands('M0 0 L900 0').offset({ x: 0, y: 120 })
295e41f4b71Sopenharmony_ci      }
296e41f4b71Sopenharmony_ci      .width(350)
297e41f4b71Sopenharmony_ci      .height(140)
298e41f4b71Sopenharmony_ci      .viewPort({ x: -2, y: -2, width: 304, height: 130 })
299e41f4b71Sopenharmony_ci      .fill(0x317AF7)
300e41f4b71Sopenharmony_ci      .stroke(Color.Black)
301e41f4b71Sopenharmony_ci      .strokeWidth(4)
302e41f4b71Sopenharmony_ci      .strokeDashArray([20])
303e41f4b71Sopenharmony_ci      .strokeDashOffset(10)
304e41f4b71Sopenharmony_ci      .strokeLineCap(LineCapStyle.Round)
305e41f4b71Sopenharmony_ci      .strokeLineJoin(LineJoinStyle.Round)
306e41f4b71Sopenharmony_ci      .antiAlias(true)
307e41f4b71Sopenharmony_ci      // 分别在Shape的(0, 0)、(-5, -5)点绘制一个 300 * 50 带边框的矩形,可以看出之所以将视口的起始位置坐标设为负值是因为绘制的起点默认为线宽的中点位置,因此要让边框完全显示则需要让视口偏移半个线宽
308e41f4b71Sopenharmony_ci      Shape() {
309e41f4b71Sopenharmony_ci        Rect().width(300).height(50)
310e41f4b71Sopenharmony_ci      }
311e41f4b71Sopenharmony_ci      .width(350)
312e41f4b71Sopenharmony_ci      .height(80)
313e41f4b71Sopenharmony_ci      .viewPort({ x: 0, y: 0, width: 320, height: 70 })
314e41f4b71Sopenharmony_ci      .fill(0x317AF7)
315e41f4b71Sopenharmony_ci      .stroke(Color.Black)
316e41f4b71Sopenharmony_ci      .strokeWidth(10)
317e41f4b71Sopenharmony_ci
318e41f4b71Sopenharmony_ci      Shape() {
319e41f4b71Sopenharmony_ci        Rect().width(300).height(50)
320e41f4b71Sopenharmony_ci      }
321e41f4b71Sopenharmony_ci      .width(350)
322e41f4b71Sopenharmony_ci      .height(80)
323e41f4b71Sopenharmony_ci      .viewPort({ x: -5, y: -5, width: 320, height: 70 })
324e41f4b71Sopenharmony_ci      .fill(0x317AF7)
325e41f4b71Sopenharmony_ci      .stroke(Color.Black)
326e41f4b71Sopenharmony_ci      .strokeWidth(10)
327e41f4b71Sopenharmony_ci
328e41f4b71Sopenharmony_ci      Text('path').fontSize(11).fontColor(0xCCCCCC).width(320)
329e41f4b71Sopenharmony_ci      // 在Shape的(0, -5)点绘制一条直线路径,颜色0xEE8443,线条宽度10,线条间隙20
330e41f4b71Sopenharmony_ci      Shape() {
331e41f4b71Sopenharmony_ci        Path().width(300).height(10).commands('M0 0 L900 0')
332e41f4b71Sopenharmony_ci      }
333e41f4b71Sopenharmony_ci      .width(350)
334e41f4b71Sopenharmony_ci      .height(20)
335e41f4b71Sopenharmony_ci      .viewPort({ x: 0, y: -5, width: 300, height: 20 })
336e41f4b71Sopenharmony_ci      .stroke(0xEE8443)
337e41f4b71Sopenharmony_ci      .strokeWidth(10)
338e41f4b71Sopenharmony_ci      .strokeDashArray([20])
339e41f4b71Sopenharmony_ci      // 在Shape的(0, -5)点绘制一条直线路径,颜色0xEE8443,线条宽度10,线条间隙20,向左偏移10
340e41f4b71Sopenharmony_ci      Shape() {
341e41f4b71Sopenharmony_ci        Path().width(300).height(10).commands('M0 0 L900 0')
342e41f4b71Sopenharmony_ci      }
343e41f4b71Sopenharmony_ci      .width(350)
344e41f4b71Sopenharmony_ci      .height(20)
345e41f4b71Sopenharmony_ci      .viewPort({ x: 0, y: -5, width: 300, height: 20 })
346e41f4b71Sopenharmony_ci      .stroke(0xEE8443)
347e41f4b71Sopenharmony_ci      .strokeWidth(10)
348e41f4b71Sopenharmony_ci      .strokeDashArray([20])
349e41f4b71Sopenharmony_ci      .strokeDashOffset(10)
350e41f4b71Sopenharmony_ci      // 在Shape的(0, -5)点绘制一条直线路径,颜色0xEE8443,线条宽度10,透明度0.5
351e41f4b71Sopenharmony_ci      Shape() {
352e41f4b71Sopenharmony_ci        Path().width(300).height(10).commands('M0 0 L900 0')
353e41f4b71Sopenharmony_ci      }
354e41f4b71Sopenharmony_ci      .width(350)
355e41f4b71Sopenharmony_ci      .height(20)
356e41f4b71Sopenharmony_ci      .viewPort({ x: 0, y: -5, width: 300, height: 20 })
357e41f4b71Sopenharmony_ci      .stroke(0xEE8443)
358e41f4b71Sopenharmony_ci      .strokeWidth(10)
359e41f4b71Sopenharmony_ci      .strokeOpacity(0.5)
360e41f4b71Sopenharmony_ci      // 在Shape的(0, -5)点绘制一条直线路径,颜色0xEE8443,线条宽度10,线条间隙20,线条两端样式为半圆
361e41f4b71Sopenharmony_ci      Shape() {
362e41f4b71Sopenharmony_ci        Path().width(300).height(10).commands('M0 0 L900 0')
363e41f4b71Sopenharmony_ci      }
364e41f4b71Sopenharmony_ci      .width(350)
365e41f4b71Sopenharmony_ci      .height(20)
366e41f4b71Sopenharmony_ci      .viewPort({ x: 0, y: -5, width: 300, height: 20 })
367e41f4b71Sopenharmony_ci      .stroke(0xEE8443)
368e41f4b71Sopenharmony_ci      .strokeWidth(10)
369e41f4b71Sopenharmony_ci      .strokeDashArray([20])
370e41f4b71Sopenharmony_ci      .strokeLineCap(LineCapStyle.Round)
371e41f4b71Sopenharmony_ci      // 在Shape的(-20, -5)点绘制一个封闭路径,颜色0x317AF7,线条宽度10,边框颜色0xEE8443,拐角样式锐角(默认值)
372e41f4b71Sopenharmony_ci      Shape() {
373e41f4b71Sopenharmony_ci        Path().width(200).height(60).commands('M0 0 L400 0 L400 150 Z')
374e41f4b71Sopenharmony_ci      }
375e41f4b71Sopenharmony_ci      .width(300)
376e41f4b71Sopenharmony_ci      .height(200)
377e41f4b71Sopenharmony_ci      .viewPort({ x: -20, y: -5, width: 310, height: 90 })
378e41f4b71Sopenharmony_ci      .fill(0x317AF7)
379e41f4b71Sopenharmony_ci      .stroke(0xEE8443)
380e41f4b71Sopenharmony_ci      .strokeWidth(10)
381e41f4b71Sopenharmony_ci      .strokeLineJoin(LineJoinStyle.Miter)
382e41f4b71Sopenharmony_ci      .strokeMiterLimit(5)
383e41f4b71Sopenharmony_ci    }.width('100%').margin({ top: 15 })
384e41f4b71Sopenharmony_ci  }
385e41f4b71Sopenharmony_ci}
386e41f4b71Sopenharmony_ci```
387e41f4b71Sopenharmony_ci
388e41f4b71Sopenharmony_ci![zh-cn_image_0000001184628104](figures/zh-cn_image_0000001184628104.png)
389e41f4b71Sopenharmony_ci