1e41f4b71Sopenharmony_ci# CanvasRenderingContext2D
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciUse **RenderingContext** to draw rectangles, text, images, and other objects on a canvas.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> The APIs of this module are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci## APIs
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ciCanvasRenderingContext2D(settings?: RenderingContextSettings, unit?: LengthMetricsUnit)
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci**Parameters**
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci| Name     | Type | Mandatory  | Description   |
24e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
25e41f4b71Sopenharmony_ci| settings | [RenderingContextSettings](#renderingcontextsettings) | No   | Settings of the **CanvasRenderingContext2D** object. For details, see [RenderingContextSettings](#renderingcontextsettings). |
26e41f4b71Sopenharmony_ci| unit<sup>12+</sup>  | [LengthMetricsUnit](../js-apis-arkui-graphics.md#lengthmetricsunit12) | No   | Unit mode of the **CanvasRenderingContext2D** object. The value cannot be dynamically changed once set. For details, see [LengthMetricsUnit](#lengthmetricsunit12).<br>Default value: **DEFAULT** |
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci### RenderingContextSettings
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ciRenderingContextSettings(antialias?: boolean)
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ciConfigures the settings of a **CanvasRenderingContext2D** object, including whether to enable antialiasing.
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci**Parameters**
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci| Name      | Type   | Mandatory  | Description                         |
44e41f4b71Sopenharmony_ci| --------- | ------- | ---- | ----------------------------- |
45e41f4b71Sopenharmony_ci| antialias | boolean | No   | Whether to enable antialiasing.<br>Default value: **false** |
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci### LengthMetricsUnit<sup>12+</sup>
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ciUnit mode of the **CanvasRenderingContext2D** object. The value cannot be dynamically changed once set. For details, see [LengthMetricsUnit](../js-apis-arkui-graphics.md#lengthmetricsunit12).
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci**Example**
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci```ts
54e41f4b71Sopenharmony_ci// xxx.ets
55e41f4b71Sopenharmony_ciimport { LengthMetricsUnit } from '@kit.ArkUI'
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci@Entry
58e41f4b71Sopenharmony_ci@Component
59e41f4b71Sopenharmony_cistruct LengthMetricsUnitDemo {
60e41f4b71Sopenharmony_ci  private settings: RenderingContextSettings = new RenderingContextSettings(true);
61e41f4b71Sopenharmony_ci  private contextPX: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings, LengthMetricsUnit.PX);
62e41f4b71Sopenharmony_ci  private contextVP: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci  build() {
65e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
66e41f4b71Sopenharmony_ci      Canvas(this.contextPX)
67e41f4b71Sopenharmony_ci        .width('100%')
68e41f4b71Sopenharmony_ci        .height(150)
69e41f4b71Sopenharmony_ci        .backgroundColor('#ffff00')
70e41f4b71Sopenharmony_ci        .onReady(() => {
71e41f4b71Sopenharmony_ci          this.contextPX.fillRect(10,10,100,100)
72e41f4b71Sopenharmony_ci          this.contextPX.clearRect(10,10,50,50)
73e41f4b71Sopenharmony_ci        })
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci      Canvas(this.contextVP)
76e41f4b71Sopenharmony_ci        .width('100%')
77e41f4b71Sopenharmony_ci        .height(150)
78e41f4b71Sopenharmony_ci        .backgroundColor('#ffff00')
79e41f4b71Sopenharmony_ci        .onReady(() => {
80e41f4b71Sopenharmony_ci          this.contextVP.fillRect(10,10,100,100)
81e41f4b71Sopenharmony_ci          this.contextVP.clearRect(10,10,50,50)
82e41f4b71Sopenharmony_ci        })
83e41f4b71Sopenharmony_ci    }
84e41f4b71Sopenharmony_ci    .width('100%')
85e41f4b71Sopenharmony_ci    .height('100%')
86e41f4b71Sopenharmony_ci  }
87e41f4b71Sopenharmony_ci}
88e41f4b71Sopenharmony_ci```
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci![CanvasContext2DUnitMode](figures/CanvasContext2DUnitMode.png)
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci## Attributes
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci| Name | Type | Read Only | Optional | Description |
101e41f4b71Sopenharmony_ci| --------- | ------------------------------- | ------------------ | ---------------------- | ---------------------------------------- |
102e41f4b71Sopenharmony_ci| [fillStyle](#fillstyle) | string \|number<sup>10+</sup> \|[CanvasGradient](ts-components-canvas-canvasgradient.md) \| [CanvasPattern](ts-components-canvas-canvaspattern.md#canvaspattern) | No | No | Style to fill an area.<br>- When the type is string, this attribute indicates the color of the fill area.<br>Default value: **'black'**<br>- When the type is number, this attribute indicates the color of the fill area.<br>Default value: **'#000000'**<br>- When the type is **CanvasGradient**, this attribute indicates a gradient object, which is created using the **[createLinearGradient](#createlineargradient)** API.<br>- When the type is **CanvasPattern**, this attribute indicates a pattern, which is created using the **[createPattern](#createpattern)** API. |
103e41f4b71Sopenharmony_ci| [lineWidth](#linewidth) | number | No | No | Line width.<br>Default value: **1(px)**<br>Default unit: vp<br> The value cannot be **0** or a negative number. If it is set to **0** or a negative number, the default value is used instead.              |
104e41f4b71Sopenharmony_ci| [strokeStyle](#strokestyle)              | string \|number<sup>10+</sup> \|[CanvasGradient](ts-components-canvas-canvasgradient.md) \| [CanvasPattern](ts-components-canvas-canvaspattern.md#canvaspattern)  | No | No | Stroke color.<br> <br>Default value: **'black'**<br> <br>Default value: **'#000000'**<br>- When the type is **CanvasGradient**, this attribute indicates a gradient object, which is created using the **[createLinearGradient](#createlineargradient)** API.<br>- When the type is **CanvasPattern**, this attribute indicates a pattern, which is created using the **[createPattern](#createpattern)** API. |
105e41f4b71Sopenharmony_ci| [lineCap](#linecap)                      | [CanvasLineCap](#canvaslinecap) | No | No | Style of the line endpoints. The options are as follows:<br>- **'butt'**: The endpoints of the line are squared off.<br>- **'round'**: The endpoints of the line are rounded.<br>- **'square'**: The endpoints of the line are squared off by adding a box with an equal width and half the height of the line's thickness.<br>Default value: **'butt'** |
106e41f4b71Sopenharmony_ci| [lineJoin](#linejoin)                    | [CanvasLineJoin](#canvaslinejoin) | No | No | Style of the shape used to join line segments. The options are as follows:<br>- **'round'**: The shape used to join line segments is a sector, whose radius at the rounded corner is equal to the line width.<br>- **'bevel'**: The shape used to join line segments is a triangle. The rectangular corner of each line is independent.<br>- **'miter'**: The shape used to join line segments has a mitered corner by extending the outside edges of the lines until they meet. You can view the effect of this attribute in **miterLimit**.<br>Default value: **'miter'** |
107e41f4b71Sopenharmony_ci| [miterLimit](#miterlimit)                | number | No | No | Maximum miter length. The miter length is the distance between the inner corner and the outer corner where two lines meet.<br>Default value: **10**<br>Unit: px<br>The value cannot be **0** or a negative number. If it is set to **0** or a negative number, the default value is used instead. |
108e41f4b71Sopenharmony_ci| [font](#font)                            | string | No | No | Font style.<br>Syntax: ctx.font='font-size font-family'<br>- (Optional) **font-size**: font size and line height. The unit can be px or vp.<br>- (Optional) **font-family**: font family.<br>Syntax: ctx.font='font-style font-weight font-size font-family'<br>- (Optional) **font-style**: font style. Available values are **'normal'** and **'italic'**.<br>- (Optional) **font-weight**: font weight. Available values are as follows: **'normal'**, **'bold'**, **'bolder'**, **'lighter'**, **'100'**, **'200'**, **'300'**, **'400'**, **'500'**, **'600'**, **'700'**, **'800'**, **'900'**.<br>- (Optional) **font-size**: font size and line height. The unit must be specified and can be px or vp.<br>- (Optional) **font-family**: font family. Available values are **'sans-serif'**, **'serif'**, and **'monospace'**.<br>Default value: **'normal normal 14px sans-serif'** |
109e41f4b71Sopenharmony_ci| [textAlign](#textalign)                  | [CanvasTextAlign](#canvastextalign) | No | No | Text alignment mode. Available values are as follows:<br>- **'left'**: The text is left-aligned.<br>- **'right'**: The text is right-aligned.<br>- **'center'**: The text is center-aligned.<br>- **'start'**: The text is aligned with the start bound.<br>- **'end'**: The text is aligned with the end bound.<br>In the **ltr** layout mode, the value **'start'** equals **'left'**. In the **rtl** layout mode, the value **'start'** equals **'right'**.<br>Default value: **'left'** |
110e41f4b71Sopenharmony_ci| [textBaseline](#textbaseline)            | [CanvasTextBaseline](#canvastextbaseline) | No | No | Horizontal alignment mode of text. Available values are as follows:<br>- **'alphabetic'**: The text baseline is the normal alphabetic baseline.<br>- **'top'**: The text baseline is on the top of the text bounding box.<br>- **'hanging'**: The text baseline is a hanging baseline over the text.<br>- **'middle'**: The text baseline is in the middle of the text bounding box.<br>**'ideographic'**: The text baseline is the ideographic baseline. If a character exceeds the alphabetic baseline, the ideographic baseline is located at the bottom of the excess character.<br>- **'bottom'**: The text baseline is at the bottom of the text bounding box. Its difference from the ideographic baseline is that the ideographic baseline does not consider letters in the next line.<br>Default value: **'alphabetic'** |
111e41f4b71Sopenharmony_ci| [globalAlpha](#globalalpha)              | number | No | No | Opacity.<br>**0.0**: completely transparent.<br>**1.0**: completely opaque.<br>Default value: **1.0** |
112e41f4b71Sopenharmony_ci| [lineDashOffset](#linedashoffset)        | number | No | No | Offset of the dashed line. The precision is float.<br>Default value: **0.0**<br>Unit: px |
113e41f4b71Sopenharmony_ci| [globalCompositeOperation](#globalcompositeoperation) | string | No | No | Composition operation type. Available values are as follows: **'source-over'**, **'source-atop'**, **'source-in'**, **'source-out'**, **'destination-over'**, **'destination-atop'**, **'destination-in'**, **'destination-out'**, **'lighter'**, **'copy'**, and **'xor'**.<br>Default value: **'source-over'** |
114e41f4b71Sopenharmony_ci| [shadowBlur](#shadowblur)                | number | No | No | Blur level during shadow drawing. A larger value indicates a more blurred effect. The precision is float.<br>Default value: **0.0**<br>The value cannot be a negative number. If it is set to a negative number, the default value is used instead. |
115e41f4b71Sopenharmony_ci| [shadowColor](#shadowcolor)              | string | No | No | Shadow color.<br>Default value: transparent black |
116e41f4b71Sopenharmony_ci| [shadowOffsetX](#shadowoffsetx)          | number | No | No | X-axis shadow offset relative to the original object.<br>Default value: **0**<br>Default unit: vp |
117e41f4b71Sopenharmony_ci| [shadowOffsetY](#shadowoffsety)          | number | No | No | Y-axis shadow offset relative to the original object.<br>Default value: **0**<br>Default unit: vp |
118e41f4b71Sopenharmony_ci| [imageSmoothingEnabled](#imagesmoothingenabled) | boolean | No | No | Whether to adjust the image smoothness during image drawing. The value **true** means to enable this feature, and **false** means the opposite.<br>Default value: **true** |
119e41f4b71Sopenharmony_ci| [height](#height)                        | number | Yes | No | Component height.<br>Default unit: vp |
120e41f4b71Sopenharmony_ci| [width](#width)                          | number | Yes | No | Component width.<br>Default unit: vp |
121e41f4b71Sopenharmony_ci| [imageSmoothingQuality](#imagesmoothingquality) | [ImageSmoothingQuality](#imagesmoothingquality-1) | No | No | Quality of image smoothing. This attribute works only when **imageSmoothingEnabled** is set to **true**.<br>Default value: **ImageSmoothingQuality.low** |
122e41f4b71Sopenharmony_ci| [direction](#direction)                  | [CanvasDirection](#canvasdirection) | No | No | Text direction used for drawing text.<br>Default value: **CanvasDirection.inherit** |
123e41f4b71Sopenharmony_ci| [filter](#filter)                        | string | No | No | Filter effect. Available values are as follows:<br>- **'none'**: no filter effect.<br>- **'blur'**: applies the Gaussian blur for the image.<br>- **'brightness'**: applies a linear multiplication to the image to make it look brighter or darker.<br>- **'contrast'**: adjusts the image contrast.<br>- **'grayscale'**: converts the image to a grayscale image.<br>- **'hue-rotate'**: applies hue rotation to the image.<br>- **'invert'**: inverts the input image.<br>- **'opacity'**: sets the opacity of the image.<br>- **'saturate'**: sets the saturation of the image.<br>- **'sepia'**: converts the image to dark brown.<br>Default value: **'none'** |
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_ci> **NOTE**
126e41f4b71Sopenharmony_ci>
127e41f4b71Sopenharmony_ci> The string-type value of **fillStyle**, **shadowColor**, and **strokeStyle** can be in 'rgb(255, 255, 255)', 'rgba(255, 255, 255, 1.0)', or '\#FFFFFF' format.
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ci### fillStyle
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci```ts
133e41f4b71Sopenharmony_ci// xxx.ets
134e41f4b71Sopenharmony_ci@Entry
135e41f4b71Sopenharmony_ci@Component
136e41f4b71Sopenharmony_cistruct FillStyleExample {
137e41f4b71Sopenharmony_ci  private settings: RenderingContextSettings = new RenderingContextSettings(true)
138e41f4b71Sopenharmony_ci  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ci  build() {
141e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
142e41f4b71Sopenharmony_ci      Canvas(this.context)
143e41f4b71Sopenharmony_ci        .width('100%')
144e41f4b71Sopenharmony_ci        .height('100%')
145e41f4b71Sopenharmony_ci        .backgroundColor('#ffff00')
146e41f4b71Sopenharmony_ci        .onReady(() =>{
147e41f4b71Sopenharmony_ci          this.context.fillStyle = '#0000ff'
148e41f4b71Sopenharmony_ci          this.context.fillRect(20, 20, 150, 100)
149e41f4b71Sopenharmony_ci        })
150e41f4b71Sopenharmony_ci    }
151e41f4b71Sopenharmony_ci    .width('100%')
152e41f4b71Sopenharmony_ci    .height('100%')
153e41f4b71Sopenharmony_ci  }
154e41f4b71Sopenharmony_ci}
155e41f4b71Sopenharmony_ci```
156e41f4b71Sopenharmony_ci
157e41f4b71Sopenharmony_ci![en-us_image_0000001257058395](figures/en-us_image_0000001257058395.png)
158e41f4b71Sopenharmony_ci
159e41f4b71Sopenharmony_ci
160e41f4b71Sopenharmony_ci### lineWidth
161e41f4b71Sopenharmony_ci
162e41f4b71Sopenharmony_ci```ts
163e41f4b71Sopenharmony_ci// xxx.ets
164e41f4b71Sopenharmony_ci@Entry
165e41f4b71Sopenharmony_ci@Component
166e41f4b71Sopenharmony_cistruct LineWidthExample {
167e41f4b71Sopenharmony_ci  private settings: RenderingContextSettings = new RenderingContextSettings(true)
168e41f4b71Sopenharmony_ci  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci  build() {
171e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
172e41f4b71Sopenharmony_ci      Canvas(this.context)
173e41f4b71Sopenharmony_ci        .width('100%')
174e41f4b71Sopenharmony_ci        .height('100%')
175e41f4b71Sopenharmony_ci        .backgroundColor('#ffff00')
176e41f4b71Sopenharmony_ci        .onReady(() =>{
177e41f4b71Sopenharmony_ci        this.context.lineWidth = 5
178e41f4b71Sopenharmony_ci        this.context.strokeRect(25, 25, 85, 105)
179e41f4b71Sopenharmony_ci      })
180e41f4b71Sopenharmony_ci    }
181e41f4b71Sopenharmony_ci    .width('100%')
182e41f4b71Sopenharmony_ci    .height('100%')
183e41f4b71Sopenharmony_ci  }
184e41f4b71Sopenharmony_ci}
185e41f4b71Sopenharmony_ci```
186e41f4b71Sopenharmony_ci
187e41f4b71Sopenharmony_ci![en-us_image_0000001212378408](figures/en-us_image_0000001212378408.png)
188e41f4b71Sopenharmony_ci
189e41f4b71Sopenharmony_ci
190e41f4b71Sopenharmony_ci### strokeStyle
191e41f4b71Sopenharmony_ci
192e41f4b71Sopenharmony_ci```ts
193e41f4b71Sopenharmony_ci// xxx.ets
194e41f4b71Sopenharmony_ci@Entry
195e41f4b71Sopenharmony_ci@Component
196e41f4b71Sopenharmony_cistruct StrokeStyleExample {
197e41f4b71Sopenharmony_ci  private settings: RenderingContextSettings = new RenderingContextSettings(true)
198e41f4b71Sopenharmony_ci  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
199e41f4b71Sopenharmony_ci
200e41f4b71Sopenharmony_ci  build() {
201e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
202e41f4b71Sopenharmony_ci      Canvas(this.context)
203e41f4b71Sopenharmony_ci        .width('100%')
204e41f4b71Sopenharmony_ci        .height('100%')
205e41f4b71Sopenharmony_ci        .backgroundColor('#ffff00')
206e41f4b71Sopenharmony_ci        .onReady(() =>{
207e41f4b71Sopenharmony_ci          this.context.lineWidth = 10
208e41f4b71Sopenharmony_ci          this.context.strokeStyle = '#0000ff'
209e41f4b71Sopenharmony_ci          this.context.strokeRect(25, 25, 155, 105)
210e41f4b71Sopenharmony_ci        })
211e41f4b71Sopenharmony_ci    }
212e41f4b71Sopenharmony_ci    .width('100%')
213e41f4b71Sopenharmony_ci    .height('100%')
214e41f4b71Sopenharmony_ci  }
215e41f4b71Sopenharmony_ci}
216e41f4b71Sopenharmony_ci```
217e41f4b71Sopenharmony_ci
218e41f4b71Sopenharmony_ci
219e41f4b71Sopenharmony_ci![en-us_image_0000001212218446](figures/en-us_image_0000001212218446.png)
220e41f4b71Sopenharmony_ci
221e41f4b71Sopenharmony_ci
222e41f4b71Sopenharmony_ci### lineCap
223e41f4b71Sopenharmony_ci
224e41f4b71Sopenharmony_ci```ts
225e41f4b71Sopenharmony_ci// xxx.ets
226e41f4b71Sopenharmony_ci@Entry
227e41f4b71Sopenharmony_ci@Component
228e41f4b71Sopenharmony_cistruct LineCapExample {
229e41f4b71Sopenharmony_ci  private settings: RenderingContextSettings = new RenderingContextSettings(true)
230e41f4b71Sopenharmony_ci  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
231e41f4b71Sopenharmony_ci
232e41f4b71Sopenharmony_ci  build() {
233e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
234e41f4b71Sopenharmony_ci      Canvas(this.context)
235e41f4b71Sopenharmony_ci        .width('100%')
236e41f4b71Sopenharmony_ci        .height('100%')
237e41f4b71Sopenharmony_ci        .backgroundColor('#ffff00')
238e41f4b71Sopenharmony_ci        .onReady(() =>{
239e41f4b71Sopenharmony_ci          this.context.lineWidth = 8
240e41f4b71Sopenharmony_ci          this.context.beginPath()
241e41f4b71Sopenharmony_ci          this.context.lineCap = 'round'
242e41f4b71Sopenharmony_ci          this.context.moveTo(30, 50)
243e41f4b71Sopenharmony_ci          this.context.lineTo(220, 50)
244e41f4b71Sopenharmony_ci          this.context.stroke()
245e41f4b71Sopenharmony_ci        })
246e41f4b71Sopenharmony_ci    }
247e41f4b71Sopenharmony_ci    .width('100%')
248e41f4b71Sopenharmony_ci    .height('100%')
249e41f4b71Sopenharmony_ci  }
250e41f4b71Sopenharmony_ci}
251e41f4b71Sopenharmony_ci```
252e41f4b71Sopenharmony_ci
253e41f4b71Sopenharmony_ci![en-us_image_0000001212378406](figures/en-us_image_0000001212378406.png)
254e41f4b71Sopenharmony_ci
255e41f4b71Sopenharmony_ci
256e41f4b71Sopenharmony_ci### lineJoin
257e41f4b71Sopenharmony_ci
258e41f4b71Sopenharmony_ci```ts
259e41f4b71Sopenharmony_ci// xxx.ets
260e41f4b71Sopenharmony_ci@Entry
261e41f4b71Sopenharmony_ci@Component
262e41f4b71Sopenharmony_cistruct LineJoinExample {
263e41f4b71Sopenharmony_ci  private settings: RenderingContextSettings = new RenderingContextSettings(true)
264e41f4b71Sopenharmony_ci  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
265e41f4b71Sopenharmony_ci
266e41f4b71Sopenharmony_ci  build() {
267e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
268e41f4b71Sopenharmony_ci      Canvas(this.context)
269e41f4b71Sopenharmony_ci        .width('100%')
270e41f4b71Sopenharmony_ci        .height('100%')
271e41f4b71Sopenharmony_ci        .backgroundColor('#ffff00')
272e41f4b71Sopenharmony_ci        .onReady(() =>{
273e41f4b71Sopenharmony_ci        this.context.beginPath()
274e41f4b71Sopenharmony_ci        this.context.lineWidth = 8
275e41f4b71Sopenharmony_ci        this.context.lineJoin = 'miter'
276e41f4b71Sopenharmony_ci        this.context.moveTo(30, 30)
277e41f4b71Sopenharmony_ci        this.context.lineTo(120, 60)
278e41f4b71Sopenharmony_ci        this.context.lineTo(30, 110)
279e41f4b71Sopenharmony_ci        this.context.stroke()
280e41f4b71Sopenharmony_ci      })
281e41f4b71Sopenharmony_ci    }
282e41f4b71Sopenharmony_ci    .width('100%')
283e41f4b71Sopenharmony_ci    .height('100%')
284e41f4b71Sopenharmony_ci  }
285e41f4b71Sopenharmony_ci}
286e41f4b71Sopenharmony_ci```
287e41f4b71Sopenharmony_ci
288e41f4b71Sopenharmony_ci![en-us_image_0000001212218438](figures/en-us_image_0000001212218438.png)
289e41f4b71Sopenharmony_ci
290e41f4b71Sopenharmony_ci
291e41f4b71Sopenharmony_ci### miterLimit
292e41f4b71Sopenharmony_ci
293e41f4b71Sopenharmony_ci```ts
294e41f4b71Sopenharmony_ci// xxx.ets
295e41f4b71Sopenharmony_ci@Entry
296e41f4b71Sopenharmony_ci@Component
297e41f4b71Sopenharmony_cistruct MiterLimit {
298e41f4b71Sopenharmony_ci  private settings: RenderingContextSettings = new RenderingContextSettings(true)
299e41f4b71Sopenharmony_ci  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
300e41f4b71Sopenharmony_ci  
301e41f4b71Sopenharmony_ci  build() {
302e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
303e41f4b71Sopenharmony_ci      Canvas(this.context)
304e41f4b71Sopenharmony_ci        .width('100%')
305e41f4b71Sopenharmony_ci        .height('100%')
306e41f4b71Sopenharmony_ci        .backgroundColor('#ffff00')
307e41f4b71Sopenharmony_ci        .onReady(() =>{
308e41f4b71Sopenharmony_ci          this.context.lineWidth = 8
309e41f4b71Sopenharmony_ci          this.context.lineJoin = 'miter'
310e41f4b71Sopenharmony_ci          this.context.miterLimit = 3
311e41f4b71Sopenharmony_ci          this.context.moveTo(30, 30)
312e41f4b71Sopenharmony_ci          this.context.lineTo(60, 35)
313e41f4b71Sopenharmony_ci          this.context.lineTo(30, 37)
314e41f4b71Sopenharmony_ci          this.context.stroke()
315e41f4b71Sopenharmony_ci      })
316e41f4b71Sopenharmony_ci    }
317e41f4b71Sopenharmony_ci    .width('100%')
318e41f4b71Sopenharmony_ci    .height('100%')
319e41f4b71Sopenharmony_ci  }
320e41f4b71Sopenharmony_ci}
321e41f4b71Sopenharmony_ci```
322e41f4b71Sopenharmony_ci
323e41f4b71Sopenharmony_ci![en-us_image_0000001212378398](figures/en-us_image_0000001212378398.png)
324e41f4b71Sopenharmony_ci
325e41f4b71Sopenharmony_ci
326e41f4b71Sopenharmony_ci### font
327e41f4b71Sopenharmony_ci
328e41f4b71Sopenharmony_ci```ts
329e41f4b71Sopenharmony_ci// xxx.ets
330e41f4b71Sopenharmony_ci@Entry
331e41f4b71Sopenharmony_ci@Component
332e41f4b71Sopenharmony_cistruct Fonts {
333e41f4b71Sopenharmony_ci  private settings: RenderingContextSettings = new RenderingContextSettings(true)
334e41f4b71Sopenharmony_ci  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
335e41f4b71Sopenharmony_ci
336e41f4b71Sopenharmony_ci  build() {
337e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
338e41f4b71Sopenharmony_ci      Canvas(this.context)
339e41f4b71Sopenharmony_ci        .width('100%')
340e41f4b71Sopenharmony_ci        .height('100%')
341e41f4b71Sopenharmony_ci        .backgroundColor('#ffff00')
342e41f4b71Sopenharmony_ci        .onReady(() =>{
343e41f4b71Sopenharmony_ci          this.context.font = '30px sans-serif'
344e41f4b71Sopenharmony_ci          this.context.fillText("Hello px", 20, 60)
345e41f4b71Sopenharmony_ci          this.context.font = '30vp sans-serif'
346e41f4b71Sopenharmony_ci          this.context.fillText("Hello vp", 20, 100)
347e41f4b71Sopenharmony_ci        })
348e41f4b71Sopenharmony_ci    }
349e41f4b71Sopenharmony_ci    .width('100%')
350e41f4b71Sopenharmony_ci    .height('100%')
351e41f4b71Sopenharmony_ci  }
352e41f4b71Sopenharmony_ci}
353e41f4b71Sopenharmony_ci```
354e41f4b71Sopenharmony_ci
355e41f4b71Sopenharmony_ci![en-us_image_0000001257058409](figures/en-us_image_0000001257058409.png)
356e41f4b71Sopenharmony_ci
357e41f4b71Sopenharmony_ci
358e41f4b71Sopenharmony_ci### textAlign
359e41f4b71Sopenharmony_ci
360e41f4b71Sopenharmony_ci```ts
361e41f4b71Sopenharmony_ci// xxx.ets
362e41f4b71Sopenharmony_ci@Entry
363e41f4b71Sopenharmony_ci@Component
364e41f4b71Sopenharmony_cistruct CanvasExample {
365e41f4b71Sopenharmony_ci  private settings: RenderingContextSettings = new RenderingContextSettings(true)
366e41f4b71Sopenharmony_ci  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
367e41f4b71Sopenharmony_ci  
368e41f4b71Sopenharmony_ci  build() {
369e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
370e41f4b71Sopenharmony_ci      Canvas(this.context)
371e41f4b71Sopenharmony_ci        .width('100%')
372e41f4b71Sopenharmony_ci        .height('100%')
373e41f4b71Sopenharmony_ci        .backgroundColor('#ffff00')
374e41f4b71Sopenharmony_ci        .onReady(() =>{
375e41f4b71Sopenharmony_ci        this.context.strokeStyle = '#0000ff'
376e41f4b71Sopenharmony_ci        this.context.moveTo(140, 10)
377e41f4b71Sopenharmony_ci        this.context.lineTo(140, 160)
378e41f4b71Sopenharmony_ci        this.context.stroke()
379e41f4b71Sopenharmony_ci        this.context.font = '18px sans-serif'
380e41f4b71Sopenharmony_ci        this.context.textAlign = 'start'
381e41f4b71Sopenharmony_ci        this.context.fillText('textAlign=start', 140, 60)
382e41f4b71Sopenharmony_ci        this.context.textAlign = 'end'
383e41f4b71Sopenharmony_ci        this.context.fillText('textAlign=end', 140, 80)
384e41f4b71Sopenharmony_ci        this.context.textAlign = 'left'
385e41f4b71Sopenharmony_ci        this.context.fillText('textAlign=left', 140, 100)
386e41f4b71Sopenharmony_ci        this.context.textAlign = 'center'
387e41f4b71Sopenharmony_ci        this.context.fillText('textAlign=center',140, 120)
388e41f4b71Sopenharmony_ci        this.context.textAlign = 'right'
389e41f4b71Sopenharmony_ci        this.context.fillText('textAlign=right',140, 140)
390e41f4b71Sopenharmony_ci      })
391e41f4b71Sopenharmony_ci    }
392e41f4b71Sopenharmony_ci    .width('100%')
393e41f4b71Sopenharmony_ci    .height('100%')
394e41f4b71Sopenharmony_ci  }
395e41f4b71Sopenharmony_ci}
396e41f4b71Sopenharmony_ci```
397e41f4b71Sopenharmony_ci
398e41f4b71Sopenharmony_ci![en-us_image_0000001256978351](figures/en-us_image_0000001256978351.png)
399e41f4b71Sopenharmony_ci
400e41f4b71Sopenharmony_ci
401e41f4b71Sopenharmony_ci### textBaseline
402e41f4b71Sopenharmony_ci
403e41f4b71Sopenharmony_ci```ts
404e41f4b71Sopenharmony_ci// xxx.ets
405e41f4b71Sopenharmony_ci@Entry
406e41f4b71Sopenharmony_ci@Component
407e41f4b71Sopenharmony_cistruct TextBaseline {
408e41f4b71Sopenharmony_ci  private settings: RenderingContextSettings = new RenderingContextSettings(true)
409e41f4b71Sopenharmony_ci  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
410e41f4b71Sopenharmony_ci  
411e41f4b71Sopenharmony_ci  build() {
412e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
413e41f4b71Sopenharmony_ci      Canvas(this.context)
414e41f4b71Sopenharmony_ci        .width('100%')
415e41f4b71Sopenharmony_ci        .height('100%')
416e41f4b71Sopenharmony_ci        .backgroundColor('#ffff00')
417e41f4b71Sopenharmony_ci        .onReady(() =>{
418e41f4b71Sopenharmony_ci          this.context.strokeStyle = '#0000ff'
419e41f4b71Sopenharmony_ci          this.context.moveTo(0, 120)
420e41f4b71Sopenharmony_ci          this.context.lineTo(400, 120)
421e41f4b71Sopenharmony_ci          this.context.stroke()
422e41f4b71Sopenharmony_ci          this.context.font = '20px sans-serif'
423e41f4b71Sopenharmony_ci          this.context.textBaseline = 'top'
424e41f4b71Sopenharmony_ci          this.context.fillText('Top', 10, 120)
425e41f4b71Sopenharmony_ci          this.context.textBaseline = 'bottom'
426e41f4b71Sopenharmony_ci          this.context.fillText('Bottom', 55, 120)
427e41f4b71Sopenharmony_ci          this.context.textBaseline = 'middle'
428e41f4b71Sopenharmony_ci          this.context.fillText('Middle', 125, 120)
429e41f4b71Sopenharmony_ci          this.context.textBaseline = 'alphabetic'
430e41f4b71Sopenharmony_ci          this.context.fillText('Alphabetic', 195, 120)
431e41f4b71Sopenharmony_ci          this.context.textBaseline = 'hanging'
432e41f4b71Sopenharmony_ci          this.context.fillText('Hanging', 295, 120)
433e41f4b71Sopenharmony_ci      })
434e41f4b71Sopenharmony_ci    }
435e41f4b71Sopenharmony_ci    .width('100%')
436e41f4b71Sopenharmony_ci    .height('100%')
437e41f4b71Sopenharmony_ci  }
438e41f4b71Sopenharmony_ci}
439e41f4b71Sopenharmony_ci```
440e41f4b71Sopenharmony_ci
441e41f4b71Sopenharmony_ci![en-us_image_0000001212058462](figures/en-us_image_0000001212058462.png)
442e41f4b71Sopenharmony_ci
443e41f4b71Sopenharmony_ci
444e41f4b71Sopenharmony_ci### globalAlpha
445e41f4b71Sopenharmony_ci
446e41f4b71Sopenharmony_ci```ts
447e41f4b71Sopenharmony_ci// xxx.ets
448e41f4b71Sopenharmony_ci@Entry
449e41f4b71Sopenharmony_ci@Component
450e41f4b71Sopenharmony_cistruct GlobalAlpha {
451e41f4b71Sopenharmony_ci  private settings: RenderingContextSettings = new RenderingContextSettings(true)
452e41f4b71Sopenharmony_ci  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
453e41f4b71Sopenharmony_ci  
454e41f4b71Sopenharmony_ci  build() {
455e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
456e41f4b71Sopenharmony_ci      Canvas(this.context)
457e41f4b71Sopenharmony_ci        .width('100%')
458e41f4b71Sopenharmony_ci        .height('100%')
459e41f4b71Sopenharmony_ci        .backgroundColor('#ffff00')
460e41f4b71Sopenharmony_ci        .onReady(() =>{
461e41f4b71Sopenharmony_ci          this.context.fillStyle = 'rgb(0,0,255)'
462e41f4b71Sopenharmony_ci          this.context.fillRect(0, 0, 50, 50)
463e41f4b71Sopenharmony_ci          this.context.globalAlpha = 0.4
464e41f4b71Sopenharmony_ci          this.context.fillStyle = 'rgb(0,0,255)'
465e41f4b71Sopenharmony_ci          this.context.fillRect(50, 50, 50, 50)
466e41f4b71Sopenharmony_ci      })
467e41f4b71Sopenharmony_ci    }
468e41f4b71Sopenharmony_ci    .width('100%')
469e41f4b71Sopenharmony_ci    .height('100%')
470e41f4b71Sopenharmony_ci  }
471e41f4b71Sopenharmony_ci}
472e41f4b71Sopenharmony_ci```
473e41f4b71Sopenharmony_ci
474e41f4b71Sopenharmony_ci![en-us_image_0000001194192434](figures/en-us_image_0000001194192434.png)
475e41f4b71Sopenharmony_ci
476e41f4b71Sopenharmony_ci
477e41f4b71Sopenharmony_ci### lineDashOffset
478e41f4b71Sopenharmony_ci
479e41f4b71Sopenharmony_ci```ts
480e41f4b71Sopenharmony_ci// xxx.ets
481e41f4b71Sopenharmony_ci@Entry
482e41f4b71Sopenharmony_ci@Component
483e41f4b71Sopenharmony_cistruct LineDashOffset {
484e41f4b71Sopenharmony_ci  private settings: RenderingContextSettings = new RenderingContextSettings(true)
485e41f4b71Sopenharmony_ci  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
486e41f4b71Sopenharmony_ci  
487e41f4b71Sopenharmony_ci  build() {
488e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
489e41f4b71Sopenharmony_ci      Canvas(this.context)
490e41f4b71Sopenharmony_ci        .width('100%')
491e41f4b71Sopenharmony_ci        .height('100%')
492e41f4b71Sopenharmony_ci        .backgroundColor('#ffff00')
493e41f4b71Sopenharmony_ci        .onReady(() =>{
494e41f4b71Sopenharmony_ci          this.context.arc(100, 75, 50, 0, 6.28)
495e41f4b71Sopenharmony_ci          this.context.setLineDash([10,20])
496e41f4b71Sopenharmony_ci          this.context.lineDashOffset = 10.0
497e41f4b71Sopenharmony_ci          this.context.stroke()
498e41f4b71Sopenharmony_ci      })
499e41f4b71Sopenharmony_ci    }
500e41f4b71Sopenharmony_ci    .width('100%')
501e41f4b71Sopenharmony_ci    .height('100%')
502e41f4b71Sopenharmony_ci  }
503e41f4b71Sopenharmony_ci}
504e41f4b71Sopenharmony_ci```
505e41f4b71Sopenharmony_ci
506e41f4b71Sopenharmony_ci![en-us_image_0000001194352434](figures/en-us_image_0000001194352434.png)
507e41f4b71Sopenharmony_ci
508e41f4b71Sopenharmony_ci
509e41f4b71Sopenharmony_ci### globalCompositeOperation
510e41f4b71Sopenharmony_ci
511e41f4b71Sopenharmony_ci| Name              | Description                      |
512e41f4b71Sopenharmony_ci| ---------------- | ------------------------ |
513e41f4b71Sopenharmony_ci| source-over      | Displays the new drawing above the existing drawing. This attribute is used by default.  |
514e41f4b71Sopenharmony_ci| source-atop      | Displays the new drawing on the top of the existing drawing.       |
515e41f4b71Sopenharmony_ci| source-in        | Displays the new drawing inside the existing drawing.        |
516e41f4b71Sopenharmony_ci| source-out       | Displays part of the new drawing that is outside of the existing drawing.       |
517e41f4b71Sopenharmony_ci| destination-over | Displays the existing drawing above the new drawing.       |
518e41f4b71Sopenharmony_ci| destination-atop | Displays the existing drawing on the top of the new drawing.       |
519e41f4b71Sopenharmony_ci| destination-in   | Displays the existing drawing inside the new drawing.        |
520e41f4b71Sopenharmony_ci| destination-out  | Displays the existing drawing outside the new drawing.        |
521e41f4b71Sopenharmony_ci| lighter          | Displays both the new and existing drawing.         |
522e41f4b71Sopenharmony_ci| copy             | Displays the new drawing and neglects the existing drawing.       |
523e41f4b71Sopenharmony_ci| xor              | Combines the new drawing and existing drawing using the XOR operation. |
524e41f4b71Sopenharmony_ci
525e41f4b71Sopenharmony_ci```ts
526e41f4b71Sopenharmony_ci// xxx.ets
527e41f4b71Sopenharmony_ci@Entry
528e41f4b71Sopenharmony_ci@Component
529e41f4b71Sopenharmony_cistruct GlobalCompositeOperation {
530e41f4b71Sopenharmony_ci  private settings: RenderingContextSettings = new RenderingContextSettings(true)
531e41f4b71Sopenharmony_ci  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
532e41f4b71Sopenharmony_ci  
533e41f4b71Sopenharmony_ci  build() {
534e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
535e41f4b71Sopenharmony_ci      Canvas(this.context)
536e41f4b71Sopenharmony_ci        .width('100%')
537e41f4b71Sopenharmony_ci        .height('100%')
538e41f4b71Sopenharmony_ci        .backgroundColor('#ffff00')
539e41f4b71Sopenharmony_ci        .onReady(() =>{
540e41f4b71Sopenharmony_ci          this.context.fillStyle = 'rgb(255,0,0)'
541e41f4b71Sopenharmony_ci          this.context.fillRect(20, 20, 50, 50)
542e41f4b71Sopenharmony_ci          this.context.globalCompositeOperation = 'source-over'
543e41f4b71Sopenharmony_ci          this.context.fillStyle = 'rgb(0,0,255)'
544e41f4b71Sopenharmony_ci          this.context.fillRect(50, 50, 50, 50)
545e41f4b71Sopenharmony_ci          this.context.fillStyle = 'rgb(255,0,0)'
546e41f4b71Sopenharmony_ci          this.context.fillRect(120, 20, 50, 50)
547e41f4b71Sopenharmony_ci          this.context.globalCompositeOperation = 'destination-over'
548e41f4b71Sopenharmony_ci          this.context.fillStyle = 'rgb(0,0,255)'
549e41f4b71Sopenharmony_ci          this.context.fillRect(150, 50, 50, 50)
550e41f4b71Sopenharmony_ci      })
551e41f4b71Sopenharmony_ci    }
552e41f4b71Sopenharmony_ci    .width('100%')
553e41f4b71Sopenharmony_ci    .height('100%')
554e41f4b71Sopenharmony_ci  }
555e41f4b71Sopenharmony_ci}
556e41f4b71Sopenharmony_ci```
557e41f4b71Sopenharmony_ci
558e41f4b71Sopenharmony_ci![en-us_image_0000001211898480](figures/en-us_image_0000001211898480.png)
559e41f4b71Sopenharmony_ci
560e41f4b71Sopenharmony_ci
561e41f4b71Sopenharmony_ci### shadowBlur
562e41f4b71Sopenharmony_ci
563e41f4b71Sopenharmony_ci```ts
564e41f4b71Sopenharmony_ci// xxx.ets
565e41f4b71Sopenharmony_ci@Entry
566e41f4b71Sopenharmony_ci@Component
567e41f4b71Sopenharmony_cistruct ShadowBlur {
568e41f4b71Sopenharmony_ci  private settings: RenderingContextSettings = new RenderingContextSettings(true)
569e41f4b71Sopenharmony_ci  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
570e41f4b71Sopenharmony_ci  
571e41f4b71Sopenharmony_ci  build() {
572e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
573e41f4b71Sopenharmony_ci      Canvas(this.context)
574e41f4b71Sopenharmony_ci        .width('100%')
575e41f4b71Sopenharmony_ci        .height('100%')
576e41f4b71Sopenharmony_ci        .backgroundColor('#ffff00')
577e41f4b71Sopenharmony_ci        .onReady(() =>{
578e41f4b71Sopenharmony_ci          this.context.shadowBlur = 30
579e41f4b71Sopenharmony_ci          this.context.shadowColor = 'rgb(0,0,0)'
580e41f4b71Sopenharmony_ci          this.context.fillStyle = 'rgb(255,0,0)'
581e41f4b71Sopenharmony_ci          this.context.fillRect(20, 20, 100, 80)
582e41f4b71Sopenharmony_ci      })
583e41f4b71Sopenharmony_ci    }
584e41f4b71Sopenharmony_ci    .width('100%')
585e41f4b71Sopenharmony_ci    .height('100%')
586e41f4b71Sopenharmony_ci  }
587e41f4b71Sopenharmony_ci}
588e41f4b71Sopenharmony_ci```
589e41f4b71Sopenharmony_ci
590e41f4b71Sopenharmony_ci![en-us_image_0000001256978343](figures/en-us_image_0000001256978343.png)
591e41f4b71Sopenharmony_ci
592e41f4b71Sopenharmony_ci
593e41f4b71Sopenharmony_ci### shadowColor
594e41f4b71Sopenharmony_ci
595e41f4b71Sopenharmony_ci```ts
596e41f4b71Sopenharmony_ci// xxx.ets
597e41f4b71Sopenharmony_ci@Entry
598e41f4b71Sopenharmony_ci@Component
599e41f4b71Sopenharmony_cistruct ShadowColor {
600e41f4b71Sopenharmony_ci  private settings: RenderingContextSettings = new RenderingContextSettings(true)
601e41f4b71Sopenharmony_ci  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
602e41f4b71Sopenharmony_ci  
603e41f4b71Sopenharmony_ci  build() {
604e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
605e41f4b71Sopenharmony_ci      Canvas(this.context)
606e41f4b71Sopenharmony_ci        .width('100%')
607e41f4b71Sopenharmony_ci        .height('100%')
608e41f4b71Sopenharmony_ci        .backgroundColor('#ffff00')
609e41f4b71Sopenharmony_ci        .onReady(() =>{
610e41f4b71Sopenharmony_ci          this.context.shadowBlur = 30
611e41f4b71Sopenharmony_ci          this.context.shadowColor = 'rgb(0,0,255)'
612e41f4b71Sopenharmony_ci          this.context.fillStyle = 'rgb(255,0,0)'
613e41f4b71Sopenharmony_ci          this.context.fillRect(30, 30, 100, 100)
614e41f4b71Sopenharmony_ci      })
615e41f4b71Sopenharmony_ci    }
616e41f4b71Sopenharmony_ci    .width('100%')
617e41f4b71Sopenharmony_ci    .height('100%')
618e41f4b71Sopenharmony_ci  }
619e41f4b71Sopenharmony_ci}
620e41f4b71Sopenharmony_ci```
621e41f4b71Sopenharmony_ci
622e41f4b71Sopenharmony_ci![en-us_image_0000001257138353](figures/en-us_image_0000001257138353.png)
623e41f4b71Sopenharmony_ci
624e41f4b71Sopenharmony_ci
625e41f4b71Sopenharmony_ci### shadowOffsetX
626e41f4b71Sopenharmony_ci
627e41f4b71Sopenharmony_ci```ts
628e41f4b71Sopenharmony_ci// xxx.ets
629e41f4b71Sopenharmony_ci@Entry
630e41f4b71Sopenharmony_ci@Component
631e41f4b71Sopenharmony_cistruct ShadowOffsetX {
632e41f4b71Sopenharmony_ci  private settings: RenderingContextSettings = new RenderingContextSettings(true)
633e41f4b71Sopenharmony_ci  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
634e41f4b71Sopenharmony_ci  
635e41f4b71Sopenharmony_ci  build() {
636e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
637e41f4b71Sopenharmony_ci      Canvas(this.context)
638e41f4b71Sopenharmony_ci        .width('100%')
639e41f4b71Sopenharmony_ci        .height('100%')
640e41f4b71Sopenharmony_ci        .backgroundColor('#ffff00')
641e41f4b71Sopenharmony_ci        .onReady(() =>{
642e41f4b71Sopenharmony_ci          this.context.shadowBlur = 10
643e41f4b71Sopenharmony_ci          this.context.shadowOffsetX = 20
644e41f4b71Sopenharmony_ci          this.context.shadowColor = 'rgb(0,0,0)'
645e41f4b71Sopenharmony_ci          this.context.fillStyle = 'rgb(255,0,0)'
646e41f4b71Sopenharmony_ci          this.context.fillRect(20, 20, 100, 80)
647e41f4b71Sopenharmony_ci      })
648e41f4b71Sopenharmony_ci    }
649e41f4b71Sopenharmony_ci    .width('100%')
650e41f4b71Sopenharmony_ci    .height('100%')
651e41f4b71Sopenharmony_ci  }
652e41f4b71Sopenharmony_ci}
653e41f4b71Sopenharmony_ci```
654e41f4b71Sopenharmony_ci
655e41f4b71Sopenharmony_ci![en-us_image_0000001212218436](figures/en-us_image_0000001212218436.png)
656e41f4b71Sopenharmony_ci
657e41f4b71Sopenharmony_ci
658e41f4b71Sopenharmony_ci### shadowOffsetY
659e41f4b71Sopenharmony_ci
660e41f4b71Sopenharmony_ci```ts
661e41f4b71Sopenharmony_ci// xxx.ets
662e41f4b71Sopenharmony_ci@Entry
663e41f4b71Sopenharmony_ci@Component
664e41f4b71Sopenharmony_cistruct ShadowOffsetY {
665e41f4b71Sopenharmony_ci  private settings: RenderingContextSettings = new RenderingContextSettings(true)
666e41f4b71Sopenharmony_ci  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
667e41f4b71Sopenharmony_ci  build() {
668e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
669e41f4b71Sopenharmony_ci      Canvas(this.context)
670e41f4b71Sopenharmony_ci        .width('100%')
671e41f4b71Sopenharmony_ci        .height('100%')
672e41f4b71Sopenharmony_ci        .backgroundColor('#ffff00')
673e41f4b71Sopenharmony_ci        .onReady(() =>{
674e41f4b71Sopenharmony_ci          this.context.shadowBlur = 10
675e41f4b71Sopenharmony_ci          this.context.shadowOffsetY = 20
676e41f4b71Sopenharmony_ci          this.context.shadowColor = 'rgb(0,0,0)'
677e41f4b71Sopenharmony_ci          this.context.fillStyle = 'rgb(255,0,0)'
678e41f4b71Sopenharmony_ci          this.context.fillRect(30, 30, 100, 100)
679e41f4b71Sopenharmony_ci      })
680e41f4b71Sopenharmony_ci    }
681e41f4b71Sopenharmony_ci    .width('100%')
682e41f4b71Sopenharmony_ci    .height('100%')
683e41f4b71Sopenharmony_ci  }
684e41f4b71Sopenharmony_ci}
685e41f4b71Sopenharmony_ci```
686e41f4b71Sopenharmony_ci
687e41f4b71Sopenharmony_ci![en-us_image_0000001212378410](figures/en-us_image_0000001212378410.png)
688e41f4b71Sopenharmony_ci
689e41f4b71Sopenharmony_ci
690e41f4b71Sopenharmony_ci### imageSmoothingEnabled
691e41f4b71Sopenharmony_ci
692e41f4b71Sopenharmony_ci```ts
693e41f4b71Sopenharmony_ci// xxx.ets
694e41f4b71Sopenharmony_ci@Entry
695e41f4b71Sopenharmony_ci@Component
696e41f4b71Sopenharmony_cistruct ImageSmoothingEnabled {
697e41f4b71Sopenharmony_ci  private settings: RenderingContextSettings = new RenderingContextSettings(true)
698e41f4b71Sopenharmony_ci  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
699e41f4b71Sopenharmony_ci  private img:ImageBitmap = new ImageBitmap("common/images/icon.jpg")
700e41f4b71Sopenharmony_ci  
701e41f4b71Sopenharmony_ci  build() {
702e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
703e41f4b71Sopenharmony_ci      Canvas(this.context)
704e41f4b71Sopenharmony_ci        .width('100%')
705e41f4b71Sopenharmony_ci        .height('100%')
706e41f4b71Sopenharmony_ci        .backgroundColor('#ffff00')
707e41f4b71Sopenharmony_ci        .onReady(() =>{
708e41f4b71Sopenharmony_ci          this.context.imageSmoothingEnabled = false
709e41f4b71Sopenharmony_ci          this.context.drawImage( this.img,0,0,400,200)
710e41f4b71Sopenharmony_ci      })
711e41f4b71Sopenharmony_ci    }
712e41f4b71Sopenharmony_ci    .width('100%')
713e41f4b71Sopenharmony_ci    .height('100%')
714e41f4b71Sopenharmony_ci  }
715e41f4b71Sopenharmony_ci}
716e41f4b71Sopenharmony_ci```
717e41f4b71Sopenharmony_ci
718e41f4b71Sopenharmony_ci![en-us_image_0000001211898472](figures/en-us_image_0000001211898472.png)
719e41f4b71Sopenharmony_ci
720e41f4b71Sopenharmony_ci
721e41f4b71Sopenharmony_ci### height
722e41f4b71Sopenharmony_ci
723e41f4b71Sopenharmony_ci```ts
724e41f4b71Sopenharmony_ci// xxx.ets
725e41f4b71Sopenharmony_ci@Entry
726e41f4b71Sopenharmony_ci@Component
727e41f4b71Sopenharmony_cistruct HeightExample {
728e41f4b71Sopenharmony_ci  private settings: RenderingContextSettings = new RenderingContextSettings(true)
729e41f4b71Sopenharmony_ci  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
730e41f4b71Sopenharmony_ci
731e41f4b71Sopenharmony_ci  build() {
732e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
733e41f4b71Sopenharmony_ci      Canvas(this.context)
734e41f4b71Sopenharmony_ci        .width(300)
735e41f4b71Sopenharmony_ci        .height(300)
736e41f4b71Sopenharmony_ci        .backgroundColor('#ffff00')
737e41f4b71Sopenharmony_ci        .onReady(() => {
738e41f4b71Sopenharmony_ci          let h = this.context.height
739e41f4b71Sopenharmony_ci          this.context.fillRect(0, 0, 300, h/2)
740e41f4b71Sopenharmony_ci        })
741e41f4b71Sopenharmony_ci    }
742e41f4b71Sopenharmony_ci    .width('100%')
743e41f4b71Sopenharmony_ci    .height('100%')
744e41f4b71Sopenharmony_ci  }
745e41f4b71Sopenharmony_ci}
746e41f4b71Sopenharmony_ci```
747e41f4b71Sopenharmony_ci
748e41f4b71Sopenharmony_ci![en-us_image_canvas_height](figures/en-us_image_canvas_height.png)
749e41f4b71Sopenharmony_ci
750e41f4b71Sopenharmony_ci
751e41f4b71Sopenharmony_ci### width
752e41f4b71Sopenharmony_ci
753e41f4b71Sopenharmony_ci```ts
754e41f4b71Sopenharmony_ci// xxx.ets
755e41f4b71Sopenharmony_ci@Entry
756e41f4b71Sopenharmony_ci@Component
757e41f4b71Sopenharmony_cistruct WidthExample {
758e41f4b71Sopenharmony_ci  private settings: RenderingContextSettings = new RenderingContextSettings(true)
759e41f4b71Sopenharmony_ci  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
760e41f4b71Sopenharmony_ci
761e41f4b71Sopenharmony_ci  build() {
762e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
763e41f4b71Sopenharmony_ci      Canvas(this.context)
764e41f4b71Sopenharmony_ci        .width(300)
765e41f4b71Sopenharmony_ci        .height(300)
766e41f4b71Sopenharmony_ci        .backgroundColor('#ffff00')
767e41f4b71Sopenharmony_ci        .onReady(() => {
768e41f4b71Sopenharmony_ci          let w = this.context.width
769e41f4b71Sopenharmony_ci          this.context.fillRect(0, 0, w/2, 300)
770e41f4b71Sopenharmony_ci        })
771e41f4b71Sopenharmony_ci    }
772e41f4b71Sopenharmony_ci    .width('100%')
773e41f4b71Sopenharmony_ci    .height('100%')
774e41f4b71Sopenharmony_ci  }
775e41f4b71Sopenharmony_ci}
776e41f4b71Sopenharmony_ci```
777e41f4b71Sopenharmony_ci
778e41f4b71Sopenharmony_ci![en-us_image_canvas_width](figures/en-us_image_canvas_width.png)
779e41f4b71Sopenharmony_ci
780e41f4b71Sopenharmony_ci
781e41f4b71Sopenharmony_ci### imageSmoothingQuality
782e41f4b71Sopenharmony_ci
783e41f4b71Sopenharmony_ci```ts
784e41f4b71Sopenharmony_ci  // xxx.ets
785e41f4b71Sopenharmony_ci  @Entry
786e41f4b71Sopenharmony_ci  @Component
787e41f4b71Sopenharmony_ci  struct ImageSmoothingQualityDemo {
788e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true);
789e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
790e41f4b71Sopenharmony_ci    private img:ImageBitmap = new ImageBitmap("common/images/example.jpg");
791e41f4b71Sopenharmony_ci
792e41f4b71Sopenharmony_ci    build() {
793e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
794e41f4b71Sopenharmony_ci        Canvas(this.context)
795e41f4b71Sopenharmony_ci          .width('100%')
796e41f4b71Sopenharmony_ci          .height('100%')
797e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
798e41f4b71Sopenharmony_ci          .onReady(() =>{
799e41f4b71Sopenharmony_ci            let ctx = this.context
800e41f4b71Sopenharmony_ci            ctx.imageSmoothingEnabled = true
801e41f4b71Sopenharmony_ci            ctx.imageSmoothingQuality = 'high'
802e41f4b71Sopenharmony_ci            ctx.drawImage(this.img, 0, 0, 400, 200)
803e41f4b71Sopenharmony_ci          })
804e41f4b71Sopenharmony_ci      }
805e41f4b71Sopenharmony_ci      .width('100%')
806e41f4b71Sopenharmony_ci      .height('100%')
807e41f4b71Sopenharmony_ci    }
808e41f4b71Sopenharmony_ci  }
809e41f4b71Sopenharmony_ci```
810e41f4b71Sopenharmony_ci
811e41f4b71Sopenharmony_ci![ImageSmoothingQualityDemo](figures/ImageSmoothingQualityDemo.jpeg)
812e41f4b71Sopenharmony_ci
813e41f4b71Sopenharmony_ci
814e41f4b71Sopenharmony_ci### direction
815e41f4b71Sopenharmony_ci
816e41f4b71Sopenharmony_ci```ts
817e41f4b71Sopenharmony_ci  // xxx.ets
818e41f4b71Sopenharmony_ci  @Entry
819e41f4b71Sopenharmony_ci  @Component
820e41f4b71Sopenharmony_ci  struct DirectionDemo {
821e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true);
822e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
823e41f4b71Sopenharmony_ci
824e41f4b71Sopenharmony_ci    build() {
825e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
826e41f4b71Sopenharmony_ci        Canvas(this.context)
827e41f4b71Sopenharmony_ci          .width('100%')
828e41f4b71Sopenharmony_ci          .height('100%')
829e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
830e41f4b71Sopenharmony_ci          .onReady(() =>{
831e41f4b71Sopenharmony_ci            let ctx = this.context
832e41f4b71Sopenharmony_ci            ctx.font = '48px serif';
833e41f4b71Sopenharmony_ci            ctx.textAlign = 'start'
834e41f4b71Sopenharmony_ci            ctx.fillText("Hi ltr!", 200, 50);
835e41f4b71Sopenharmony_ci
836e41f4b71Sopenharmony_ci            ctx.direction = "rtl";
837e41f4b71Sopenharmony_ci            ctx.fillText("Hi rtl!", 200, 100);
838e41f4b71Sopenharmony_ci          })
839e41f4b71Sopenharmony_ci      }
840e41f4b71Sopenharmony_ci      .width('100%')
841e41f4b71Sopenharmony_ci      .height('100%')
842e41f4b71Sopenharmony_ci    }
843e41f4b71Sopenharmony_ci  }
844e41f4b71Sopenharmony_ci```
845e41f4b71Sopenharmony_ci
846e41f4b71Sopenharmony_ci![directionDemo](figures/directionDemo.jpeg)
847e41f4b71Sopenharmony_ci
848e41f4b71Sopenharmony_ci
849e41f4b71Sopenharmony_ci### filter
850e41f4b71Sopenharmony_ci
851e41f4b71Sopenharmony_ci```ts
852e41f4b71Sopenharmony_ci  // xxx.ets
853e41f4b71Sopenharmony_ci  @Entry
854e41f4b71Sopenharmony_ci  @Component
855e41f4b71Sopenharmony_ci  struct FilterDemo {
856e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true);
857e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
858e41f4b71Sopenharmony_ci    private img:ImageBitmap = new ImageBitmap("common/images/example.jpg");
859e41f4b71Sopenharmony_ci
860e41f4b71Sopenharmony_ci    build() {
861e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
862e41f4b71Sopenharmony_ci        Canvas(this.context)
863e41f4b71Sopenharmony_ci          .width('100%')
864e41f4b71Sopenharmony_ci          .height('100%')
865e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
866e41f4b71Sopenharmony_ci          .onReady(() =>{
867e41f4b71Sopenharmony_ci            let ctx = this.context
868e41f4b71Sopenharmony_ci            let img = this.img
869e41f4b71Sopenharmony_ci
870e41f4b71Sopenharmony_ci            ctx.drawImage(img, 0, 0, 100, 100);
871e41f4b71Sopenharmony_ci
872e41f4b71Sopenharmony_ci            ctx.filter = 'grayscale(50%)';
873e41f4b71Sopenharmony_ci            ctx.drawImage(img, 100, 0, 100, 100);
874e41f4b71Sopenharmony_ci
875e41f4b71Sopenharmony_ci            ctx.filter = 'sepia(60%)';
876e41f4b71Sopenharmony_ci            ctx.drawImage(img, 200, 0, 100, 100);
877e41f4b71Sopenharmony_ci
878e41f4b71Sopenharmony_ci            ctx.filter = 'saturate(30%)';
879e41f4b71Sopenharmony_ci            ctx.drawImage(img, 0, 100, 100, 100);
880e41f4b71Sopenharmony_ci
881e41f4b71Sopenharmony_ci            ctx.filter = 'hue-rotate(90deg)';
882e41f4b71Sopenharmony_ci            ctx.drawImage(img, 100, 100, 100, 100);
883e41f4b71Sopenharmony_ci
884e41f4b71Sopenharmony_ci            ctx.filter = 'invert(100%)';
885e41f4b71Sopenharmony_ci            ctx.drawImage(img, 200, 100, 100, 100);
886e41f4b71Sopenharmony_ci
887e41f4b71Sopenharmony_ci            ctx.filter = 'opacity(25%)';
888e41f4b71Sopenharmony_ci            ctx.drawImage(img, 0, 200, 100, 100);
889e41f4b71Sopenharmony_ci
890e41f4b71Sopenharmony_ci            ctx.filter = 'brightness(0.4)';
891e41f4b71Sopenharmony_ci            ctx.drawImage(img, 100, 200, 100, 100);
892e41f4b71Sopenharmony_ci
893e41f4b71Sopenharmony_ci            ctx.filter = 'contrast(200%)';
894e41f4b71Sopenharmony_ci            ctx.drawImage(img, 200, 200, 100, 100);
895e41f4b71Sopenharmony_ci
896e41f4b71Sopenharmony_ci            ctx.filter = 'blur(5px)';
897e41f4b71Sopenharmony_ci            ctx.drawImage(img, 0, 300, 100, 100);
898e41f4b71Sopenharmony_ci
899e41f4b71Sopenharmony_ci            let result = ctx.toDataURL()
900e41f4b71Sopenharmony_ci            console.info(result)
901e41f4b71Sopenharmony_ci          })
902e41f4b71Sopenharmony_ci      }
903e41f4b71Sopenharmony_ci      .width('100%')
904e41f4b71Sopenharmony_ci      .height('100%')
905e41f4b71Sopenharmony_ci    }
906e41f4b71Sopenharmony_ci  }
907e41f4b71Sopenharmony_ci```
908e41f4b71Sopenharmony_ci
909e41f4b71Sopenharmony_ci![filterDemo](figures/filterDemo.jpeg)
910e41f4b71Sopenharmony_ci
911e41f4b71Sopenharmony_ci## Methods
912e41f4b71Sopenharmony_ci
913e41f4b71Sopenharmony_ciCalls to the following methods on hidden pages will result in cache data. Therefore, avoid frequently refreshing the canvas on hidden pages.
914e41f4b71Sopenharmony_ci
915e41f4b71Sopenharmony_ci### fillRect
916e41f4b71Sopenharmony_ci
917e41f4b71Sopenharmony_cifillRect(x: number, y: number, w: number, h: number): void
918e41f4b71Sopenharmony_ci
919e41f4b71Sopenharmony_ciFills a rectangle on the canvas.
920e41f4b71Sopenharmony_ci
921e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
922e41f4b71Sopenharmony_ci
923e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
924e41f4b71Sopenharmony_ci
925e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
926e41f4b71Sopenharmony_ci
927e41f4b71Sopenharmony_ci**Parameters**
928e41f4b71Sopenharmony_ci
929e41f4b71Sopenharmony_ci| Name    | Type    | Mandatory | Description           |
930e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------- |
931e41f4b71Sopenharmony_ci| x      | number | Yes | X coordinate of the upper left corner of the rectangle.<br>Default unit: vp<br>Default value: **0** |
932e41f4b71Sopenharmony_ci| y      | number | Yes | Y coordinate of the upper left corner of the rectangle.<br>Default unit: vp<br>Default value: **0** |
933e41f4b71Sopenharmony_ci| w      | number | Yes | Width of the rectangle.<br>Default unit: vp<br>Default value: **0** |
934e41f4b71Sopenharmony_ci| h      | number | Yes | Height of the rectangle.<br>Default unit: vp<br>Default value: **0** |
935e41f4b71Sopenharmony_ci
936e41f4b71Sopenharmony_ci**Example**
937e41f4b71Sopenharmony_ci
938e41f4b71Sopenharmony_ci  ```ts
939e41f4b71Sopenharmony_ci  // xxx.ets
940e41f4b71Sopenharmony_ci  @Entry
941e41f4b71Sopenharmony_ci  @Component
942e41f4b71Sopenharmony_ci  struct FillRect {
943e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
944e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
945e41f4b71Sopenharmony_ci    
946e41f4b71Sopenharmony_ci    build() {
947e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
948e41f4b71Sopenharmony_ci        Canvas(this.context)
949e41f4b71Sopenharmony_ci          .width('100%')
950e41f4b71Sopenharmony_ci          .height('100%')
951e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
952e41f4b71Sopenharmony_ci          .onReady(() =>{
953e41f4b71Sopenharmony_ci            this.context.fillRect(30,30,100,100)
954e41f4b71Sopenharmony_ci         })
955e41f4b71Sopenharmony_ci        }
956e41f4b71Sopenharmony_ci      .width('100%')
957e41f4b71Sopenharmony_ci      .height('100%')
958e41f4b71Sopenharmony_ci    }
959e41f4b71Sopenharmony_ci  }
960e41f4b71Sopenharmony_ci  ```
961e41f4b71Sopenharmony_ci
962e41f4b71Sopenharmony_ci  ![en-us_image_0000001212218440](figures/en-us_image_0000001212218440.png)
963e41f4b71Sopenharmony_ci
964e41f4b71Sopenharmony_ci
965e41f4b71Sopenharmony_ci### strokeRect
966e41f4b71Sopenharmony_ci
967e41f4b71Sopenharmony_cistrokeRect(x: number, y: number, w: number, h: number): void
968e41f4b71Sopenharmony_ci
969e41f4b71Sopenharmony_ciDraws an outlined rectangle on the canvas.
970e41f4b71Sopenharmony_ci
971e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
972e41f4b71Sopenharmony_ci
973e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
974e41f4b71Sopenharmony_ci
975e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
976e41f4b71Sopenharmony_ci
977e41f4b71Sopenharmony_ci**Parameters**
978e41f4b71Sopenharmony_ci
979e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory  | Description          |
980e41f4b71Sopenharmony_ci| ---- | ------ | ----  | ------------ |
981e41f4b71Sopenharmony_ci| x    | number | Yes    | X coordinate of the upper left corner of the rectangle.<br>Default unit: vp<br>Default value: **0** |
982e41f4b71Sopenharmony_ci| y    | number | Yes    | Y coordinate of the upper left corner of the rectangle.<br>Default unit: vp<br>Default value: **0** |
983e41f4b71Sopenharmony_ci| w    | number | Yes    | Width of the rectangle.<br>Default unit: vp<br>Default value: **0** |
984e41f4b71Sopenharmony_ci| h    | number | Yes    | Height of the rectangle.<br>Default unit: vp<br>Default value: **0** |
985e41f4b71Sopenharmony_ci
986e41f4b71Sopenharmony_ci**Example**
987e41f4b71Sopenharmony_ci
988e41f4b71Sopenharmony_ci  ```ts
989e41f4b71Sopenharmony_ci  // xxx.ets
990e41f4b71Sopenharmony_ci  @Entry
991e41f4b71Sopenharmony_ci  @Component
992e41f4b71Sopenharmony_ci  struct StrokeRect {
993e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
994e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
995e41f4b71Sopenharmony_ci
996e41f4b71Sopenharmony_ci    build() {
997e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
998e41f4b71Sopenharmony_ci        Canvas(this.context)
999e41f4b71Sopenharmony_ci          .width('100%')
1000e41f4b71Sopenharmony_ci          .height('100%')
1001e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
1002e41f4b71Sopenharmony_ci          .onReady(() =>{
1003e41f4b71Sopenharmony_ci            this.context.strokeRect(30, 30, 200, 150)
1004e41f4b71Sopenharmony_ci        })
1005e41f4b71Sopenharmony_ci      }
1006e41f4b71Sopenharmony_ci      .width('100%')
1007e41f4b71Sopenharmony_ci      .height('100%')
1008e41f4b71Sopenharmony_ci    }
1009e41f4b71Sopenharmony_ci  }
1010e41f4b71Sopenharmony_ci  ```
1011e41f4b71Sopenharmony_ci
1012e41f4b71Sopenharmony_ci  ![en-us_image_0000001257138359](figures/en-us_image_0000001257138359.png)
1013e41f4b71Sopenharmony_ci
1014e41f4b71Sopenharmony_ci
1015e41f4b71Sopenharmony_ci### clearRect
1016e41f4b71Sopenharmony_ci
1017e41f4b71Sopenharmony_ciclearRect(x: number, y: number, w: number, h: number): void
1018e41f4b71Sopenharmony_ci
1019e41f4b71Sopenharmony_ciClears the content in a rectangle on the canvas.
1020e41f4b71Sopenharmony_ci
1021e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
1022e41f4b71Sopenharmony_ci
1023e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1024e41f4b71Sopenharmony_ci
1025e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1026e41f4b71Sopenharmony_ci
1027e41f4b71Sopenharmony_ci**Parameters**
1028e41f4b71Sopenharmony_ci
1029e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory | Description |
1030e41f4b71Sopenharmony_ci| ---- | ------ | ---- | ------------- |
1031e41f4b71Sopenharmony_ci| x    | number | Yes | X coordinate of the upper left corner of the rectangle.<br>Default unit: vp<br>Default value: **0** |
1032e41f4b71Sopenharmony_ci| y    | number | Yes | Y coordinate of the upper left corner of the rectangle.<br>Default unit: vp<br>Default value: **0** |
1033e41f4b71Sopenharmony_ci| w    | number | Yes | Width of the rectangle.<br>Default unit: vp<br>Default value: **0** |
1034e41f4b71Sopenharmony_ci| h    | number | Yes | Height of the rectangle.<br>Default unit: vp<br>Default value: **0** |
1035e41f4b71Sopenharmony_ci
1036e41f4b71Sopenharmony_ci**Example**
1037e41f4b71Sopenharmony_ci
1038e41f4b71Sopenharmony_ci  ```ts
1039e41f4b71Sopenharmony_ci  // xxx.ets
1040e41f4b71Sopenharmony_ci  @Entry
1041e41f4b71Sopenharmony_ci  @Component
1042e41f4b71Sopenharmony_ci  struct ClearRect {
1043e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
1044e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
1045e41f4b71Sopenharmony_ci
1046e41f4b71Sopenharmony_ci    build() {
1047e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
1048e41f4b71Sopenharmony_ci        Canvas(this.context)
1049e41f4b71Sopenharmony_ci          .width('100%')
1050e41f4b71Sopenharmony_ci          .height('100%')
1051e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
1052e41f4b71Sopenharmony_ci          .onReady(() =>{
1053e41f4b71Sopenharmony_ci            this.context.fillStyle = 'rgb(0,0,255)'
1054e41f4b71Sopenharmony_ci            this.context.fillRect(20,20,200,200)
1055e41f4b71Sopenharmony_ci            this.context.clearRect(30,30,150,100)
1056e41f4b71Sopenharmony_ci        })
1057e41f4b71Sopenharmony_ci      }
1058e41f4b71Sopenharmony_ci      .width('100%')
1059e41f4b71Sopenharmony_ci      .height('100%')
1060e41f4b71Sopenharmony_ci    }
1061e41f4b71Sopenharmony_ci  }
1062e41f4b71Sopenharmony_ci  ```
1063e41f4b71Sopenharmony_ci
1064e41f4b71Sopenharmony_ci  ![en-us_image_0000001211898482](figures/en-us_image_0000001211898482.png)
1065e41f4b71Sopenharmony_ci
1066e41f4b71Sopenharmony_ci
1067e41f4b71Sopenharmony_ci### fillText
1068e41f4b71Sopenharmony_ci
1069e41f4b71Sopenharmony_cifillText(text: string, x: number, y: number, maxWidth?: number): void
1070e41f4b71Sopenharmony_ci
1071e41f4b71Sopenharmony_ciDraws filled text on the canvas.
1072e41f4b71Sopenharmony_ci
1073e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
1074e41f4b71Sopenharmony_ci
1075e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1076e41f4b71Sopenharmony_ci
1077e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1078e41f4b71Sopenharmony_ci
1079e41f4b71Sopenharmony_ci**Parameters**
1080e41f4b71Sopenharmony_ci
1081e41f4b71Sopenharmony_ci| Name      | Type    | Mandatory  | Description |
1082e41f4b71Sopenharmony_ci| -------- | ------ | ---- | --------------- |
1083e41f4b71Sopenharmony_ci| text     | string | Yes   | Text to draw.<br>Default value: **''**     |
1084e41f4b71Sopenharmony_ci| x        | number | Yes   | X coordinate of the lower left corner of the text.<br>Default unit: vp<br>Default value: **0** |
1085e41f4b71Sopenharmony_ci| y        | number | Yes   | Y coordinate of the lower left corner of the text.<br>Default unit: vp<br>Default value: **0** |
1086e41f4b71Sopenharmony_ci| maxWidth | number | No   | Maximum width allowed for the text.<br>Default unit: vp |
1087e41f4b71Sopenharmony_ci
1088e41f4b71Sopenharmony_ci**Example**
1089e41f4b71Sopenharmony_ci
1090e41f4b71Sopenharmony_ci  ```ts
1091e41f4b71Sopenharmony_ci  // xxx.ets
1092e41f4b71Sopenharmony_ci  @Entry
1093e41f4b71Sopenharmony_ci  @Component
1094e41f4b71Sopenharmony_ci  struct FillText {
1095e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
1096e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
1097e41f4b71Sopenharmony_ci
1098e41f4b71Sopenharmony_ci    build() {
1099e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
1100e41f4b71Sopenharmony_ci        Canvas(this.context)
1101e41f4b71Sopenharmony_ci          .width('100%')
1102e41f4b71Sopenharmony_ci          .height('100%')
1103e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
1104e41f4b71Sopenharmony_ci          .onReady(() =>{
1105e41f4b71Sopenharmony_ci            this.context.font = '30px sans-serif'
1106e41f4b71Sopenharmony_ci            this.context.fillText("Hello World!", 20, 100)
1107e41f4b71Sopenharmony_ci        })
1108e41f4b71Sopenharmony_ci      }
1109e41f4b71Sopenharmony_ci      .width('100%')
1110e41f4b71Sopenharmony_ci      .height('100%')
1111e41f4b71Sopenharmony_ci    }
1112e41f4b71Sopenharmony_ci  }
1113e41f4b71Sopenharmony_ci  ```
1114e41f4b71Sopenharmony_ci
1115e41f4b71Sopenharmony_ci  ![en-us_image_0000001257058399](figures/en-us_image_0000001257058399.png)
1116e41f4b71Sopenharmony_ci
1117e41f4b71Sopenharmony_ci
1118e41f4b71Sopenharmony_ci### strokeText
1119e41f4b71Sopenharmony_ci
1120e41f4b71Sopenharmony_cistrokeText(text: string, x: number, y: number, maxWidth?: number): void
1121e41f4b71Sopenharmony_ci
1122e41f4b71Sopenharmony_ciDraws a text stroke on the canvas.
1123e41f4b71Sopenharmony_ci
1124e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
1125e41f4b71Sopenharmony_ci
1126e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1127e41f4b71Sopenharmony_ci
1128e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1129e41f4b71Sopenharmony_ci
1130e41f4b71Sopenharmony_ci**Parameters**
1131e41f4b71Sopenharmony_ci
1132e41f4b71Sopenharmony_ci| Name      | Type    | Mandatory | Description    |
1133e41f4b71Sopenharmony_ci| -------- | ------ | ---- | --------------- |
1134e41f4b71Sopenharmony_ci| text     | string | Yes   | Text to draw.<br>Default value: **''**     |
1135e41f4b71Sopenharmony_ci| x        | number | Yes   | X coordinate of the lower left corner of the text.<br>Default unit: vp<br>Default value: **0** |
1136e41f4b71Sopenharmony_ci| y        | number | Yes   | Y coordinate of the lower left corner of the text.<br>Default unit: vp<br>Default value: **0** |
1137e41f4b71Sopenharmony_ci| maxWidth | number | No   | Maximum width of the text.<br>Default unit: vp |
1138e41f4b71Sopenharmony_ci
1139e41f4b71Sopenharmony_ci**Example**
1140e41f4b71Sopenharmony_ci
1141e41f4b71Sopenharmony_ci  ```ts
1142e41f4b71Sopenharmony_ci  // xxx.ets
1143e41f4b71Sopenharmony_ci  @Entry
1144e41f4b71Sopenharmony_ci  @Component
1145e41f4b71Sopenharmony_ci  struct StrokeText {
1146e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
1147e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
1148e41f4b71Sopenharmony_ci
1149e41f4b71Sopenharmony_ci    build() {
1150e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
1151e41f4b71Sopenharmony_ci        Canvas(this.context)
1152e41f4b71Sopenharmony_ci          .width('100%')
1153e41f4b71Sopenharmony_ci          .height('100%')
1154e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
1155e41f4b71Sopenharmony_ci          .onReady(() =>{
1156e41f4b71Sopenharmony_ci            this.context.font = '55px sans-serif'
1157e41f4b71Sopenharmony_ci            this.context.strokeText("Hello World!", 20, 60)
1158e41f4b71Sopenharmony_ci        })
1159e41f4b71Sopenharmony_ci      }
1160e41f4b71Sopenharmony_ci      .width('100%')
1161e41f4b71Sopenharmony_ci      .height('100%')
1162e41f4b71Sopenharmony_ci    }
1163e41f4b71Sopenharmony_ci  }
1164e41f4b71Sopenharmony_ci  ```
1165e41f4b71Sopenharmony_ci
1166e41f4b71Sopenharmony_ci  ![en-us_image_0000001256978349](figures/en-us_image_0000001256978349.png)
1167e41f4b71Sopenharmony_ci
1168e41f4b71Sopenharmony_ci
1169e41f4b71Sopenharmony_ci### measureText
1170e41f4b71Sopenharmony_ci
1171e41f4b71Sopenharmony_cimeasureText(text: string): TextMetrics
1172e41f4b71Sopenharmony_ci
1173e41f4b71Sopenharmony_ciMeasures the specified text to obtain its width. This API returns a **TextMetrics** object.
1174e41f4b71Sopenharmony_ci
1175e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
1176e41f4b71Sopenharmony_ci
1177e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1178e41f4b71Sopenharmony_ci
1179e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1180e41f4b71Sopenharmony_ci
1181e41f4b71Sopenharmony_ci**Parameters**
1182e41f4b71Sopenharmony_ci
1183e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory  | Description        |
1184e41f4b71Sopenharmony_ci| ---- | ------ | ---- |---------- |
1185e41f4b71Sopenharmony_ci| text | string | Yes | Text to be measured.<br>Default value: **''** |
1186e41f4b71Sopenharmony_ci
1187e41f4b71Sopenharmony_ci**Return value**
1188e41f4b71Sopenharmony_ci
1189e41f4b71Sopenharmony_ci| Type         | Description                                      |
1190e41f4b71Sopenharmony_ci| ----------- | ---------------------------------------- |
1191e41f4b71Sopenharmony_ci| [TextMetrics](#textmetrics) | **TextMetrics** object. |
1192e41f4b71Sopenharmony_ci
1193e41f4b71Sopenharmony_ci**Example**
1194e41f4b71Sopenharmony_ci
1195e41f4b71Sopenharmony_ci  ```ts
1196e41f4b71Sopenharmony_ci  // xxx.ets
1197e41f4b71Sopenharmony_ci  @Entry
1198e41f4b71Sopenharmony_ci  @Component
1199e41f4b71Sopenharmony_ci  struct MeasureText {
1200e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
1201e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
1202e41f4b71Sopenharmony_ci
1203e41f4b71Sopenharmony_ci    build() {
1204e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
1205e41f4b71Sopenharmony_ci        Canvas(this.context)
1206e41f4b71Sopenharmony_ci          .width('100%')
1207e41f4b71Sopenharmony_ci          .height('100%')
1208e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
1209e41f4b71Sopenharmony_ci          .onReady(() =>{
1210e41f4b71Sopenharmony_ci            this.context.font = '50px sans-serif'
1211e41f4b71Sopenharmony_ci            this.context.fillText("Hello World!", 20, 100)
1212e41f4b71Sopenharmony_ci            this.context.fillText("width:" + this.context.measureText("Hello World!").width, 20, 200)
1213e41f4b71Sopenharmony_ci        })
1214e41f4b71Sopenharmony_ci      }
1215e41f4b71Sopenharmony_ci      .width('100%')
1216e41f4b71Sopenharmony_ci      .height('100%')
1217e41f4b71Sopenharmony_ci    }
1218e41f4b71Sopenharmony_ci  }
1219e41f4b71Sopenharmony_ci  ```
1220e41f4b71Sopenharmony_ci
1221e41f4b71Sopenharmony_ci  ![en-us_image_0000001257138343](figures/en-us_image_0000001257138343.png)
1222e41f4b71Sopenharmony_ci
1223e41f4b71Sopenharmony_ci
1224e41f4b71Sopenharmony_ci### stroke
1225e41f4b71Sopenharmony_ci
1226e41f4b71Sopenharmony_cistroke(path?: Path2D): void
1227e41f4b71Sopenharmony_ci
1228e41f4b71Sopenharmony_ciStrokes a path.
1229e41f4b71Sopenharmony_ci
1230e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
1231e41f4b71Sopenharmony_ci
1232e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1233e41f4b71Sopenharmony_ci
1234e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1235e41f4b71Sopenharmony_ci
1236e41f4b71Sopenharmony_ci**Parameters**
1237e41f4b71Sopenharmony_ci
1238e41f4b71Sopenharmony_ci| Name  | Type     | Mandatory  | Description    |
1239e41f4b71Sopenharmony_ci| ---- | ---------------------------------------- | ---- | ------------ |
1240e41f4b71Sopenharmony_ci| path | [Path2D](ts-components-canvas-path2d.md) | No | A **Path2D** path to draw.<br>Default value: **null** |
1241e41f4b71Sopenharmony_ci
1242e41f4b71Sopenharmony_ci**Example**
1243e41f4b71Sopenharmony_ci
1244e41f4b71Sopenharmony_ci  ```ts
1245e41f4b71Sopenharmony_ci  // xxx.ets
1246e41f4b71Sopenharmony_ci  @Entry
1247e41f4b71Sopenharmony_ci  @Component
1248e41f4b71Sopenharmony_ci  struct Stroke {
1249e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
1250e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
1251e41f4b71Sopenharmony_ci
1252e41f4b71Sopenharmony_ci    build() {
1253e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
1254e41f4b71Sopenharmony_ci        Canvas(this.context)
1255e41f4b71Sopenharmony_ci          .width('100%')
1256e41f4b71Sopenharmony_ci          .height('100%')
1257e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
1258e41f4b71Sopenharmony_ci          .onReady(() =>{
1259e41f4b71Sopenharmony_ci            this.context.moveTo(25, 25)
1260e41f4b71Sopenharmony_ci            this.context.lineTo(25, 105)
1261e41f4b71Sopenharmony_ci            this.context.lineTo(75, 105)
1262e41f4b71Sopenharmony_ci            this.context.lineTo(75, 25)
1263e41f4b71Sopenharmony_ci            this.context.strokeStyle = 'rgb(0,0,255)'
1264e41f4b71Sopenharmony_ci            this.context.stroke()
1265e41f4b71Sopenharmony_ci          })
1266e41f4b71Sopenharmony_ci      }
1267e41f4b71Sopenharmony_ci      .width('100%')
1268e41f4b71Sopenharmony_ci      .height('100%')
1269e41f4b71Sopenharmony_ci    }
1270e41f4b71Sopenharmony_ci  }
1271e41f4b71Sopenharmony_ci  ```
1272e41f4b71Sopenharmony_ci
1273e41f4b71Sopenharmony_ci  ![en-us_image_0000001238832389](figures/en-us_image_0000001238832389.png)
1274e41f4b71Sopenharmony_ci
1275e41f4b71Sopenharmony_ci
1276e41f4b71Sopenharmony_ci### beginPath
1277e41f4b71Sopenharmony_ci
1278e41f4b71Sopenharmony_cibeginPath(): void
1279e41f4b71Sopenharmony_ci
1280e41f4b71Sopenharmony_ciCreates a drawing path.
1281e41f4b71Sopenharmony_ci
1282e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
1283e41f4b71Sopenharmony_ci
1284e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1285e41f4b71Sopenharmony_ci
1286e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1287e41f4b71Sopenharmony_ci
1288e41f4b71Sopenharmony_ci**Example**
1289e41f4b71Sopenharmony_ci
1290e41f4b71Sopenharmony_ci  ```ts
1291e41f4b71Sopenharmony_ci  // xxx.ets
1292e41f4b71Sopenharmony_ci  @Entry
1293e41f4b71Sopenharmony_ci  @Component
1294e41f4b71Sopenharmony_ci  struct BeginPath {
1295e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
1296e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
1297e41f4b71Sopenharmony_ci
1298e41f4b71Sopenharmony_ci    build() {
1299e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
1300e41f4b71Sopenharmony_ci        Canvas(this.context)
1301e41f4b71Sopenharmony_ci          .width('100%')
1302e41f4b71Sopenharmony_ci          .height('100%')
1303e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
1304e41f4b71Sopenharmony_ci          .onReady(() =>{
1305e41f4b71Sopenharmony_ci            this.context.beginPath()
1306e41f4b71Sopenharmony_ci            this.context.lineWidth = 6
1307e41f4b71Sopenharmony_ci            this.context.strokeStyle = '#0000ff'
1308e41f4b71Sopenharmony_ci            this.context.moveTo(15, 80)
1309e41f4b71Sopenharmony_ci            this.context.lineTo(280, 160)
1310e41f4b71Sopenharmony_ci            this.context.stroke()
1311e41f4b71Sopenharmony_ci          })
1312e41f4b71Sopenharmony_ci      }
1313e41f4b71Sopenharmony_ci      .width('100%')
1314e41f4b71Sopenharmony_ci      .height('100%')
1315e41f4b71Sopenharmony_ci    }
1316e41f4b71Sopenharmony_ci  }
1317e41f4b71Sopenharmony_ci  ```
1318e41f4b71Sopenharmony_ci
1319e41f4b71Sopenharmony_ci  ![en-us_image_0000001238712417](figures/en-us_image_0000001212058478.png)
1320e41f4b71Sopenharmony_ci
1321e41f4b71Sopenharmony_ci
1322e41f4b71Sopenharmony_ci### moveTo
1323e41f4b71Sopenharmony_ci
1324e41f4b71Sopenharmony_cimoveTo(x: number, y: number): void
1325e41f4b71Sopenharmony_ci
1326e41f4b71Sopenharmony_ciMoves a drawing path to a target position on the canvas.
1327e41f4b71Sopenharmony_ci
1328e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
1329e41f4b71Sopenharmony_ci
1330e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1331e41f4b71Sopenharmony_ci
1332e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1333e41f4b71Sopenharmony_ci
1334e41f4b71Sopenharmony_ci**Parameters**
1335e41f4b71Sopenharmony_ci
1336e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory  | Description       |
1337e41f4b71Sopenharmony_ci| ---- | ------ | ---- | --------- |
1338e41f4b71Sopenharmony_ci| x    | number | Yes   | X coordinate of the target position.<br>Default unit: vp<br>Default value: **0** |
1339e41f4b71Sopenharmony_ci| y    | number | Yes   | Y coordinate of the target position.<br>Default unit: vp<br>Default value: **0** |
1340e41f4b71Sopenharmony_ci
1341e41f4b71Sopenharmony_ci**Example**
1342e41f4b71Sopenharmony_ci
1343e41f4b71Sopenharmony_ci  ```ts
1344e41f4b71Sopenharmony_ci  // xxx.ets
1345e41f4b71Sopenharmony_ci  @Entry
1346e41f4b71Sopenharmony_ci  @Component
1347e41f4b71Sopenharmony_ci  struct MoveTo {
1348e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
1349e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
1350e41f4b71Sopenharmony_ci
1351e41f4b71Sopenharmony_ci    build() {
1352e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
1353e41f4b71Sopenharmony_ci        Canvas(this.context)
1354e41f4b71Sopenharmony_ci          .width('100%')
1355e41f4b71Sopenharmony_ci          .height('100%')
1356e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
1357e41f4b71Sopenharmony_ci          .onReady(() =>{
1358e41f4b71Sopenharmony_ci            this.context.beginPath()
1359e41f4b71Sopenharmony_ci            this.context.moveTo(10, 10)
1360e41f4b71Sopenharmony_ci            this.context.lineTo(280, 160)
1361e41f4b71Sopenharmony_ci            this.context.stroke()
1362e41f4b71Sopenharmony_ci          })
1363e41f4b71Sopenharmony_ci      }
1364e41f4b71Sopenharmony_ci      .width('100%')
1365e41f4b71Sopenharmony_ci      .height('100%')
1366e41f4b71Sopenharmony_ci    }
1367e41f4b71Sopenharmony_ci  }
1368e41f4b71Sopenharmony_ci  ```
1369e41f4b71Sopenharmony_ci
1370e41f4b71Sopenharmony_ci  ![en-us_image_0000001194192438](figures/en-us_image_0000001256858391.png)
1371e41f4b71Sopenharmony_ci
1372e41f4b71Sopenharmony_ci
1373e41f4b71Sopenharmony_ci### lineTo
1374e41f4b71Sopenharmony_ci
1375e41f4b71Sopenharmony_cilineTo(x: number, y: number): void
1376e41f4b71Sopenharmony_ci
1377e41f4b71Sopenharmony_ciConnects the current point to a target position using a straight line.
1378e41f4b71Sopenharmony_ci
1379e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
1380e41f4b71Sopenharmony_ci
1381e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1382e41f4b71Sopenharmony_ci
1383e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1384e41f4b71Sopenharmony_ci
1385e41f4b71Sopenharmony_ci**Parameters**
1386e41f4b71Sopenharmony_ci
1387e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory  | Description       |
1388e41f4b71Sopenharmony_ci| ---- | ------ | ---- | --------- |
1389e41f4b71Sopenharmony_ci| x    | number | Yes   | X coordinate of the target position.<br>Default unit: vp<br>Default value: **0** |
1390e41f4b71Sopenharmony_ci| y    | number | Yes   | Y coordinate of the target position.<br>Default unit: vp<br>Default value: **0** |
1391e41f4b71Sopenharmony_ci
1392e41f4b71Sopenharmony_ci**Example**
1393e41f4b71Sopenharmony_ci
1394e41f4b71Sopenharmony_ci  ```ts
1395e41f4b71Sopenharmony_ci  // xxx.ets
1396e41f4b71Sopenharmony_ci  @Entry
1397e41f4b71Sopenharmony_ci  @Component
1398e41f4b71Sopenharmony_ci  struct LineTo {
1399e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
1400e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
1401e41f4b71Sopenharmony_ci
1402e41f4b71Sopenharmony_ci    build() {
1403e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
1404e41f4b71Sopenharmony_ci        Canvas(this.context)
1405e41f4b71Sopenharmony_ci          .width('100%')
1406e41f4b71Sopenharmony_ci          .height('100%')
1407e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
1408e41f4b71Sopenharmony_ci          .onReady(() =>{
1409e41f4b71Sopenharmony_ci            this.context.beginPath()
1410e41f4b71Sopenharmony_ci            this.context.moveTo(10, 10)
1411e41f4b71Sopenharmony_ci            this.context.lineTo(280, 160)
1412e41f4b71Sopenharmony_ci            this.context.stroke()
1413e41f4b71Sopenharmony_ci          })
1414e41f4b71Sopenharmony_ci      }
1415e41f4b71Sopenharmony_ci      .width('100%')
1416e41f4b71Sopenharmony_ci      .height('100%')
1417e41f4b71Sopenharmony_ci    }
1418e41f4b71Sopenharmony_ci  }
1419e41f4b71Sopenharmony_ci  ```
1420e41f4b71Sopenharmony_ci
1421e41f4b71Sopenharmony_ci  ![en-us_image_0000001194352438](figures/en-us_image_0000001212378414.png)
1422e41f4b71Sopenharmony_ci
1423e41f4b71Sopenharmony_ci
1424e41f4b71Sopenharmony_ci### closePath
1425e41f4b71Sopenharmony_ci
1426e41f4b71Sopenharmony_ciclosePath(): void
1427e41f4b71Sopenharmony_ci
1428e41f4b71Sopenharmony_ciDraws a closed path.
1429e41f4b71Sopenharmony_ci
1430e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
1431e41f4b71Sopenharmony_ci
1432e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1433e41f4b71Sopenharmony_ci
1434e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1435e41f4b71Sopenharmony_ci
1436e41f4b71Sopenharmony_ci**Example**
1437e41f4b71Sopenharmony_ci
1438e41f4b71Sopenharmony_ci  ```ts
1439e41f4b71Sopenharmony_ci  // xxx.ets
1440e41f4b71Sopenharmony_ci  @Entry
1441e41f4b71Sopenharmony_ci  @Component
1442e41f4b71Sopenharmony_ci  struct ClosePath {
1443e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
1444e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
1445e41f4b71Sopenharmony_ci
1446e41f4b71Sopenharmony_ci    build() {
1447e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
1448e41f4b71Sopenharmony_ci        Canvas(this.context)
1449e41f4b71Sopenharmony_ci          .width('100%')
1450e41f4b71Sopenharmony_ci          .height('100%')
1451e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
1452e41f4b71Sopenharmony_ci          .onReady(() =>{
1453e41f4b71Sopenharmony_ci              this.context.beginPath()
1454e41f4b71Sopenharmony_ci              this.context.moveTo(30, 30)
1455e41f4b71Sopenharmony_ci              this.context.lineTo(110, 30)
1456e41f4b71Sopenharmony_ci              this.context.lineTo(70, 90)
1457e41f4b71Sopenharmony_ci              this.context.closePath()
1458e41f4b71Sopenharmony_ci              this.context.stroke()
1459e41f4b71Sopenharmony_ci          })
1460e41f4b71Sopenharmony_ci      }
1461e41f4b71Sopenharmony_ci      .width('100%')
1462e41f4b71Sopenharmony_ci      .height('100%')
1463e41f4b71Sopenharmony_ci    }
1464e41f4b71Sopenharmony_ci  }
1465e41f4b71Sopenharmony_ci  ```
1466e41f4b71Sopenharmony_ci
1467e41f4b71Sopenharmony_ci  ![en-us_image_0000001238952379](figures/en-us_image_0000001256978347.png)
1468e41f4b71Sopenharmony_ci
1469e41f4b71Sopenharmony_ci
1470e41f4b71Sopenharmony_ci### createPattern
1471e41f4b71Sopenharmony_ci
1472e41f4b71Sopenharmony_cicreatePattern(image: ImageBitmap, repetition: string | null): CanvasPattern | null
1473e41f4b71Sopenharmony_ci
1474e41f4b71Sopenharmony_ciCreates a pattern for image filling based on a specified source image and repetition mode.
1475e41f4b71Sopenharmony_ci
1476e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
1477e41f4b71Sopenharmony_ci
1478e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1479e41f4b71Sopenharmony_ci
1480e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1481e41f4b71Sopenharmony_ci
1482e41f4b71Sopenharmony_ci**Parameters**
1483e41f4b71Sopenharmony_ci
1484e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description |
1485e41f4b71Sopenharmony_ci| ---------- | ---------- | ---- | ---------------------------------------- |
1486e41f4b71Sopenharmony_ci| image  | [ImageBitmap](ts-components-canvas-imagebitmap.md) | Yes | Source image. For details, see **ImageBitmap**. |
1487e41f4b71Sopenharmony_ci| repetition | string \| null  | Yes | Repetition mode.<br>**'repeat'**: The image is repeated along both the x-axis and y-axis.<br>**'repeat-x'**: The image is repeated along the x-axis.<br>**'repeat-y'**: The image is repeated along the y-axis.<br>**'no-repeat'**: The image is not repeated.<br>**'clamp'**: Coordinates outside the original bounds are clamped to the edge of the image.<br>**'mirror'**: The image is mirrored with each repetition along the x-axis and y-axis.<br>Default value: **null**|
1488e41f4b71Sopenharmony_ci
1489e41f4b71Sopenharmony_ci**Return value**
1490e41f4b71Sopenharmony_ci
1491e41f4b71Sopenharmony_ci| Type                                      | Description                     |
1492e41f4b71Sopenharmony_ci| ---------------------------------------- | ----------------------- |
1493e41f4b71Sopenharmony_ci| [CanvasPattern](ts-components-canvas-canvaspattern.md#canvaspattern) \| null | Created pattern for image filling based on a specified source image and repetition mode. |
1494e41f4b71Sopenharmony_ci
1495e41f4b71Sopenharmony_ci**Example**
1496e41f4b71Sopenharmony_ci
1497e41f4b71Sopenharmony_ci  ```ts
1498e41f4b71Sopenharmony_ci  // xxx.ets
1499e41f4b71Sopenharmony_ci  @Entry
1500e41f4b71Sopenharmony_ci  @Component
1501e41f4b71Sopenharmony_ci  struct CreatePattern {
1502e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
1503e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
1504e41f4b71Sopenharmony_ci    private img:ImageBitmap = new ImageBitmap("common/images/icon.jpg")
1505e41f4b71Sopenharmony_ci
1506e41f4b71Sopenharmony_ci    build() {
1507e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
1508e41f4b71Sopenharmony_ci        Canvas(this.context)
1509e41f4b71Sopenharmony_ci          .width('100%')
1510e41f4b71Sopenharmony_ci          .height('100%')
1511e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
1512e41f4b71Sopenharmony_ci          .onReady(() =>{
1513e41f4b71Sopenharmony_ci            let pattern = this.context.createPattern(this.img, 'repeat')
1514e41f4b71Sopenharmony_ci            if (pattern) {
1515e41f4b71Sopenharmony_ci              this.context.fillStyle = pattern
1516e41f4b71Sopenharmony_ci            }
1517e41f4b71Sopenharmony_ci            this.context.fillRect(0, 0, 200, 200)
1518e41f4b71Sopenharmony_ci          })
1519e41f4b71Sopenharmony_ci      }
1520e41f4b71Sopenharmony_ci      .width('100%')
1521e41f4b71Sopenharmony_ci      .height('100%')
1522e41f4b71Sopenharmony_ci    }
1523e41f4b71Sopenharmony_ci  }
1524e41f4b71Sopenharmony_ci  ```
1525e41f4b71Sopenharmony_ci
1526e41f4b71Sopenharmony_ci  ![en-us_image_0000001211898490](figures/en-us_image_0000001211898490.png)
1527e41f4b71Sopenharmony_ci
1528e41f4b71Sopenharmony_ci
1529e41f4b71Sopenharmony_ci### bezierCurveTo
1530e41f4b71Sopenharmony_ci
1531e41f4b71Sopenharmony_cibezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void
1532e41f4b71Sopenharmony_ci
1533e41f4b71Sopenharmony_ciDraws a cubic Bezier curve on the canvas.
1534e41f4b71Sopenharmony_ci
1535e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
1536e41f4b71Sopenharmony_ci
1537e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1538e41f4b71Sopenharmony_ci
1539e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1540e41f4b71Sopenharmony_ci
1541e41f4b71Sopenharmony_ci**Parameters**
1542e41f4b71Sopenharmony_ci
1543e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory  | Description |
1544e41f4b71Sopenharmony_ci| ---- | ------ | ---- | -------------- |
1545e41f4b71Sopenharmony_ci| cp1x | number | Yes | X coordinate of the first parameter of the bezier curve.<br>Default unit: vp<br>Default value: **0** |
1546e41f4b71Sopenharmony_ci| cp1y | number | Yes | Y coordinate of the first parameter of the bezier curve.<br>Default unit: vp<br>Default value: **0** |
1547e41f4b71Sopenharmony_ci| cp2x | number | Yes | X coordinate of the second parameter of the bezier curve.<br>Default unit: vp<br>Default value: **0** |
1548e41f4b71Sopenharmony_ci| cp2y | number | Yes | Y coordinate of the second parameter of the bezier curve.<br>Default unit: vp<br>Default value: **0** |
1549e41f4b71Sopenharmony_ci| x    | number | Yes | X coordinate of the end point on the bezier curve.<br>Default unit: vp<br>Default value: **0** |
1550e41f4b71Sopenharmony_ci| y    | number | Yes | Y coordinate of the end point on the bezier curve.<br>Default unit: vp<br>Default value: **0** |
1551e41f4b71Sopenharmony_ci
1552e41f4b71Sopenharmony_ci**Example**
1553e41f4b71Sopenharmony_ci
1554e41f4b71Sopenharmony_ci  ```ts
1555e41f4b71Sopenharmony_ci  // xxx.ets
1556e41f4b71Sopenharmony_ci  @Entry
1557e41f4b71Sopenharmony_ci  @Component
1558e41f4b71Sopenharmony_ci  struct BezierCurveTo {
1559e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
1560e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
1561e41f4b71Sopenharmony_ci
1562e41f4b71Sopenharmony_ci    build() {
1563e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
1564e41f4b71Sopenharmony_ci        Canvas(this.context)
1565e41f4b71Sopenharmony_ci          .width('100%')
1566e41f4b71Sopenharmony_ci          .height('100%')
1567e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
1568e41f4b71Sopenharmony_ci          .onReady(() =>{
1569e41f4b71Sopenharmony_ci            this.context.beginPath()
1570e41f4b71Sopenharmony_ci            this.context.moveTo(10, 10)
1571e41f4b71Sopenharmony_ci            this.context.bezierCurveTo(20, 100, 200, 100, 200, 20)
1572e41f4b71Sopenharmony_ci            this.context.stroke()
1573e41f4b71Sopenharmony_ci          })
1574e41f4b71Sopenharmony_ci      }
1575e41f4b71Sopenharmony_ci      .width('100%')
1576e41f4b71Sopenharmony_ci      .height('100%')
1577e41f4b71Sopenharmony_ci    }
1578e41f4b71Sopenharmony_ci  }
1579e41f4b71Sopenharmony_ci  ```
1580e41f4b71Sopenharmony_ci
1581e41f4b71Sopenharmony_ci  ![en-us_image_0000001257138349](figures/en-us_image_0000001257138349.png)
1582e41f4b71Sopenharmony_ci
1583e41f4b71Sopenharmony_ci
1584e41f4b71Sopenharmony_ci### quadraticCurveTo
1585e41f4b71Sopenharmony_ci
1586e41f4b71Sopenharmony_ciquadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void
1587e41f4b71Sopenharmony_ci
1588e41f4b71Sopenharmony_ciDraws a quadratic curve on the canvas.
1589e41f4b71Sopenharmony_ci
1590e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
1591e41f4b71Sopenharmony_ci
1592e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1593e41f4b71Sopenharmony_ci
1594e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1595e41f4b71Sopenharmony_ci
1596e41f4b71Sopenharmony_ci**Parameters**
1597e41f4b71Sopenharmony_ci
1598e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory  | Description         |
1599e41f4b71Sopenharmony_ci| ---- | ------ | ---- | ----------- |
1600e41f4b71Sopenharmony_ci| cpx  | number | Yes   | X coordinate of the bezier curve parameter.<br>Default unit: vp<br>Default value: **0** |
1601e41f4b71Sopenharmony_ci| cpy  | number | Yes   | Y coordinate of the bezier curve parameter.<br>Default unit: vp<br>Default value: **0** |
1602e41f4b71Sopenharmony_ci| x    | number | Yes   | X coordinate of the end point on the bezier curve.<br>Default unit: vp<br>Default value: **0** |
1603e41f4b71Sopenharmony_ci| y    | number | Yes   | Y coordinate of the end point on the bezier curve.<br>Default unit: vp<br>Default value: **0** |
1604e41f4b71Sopenharmony_ci
1605e41f4b71Sopenharmony_ci**Example**
1606e41f4b71Sopenharmony_ci
1607e41f4b71Sopenharmony_ci  ```ts
1608e41f4b71Sopenharmony_ci  // xxx.ets
1609e41f4b71Sopenharmony_ci  @Entry
1610e41f4b71Sopenharmony_ci  @Component
1611e41f4b71Sopenharmony_ci  struct QuadraticCurveTo {
1612e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
1613e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
1614e41f4b71Sopenharmony_ci
1615e41f4b71Sopenharmony_ci    build() {
1616e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
1617e41f4b71Sopenharmony_ci        Canvas(this.context)
1618e41f4b71Sopenharmony_ci          .width('100%')
1619e41f4b71Sopenharmony_ci          .height('100%')
1620e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
1621e41f4b71Sopenharmony_ci          .onReady(() =>{
1622e41f4b71Sopenharmony_ci            this.context.beginPath()
1623e41f4b71Sopenharmony_ci            this.context.moveTo(20, 20)
1624e41f4b71Sopenharmony_ci            this.context.quadraticCurveTo(100, 100, 200, 20)
1625e41f4b71Sopenharmony_ci            this.context.stroke()
1626e41f4b71Sopenharmony_ci        })
1627e41f4b71Sopenharmony_ci      }
1628e41f4b71Sopenharmony_ci      .width('100%')
1629e41f4b71Sopenharmony_ci      .height('100%')
1630e41f4b71Sopenharmony_ci    }
1631e41f4b71Sopenharmony_ci  }
1632e41f4b71Sopenharmony_ci  ```
1633e41f4b71Sopenharmony_ci
1634e41f4b71Sopenharmony_ci  ![en-us_image_0000001257058397](figures/en-us_image_0000001257058397.png)
1635e41f4b71Sopenharmony_ci
1636e41f4b71Sopenharmony_ci
1637e41f4b71Sopenharmony_ci### arc
1638e41f4b71Sopenharmony_ci
1639e41f4b71Sopenharmony_ciarc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean): void
1640e41f4b71Sopenharmony_ci
1641e41f4b71Sopenharmony_ciDraws an arc on the canvas.
1642e41f4b71Sopenharmony_ci
1643e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
1644e41f4b71Sopenharmony_ci
1645e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1646e41f4b71Sopenharmony_ci
1647e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1648e41f4b71Sopenharmony_ci
1649e41f4b71Sopenharmony_ci**Parameters**
1650e41f4b71Sopenharmony_ci
1651e41f4b71Sopenharmony_ci| Name      | Type     | Mandatory  | Description        |
1652e41f4b71Sopenharmony_ci| ---------------- | ------- | ---- | ---------- |
1653e41f4b71Sopenharmony_ci| x                | number  | Yes | X coordinate of the center point of the arc.<br>Default unit: vp<br>Default value: **0** |
1654e41f4b71Sopenharmony_ci| y                | number  | Yes | Y coordinate of the center point of the arc.<br>Default unit: vp<br>Default value: **0** |
1655e41f4b71Sopenharmony_ci| radius           | number  | Yes | Radius of the arc.<br>Default unit: vp<br>Default value: **0** |
1656e41f4b71Sopenharmony_ci| startAngle       | number  | Yes | Start radian of the arc.<br>Default value: **0**  |
1657e41f4b71Sopenharmony_ci| endAngle         | number  | Yes | End radian of the arc.<br>Default value: **0**  |
1658e41f4b71Sopenharmony_ci| counterclockwise | boolean | No | Whether to draw the arc counterclockwise.<br>Default value: **false** |
1659e41f4b71Sopenharmony_ci
1660e41f4b71Sopenharmony_ci**Example**
1661e41f4b71Sopenharmony_ci
1662e41f4b71Sopenharmony_ci  ```ts
1663e41f4b71Sopenharmony_ci  // xxx.ets
1664e41f4b71Sopenharmony_ci  @Entry
1665e41f4b71Sopenharmony_ci  @Component
1666e41f4b71Sopenharmony_ci  struct Arc {
1667e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
1668e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
1669e41f4b71Sopenharmony_ci
1670e41f4b71Sopenharmony_ci    build() {
1671e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
1672e41f4b71Sopenharmony_ci        Canvas(this.context)
1673e41f4b71Sopenharmony_ci          .width('100%')
1674e41f4b71Sopenharmony_ci          .height('100%')
1675e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
1676e41f4b71Sopenharmony_ci          .onReady(() =>{
1677e41f4b71Sopenharmony_ci            this.context.beginPath()
1678e41f4b71Sopenharmony_ci            this.context.arc(100, 75, 50, 0, 6.28)
1679e41f4b71Sopenharmony_ci            this.context.stroke()
1680e41f4b71Sopenharmony_ci          })
1681e41f4b71Sopenharmony_ci      }
1682e41f4b71Sopenharmony_ci      .width('100%')
1683e41f4b71Sopenharmony_ci      .height('100%')
1684e41f4b71Sopenharmony_ci    }
1685e41f4b71Sopenharmony_ci  }
1686e41f4b71Sopenharmony_ci  ```
1687e41f4b71Sopenharmony_ci
1688e41f4b71Sopenharmony_ci  ![en-us_image_0000001212378404](figures/en-us_image_0000001212378404.png)
1689e41f4b71Sopenharmony_ci
1690e41f4b71Sopenharmony_ci
1691e41f4b71Sopenharmony_ci### arcTo
1692e41f4b71Sopenharmony_ci
1693e41f4b71Sopenharmony_ciarcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void
1694e41f4b71Sopenharmony_ci
1695e41f4b71Sopenharmony_ciDraws an arc based on the radius and points on the arc.
1696e41f4b71Sopenharmony_ci
1697e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
1698e41f4b71Sopenharmony_ci
1699e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1700e41f4b71Sopenharmony_ci
1701e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1702e41f4b71Sopenharmony_ci
1703e41f4b71Sopenharmony_ci**Parameters**
1704e41f4b71Sopenharmony_ci
1705e41f4b71Sopenharmony_ci| Name    | Type    | Mandatory  | Description         |
1706e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------- |
1707e41f4b71Sopenharmony_ci| x1     | number | Yes   | X coordinate of the first point on the arc.<br>Default unit: vp<br>Default value: **0** |
1708e41f4b71Sopenharmony_ci| y1     | number | Yes   | Y coordinate of the first point on the arc.<br>Default unit: vp<br>Default value: **0** |
1709e41f4b71Sopenharmony_ci| x2     | number | Yes   | X coordinate of the second point on the arc.<br>Default unit: vp<br>Default value: **0** |
1710e41f4b71Sopenharmony_ci| y2     | number | Yes   | Y coordinate of the second point on the arc.<br>Default unit: vp<br>Default value: **0** |
1711e41f4b71Sopenharmony_ci| radius | number | Yes   | Radius of the arc.<br>Default unit: vp<br>Default value: **0** |
1712e41f4b71Sopenharmony_ci
1713e41f4b71Sopenharmony_ci**Example**
1714e41f4b71Sopenharmony_ci
1715e41f4b71Sopenharmony_ci  ```ts
1716e41f4b71Sopenharmony_ci  // xxx.ets
1717e41f4b71Sopenharmony_ci  @Entry
1718e41f4b71Sopenharmony_ci  @Component
1719e41f4b71Sopenharmony_ci  struct ArcTo {
1720e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
1721e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
1722e41f4b71Sopenharmony_ci
1723e41f4b71Sopenharmony_ci    build() {
1724e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
1725e41f4b71Sopenharmony_ci        Canvas(this.context)
1726e41f4b71Sopenharmony_ci          .width('100%')
1727e41f4b71Sopenharmony_ci          .height('100%')
1728e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
1729e41f4b71Sopenharmony_ci          .onReady(() =>{
1730e41f4b71Sopenharmony_ci            this.context.moveTo(100, 20)
1731e41f4b71Sopenharmony_ci            this.context.arcTo(150, 20, 150, 70, 50)
1732e41f4b71Sopenharmony_ci            this.context.stroke()
1733e41f4b71Sopenharmony_ci          })
1734e41f4b71Sopenharmony_ci      }
1735e41f4b71Sopenharmony_ci      .width('100%')
1736e41f4b71Sopenharmony_ci      .height('100%')
1737e41f4b71Sopenharmony_ci    }
1738e41f4b71Sopenharmony_ci  }
1739e41f4b71Sopenharmony_ci  ```
1740e41f4b71Sopenharmony_ci
1741e41f4b71Sopenharmony_ci  ![en-us_image_0000001257058413](figures/en-us_image_0000001257058413.png)
1742e41f4b71Sopenharmony_ci
1743e41f4b71Sopenharmony_ci
1744e41f4b71Sopenharmony_ci### ellipse
1745e41f4b71Sopenharmony_ci
1746e41f4b71Sopenharmony_ciellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, counterclockwise?: boolean): void
1747e41f4b71Sopenharmony_ci
1748e41f4b71Sopenharmony_ciDraws an ellipse in the specified rectangular region on the canvas.
1749e41f4b71Sopenharmony_ci
1750e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
1751e41f4b71Sopenharmony_ci
1752e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1753e41f4b71Sopenharmony_ci
1754e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1755e41f4b71Sopenharmony_ci
1756e41f4b71Sopenharmony_ci**Parameters**
1757e41f4b71Sopenharmony_ci
1758e41f4b71Sopenharmony_ci| Name              | Type     | Mandatory  | Description                                      |
1759e41f4b71Sopenharmony_ci| ---------------- | ------- | ---- | ---------------------------------------- |
1760e41f4b71Sopenharmony_ci| x                | number  | Yes | X coordinate of the ellipse center.<br>Default unit: vp<br>Default value: **0** |
1761e41f4b71Sopenharmony_ci| y                | number  | Yes | Y coordinate of the ellipse center.<br>Default unit: vp<br>Default value: **0** |
1762e41f4b71Sopenharmony_ci| radiusX          | number  | Yes | Radius of the ellipse on the x-axis.<br>Default unit: vp<br>Default value: **0** |
1763e41f4b71Sopenharmony_ci| radiusY          | number  | Yes | Radius of the ellipse on the y-axis.<br>Default unit: vp<br>Default value: **0** |
1764e41f4b71Sopenharmony_ci| rotation         | number  | Yes | Rotation angle of the ellipse. The unit is radian.<br>Default value: **0** |
1765e41f4b71Sopenharmony_ci| startAngle       | number  | Yes | Angle of the start point for drawing the ellipse. The unit is radian.<br>Default value: **0** |
1766e41f4b71Sopenharmony_ci| endAngle         | number  | Yes | Angle of the end point for drawing the ellipse. The unit is radian.<br>Default value: **0** |
1767e41f4b71Sopenharmony_ci| counterclockwise | boolean | No | Whether to draw the ellipse in the counterclockwise direction.<br>**true**: Draw the arc counterclockwise.<br>**false**: Draw the arc clockwise.<br>Default value: **false** |
1768e41f4b71Sopenharmony_ci
1769e41f4b71Sopenharmony_ci**Example**
1770e41f4b71Sopenharmony_ci
1771e41f4b71Sopenharmony_ci  ```ts
1772e41f4b71Sopenharmony_ci  // xxx.ets
1773e41f4b71Sopenharmony_ci  @Entry
1774e41f4b71Sopenharmony_ci  @Component
1775e41f4b71Sopenharmony_ci  struct CanvasExample {
1776e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
1777e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
1778e41f4b71Sopenharmony_ci
1779e41f4b71Sopenharmony_ci    build() {
1780e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
1781e41f4b71Sopenharmony_ci        Canvas(this.context)
1782e41f4b71Sopenharmony_ci          .width('100%')
1783e41f4b71Sopenharmony_ci          .height('100%')
1784e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
1785e41f4b71Sopenharmony_ci          .onReady(() =>{
1786e41f4b71Sopenharmony_ci            this.context.beginPath()
1787e41f4b71Sopenharmony_ci            this.context.ellipse(200, 200, 50, 100, Math.PI * 0.25, Math.PI * 0.5, Math.PI * 2, false)
1788e41f4b71Sopenharmony_ci            this.context.stroke()
1789e41f4b71Sopenharmony_ci            this.context.beginPath()
1790e41f4b71Sopenharmony_ci            this.context.ellipse(200, 300, 50, 100, Math.PI * 0.25, Math.PI * 0.5, Math.PI * 2, true)
1791e41f4b71Sopenharmony_ci            this.context.stroke()
1792e41f4b71Sopenharmony_ci          })
1793e41f4b71Sopenharmony_ci      }
1794e41f4b71Sopenharmony_ci      .width('100%')
1795e41f4b71Sopenharmony_ci      .height('100%')
1796e41f4b71Sopenharmony_ci    }
1797e41f4b71Sopenharmony_ci  }
1798e41f4b71Sopenharmony_ci  ```
1799e41f4b71Sopenharmony_ci
1800e41f4b71Sopenharmony_ci  ![en-us_image_0000001194192440](figures/en-us_image_0000001194192440.jpeg)
1801e41f4b71Sopenharmony_ci
1802e41f4b71Sopenharmony_ci
1803e41f4b71Sopenharmony_ci### rect
1804e41f4b71Sopenharmony_ci
1805e41f4b71Sopenharmony_cirect(x: number, y: number, w: number, h: number): void
1806e41f4b71Sopenharmony_ci
1807e41f4b71Sopenharmony_ciCreates a rectangle on the canvas.
1808e41f4b71Sopenharmony_ci
1809e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
1810e41f4b71Sopenharmony_ci
1811e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1812e41f4b71Sopenharmony_ci
1813e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1814e41f4b71Sopenharmony_ci
1815e41f4b71Sopenharmony_ci**Parameters**
1816e41f4b71Sopenharmony_ci
1817e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory  | Description           |
1818e41f4b71Sopenharmony_ci| ---- | ------ | ---- | ------------- |
1819e41f4b71Sopenharmony_ci| x    | number | Yes   | X coordinate of the upper left corner of the rectangle.<br>Default unit: vp<br>Default value: **0** |
1820e41f4b71Sopenharmony_ci| y    | number | Yes   | Y coordinate of the upper left corner of the rectangle.<br>Default unit: vp<br>Default value: **0** |
1821e41f4b71Sopenharmony_ci| w    | number | Yes   | Width of the rectangle.<br>Default unit: vp<br>Default value: **0** |
1822e41f4b71Sopenharmony_ci| h    | number | Yes   | Height of the rectangle.<br>Default unit: vp<br>Default value: **0** |
1823e41f4b71Sopenharmony_ci
1824e41f4b71Sopenharmony_ci**Example**
1825e41f4b71Sopenharmony_ci
1826e41f4b71Sopenharmony_ci  ```ts
1827e41f4b71Sopenharmony_ci  // xxx.ets
1828e41f4b71Sopenharmony_ci  @Entry
1829e41f4b71Sopenharmony_ci  @Component
1830e41f4b71Sopenharmony_ci  struct CanvasExample {
1831e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
1832e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
1833e41f4b71Sopenharmony_ci
1834e41f4b71Sopenharmony_ci    build() {
1835e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
1836e41f4b71Sopenharmony_ci        Canvas(this.context)
1837e41f4b71Sopenharmony_ci          .width('100%')
1838e41f4b71Sopenharmony_ci          .height('100%')
1839e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
1840e41f4b71Sopenharmony_ci          .onReady(() =>{
1841e41f4b71Sopenharmony_ci            this.context.rect(20, 20, 100, 100) // Create a 100*100 rectangle at (20, 20)
1842e41f4b71Sopenharmony_ci            this.context.stroke()
1843e41f4b71Sopenharmony_ci          })
1844e41f4b71Sopenharmony_ci      }
1845e41f4b71Sopenharmony_ci      .width('100%')
1846e41f4b71Sopenharmony_ci      .height('100%')
1847e41f4b71Sopenharmony_ci    }
1848e41f4b71Sopenharmony_ci  }
1849e41f4b71Sopenharmony_ci  ```
1850e41f4b71Sopenharmony_ci
1851e41f4b71Sopenharmony_ci  ![en-us_image_0000001256978341](figures/en-us_image_0000001256978341.png)
1852e41f4b71Sopenharmony_ci
1853e41f4b71Sopenharmony_ci
1854e41f4b71Sopenharmony_ci### fill
1855e41f4b71Sopenharmony_ci
1856e41f4b71Sopenharmony_cifill(fillRule?: CanvasFillRule): void
1857e41f4b71Sopenharmony_ci
1858e41f4b71Sopenharmony_ciFills the area inside a closed path on the canvas.
1859e41f4b71Sopenharmony_ci
1860e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
1861e41f4b71Sopenharmony_ci
1862e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1863e41f4b71Sopenharmony_ci
1864e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1865e41f4b71Sopenharmony_ci
1866e41f4b71Sopenharmony_ci**Parameters** 
1867e41f4b71Sopenharmony_ci
1868e41f4b71Sopenharmony_ci| Name | Type            | Mandatory  | Description   |
1869e41f4b71Sopenharmony_ci| -------- | -------------- | ---- | ---------------------------------------- |
1870e41f4b71Sopenharmony_ci| fillRule | [CanvasFillRule](ts-canvasrenderingcontext2d.md#canvasfillrule) | No   | Rule by which to determine whether a point is inside or outside the area to fill.<br>The options are **"nonzero"** and **"evenodd"**.<br>Default value: **"nonzero"** |
1871e41f4b71Sopenharmony_ci
1872e41f4b71Sopenharmony_ci
1873e41f4b71Sopenharmony_ci**Example**  
1874e41f4b71Sopenharmony_ci
1875e41f4b71Sopenharmony_ci  ```ts
1876e41f4b71Sopenharmony_ci  // xxx.ets
1877e41f4b71Sopenharmony_ci  @Entry
1878e41f4b71Sopenharmony_ci  @Component
1879e41f4b71Sopenharmony_ci  struct Fill {
1880e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
1881e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
1882e41f4b71Sopenharmony_ci
1883e41f4b71Sopenharmony_ci    build() {
1884e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
1885e41f4b71Sopenharmony_ci        Canvas(this.context)
1886e41f4b71Sopenharmony_ci          .width('100%')
1887e41f4b71Sopenharmony_ci          .height('100%')
1888e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
1889e41f4b71Sopenharmony_ci          .onReady(() =>{
1890e41f4b71Sopenharmony_ci            this.context.rect(20, 20, 100, 100) // Create a 100*100 rectangle at (20, 20)
1891e41f4b71Sopenharmony_ci            this.context.fill()
1892e41f4b71Sopenharmony_ci          })
1893e41f4b71Sopenharmony_ci      }
1894e41f4b71Sopenharmony_ci      .width('100%')
1895e41f4b71Sopenharmony_ci      .height('100%')
1896e41f4b71Sopenharmony_ci    }
1897e41f4b71Sopenharmony_ci  }
1898e41f4b71Sopenharmony_ci  ```
1899e41f4b71Sopenharmony_ci
1900e41f4b71Sopenharmony_ci  ![en-us_image_0000001256858389](figures/en-us_image_0000001256858389.png)
1901e41f4b71Sopenharmony_ci
1902e41f4b71Sopenharmony_ci
1903e41f4b71Sopenharmony_cifill(path: Path2D, fillRule?: CanvasFillRule): void
1904e41f4b71Sopenharmony_ci
1905e41f4b71Sopenharmony_ciFills the area inside a closed path on the canvas.
1906e41f4b71Sopenharmony_ci
1907e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
1908e41f4b71Sopenharmony_ci
1909e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1910e41f4b71Sopenharmony_ci
1911e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1912e41f4b71Sopenharmony_ci
1913e41f4b71Sopenharmony_ci**Parameters** 
1914e41f4b71Sopenharmony_ci
1915e41f4b71Sopenharmony_ci| Name   | Type            | Mandatory  | Description |
1916e41f4b71Sopenharmony_ci| -------- | -------------- | ---- | ---------------------------------------- |
1917e41f4b71Sopenharmony_ci| path     | [Path2D](ts-components-canvas-path2d.md)         | Yes | A **Path2D** path to fill.                             |
1918e41f4b71Sopenharmony_ci| fillRule | [CanvasFillRule](ts-canvasrenderingcontext2d.md#canvasfillrule) | No   | Rule by which to determine whether a point is inside or outside the area to fill.<br>The options are **"nonzero"** and **"evenodd"**.<br>Default value: **"nonzero"** |
1919e41f4b71Sopenharmony_ci
1920e41f4b71Sopenharmony_ci
1921e41f4b71Sopenharmony_ci**Example**  
1922e41f4b71Sopenharmony_ci
1923e41f4b71Sopenharmony_ci```ts
1924e41f4b71Sopenharmony_ci// xxx.ets
1925e41f4b71Sopenharmony_ci@Entry
1926e41f4b71Sopenharmony_ci@Component
1927e41f4b71Sopenharmony_cistruct Fill {
1928e41f4b71Sopenharmony_ci  private settings: RenderingContextSettings = new RenderingContextSettings(true)
1929e41f4b71Sopenharmony_ci  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
1930e41f4b71Sopenharmony_ci
1931e41f4b71Sopenharmony_ci  build() {
1932e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
1933e41f4b71Sopenharmony_ci      Canvas(this.context)
1934e41f4b71Sopenharmony_ci        .width('100%')
1935e41f4b71Sopenharmony_ci        .height('100%')
1936e41f4b71Sopenharmony_ci        .backgroundColor('#ffff00')
1937e41f4b71Sopenharmony_ci        .onReady(() =>{
1938e41f4b71Sopenharmony_ci          let region = new Path2D()
1939e41f4b71Sopenharmony_ci          region.moveTo(30, 90)
1940e41f4b71Sopenharmony_ci          region.lineTo(110, 20)
1941e41f4b71Sopenharmony_ci          region.lineTo(240, 130)
1942e41f4b71Sopenharmony_ci          region.lineTo(60, 130)
1943e41f4b71Sopenharmony_ci          region.lineTo(190, 20)
1944e41f4b71Sopenharmony_ci          region.lineTo(270, 90)
1945e41f4b71Sopenharmony_ci          region.closePath()
1946e41f4b71Sopenharmony_ci          // Fill path
1947e41f4b71Sopenharmony_ci          this.context.fillStyle = '#00ff00'
1948e41f4b71Sopenharmony_ci          this.context.fill(region, "evenodd")
1949e41f4b71Sopenharmony_ci        })
1950e41f4b71Sopenharmony_ci    }
1951e41f4b71Sopenharmony_ci    .width('100%')
1952e41f4b71Sopenharmony_ci    .height('100%')
1953e41f4b71Sopenharmony_ci  }
1954e41f4b71Sopenharmony_ci}
1955e41f4b71Sopenharmony_ci```
1956e41f4b71Sopenharmony_ci
1957e41f4b71Sopenharmony_ci ![en-us_image_000000127777774](figures/en-us_image_000000127777774.png)
1958e41f4b71Sopenharmony_ci
1959e41f4b71Sopenharmony_ci
1960e41f4b71Sopenharmony_ci### clip
1961e41f4b71Sopenharmony_ci
1962e41f4b71Sopenharmony_ciclip(fillRule?: CanvasFillRule): void
1963e41f4b71Sopenharmony_ci
1964e41f4b71Sopenharmony_ciSets the current path to a clipping area.
1965e41f4b71Sopenharmony_ci
1966e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
1967e41f4b71Sopenharmony_ci
1968e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1969e41f4b71Sopenharmony_ci
1970e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1971e41f4b71Sopenharmony_ci
1972e41f4b71Sopenharmony_ci**Parameters** 
1973e41f4b71Sopenharmony_ci
1974e41f4b71Sopenharmony_ci| Name      | Type            | Mandatory  | Description                           |
1975e41f4b71Sopenharmony_ci| -------- | -------------- | ---- | ---------------------------------------- |
1976e41f4b71Sopenharmony_ci| fillRule | [CanvasFillRule](#canvasfillrule) | No | Rule by which to determine whether a point is inside or outside the area to clip.<br>The options are **"nonzero"** and **"evenodd"**.<br>Default value: **"nonzero"** |
1977e41f4b71Sopenharmony_ci
1978e41f4b71Sopenharmony_ci**Example** 
1979e41f4b71Sopenharmony_ci
1980e41f4b71Sopenharmony_ci  ```ts
1981e41f4b71Sopenharmony_ci  // xxx.ets
1982e41f4b71Sopenharmony_ci  @Entry
1983e41f4b71Sopenharmony_ci  @Component
1984e41f4b71Sopenharmony_ci  struct Clip {
1985e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
1986e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
1987e41f4b71Sopenharmony_ci
1988e41f4b71Sopenharmony_ci    build() {
1989e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
1990e41f4b71Sopenharmony_ci        Canvas(this.context)
1991e41f4b71Sopenharmony_ci          .width('100%')
1992e41f4b71Sopenharmony_ci          .height('100%')
1993e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
1994e41f4b71Sopenharmony_ci          .onReady(() =>{
1995e41f4b71Sopenharmony_ci            this.context.rect(0, 0, 100, 200)
1996e41f4b71Sopenharmony_ci            this.context.stroke()
1997e41f4b71Sopenharmony_ci            this.context.clip()
1998e41f4b71Sopenharmony_ci            this.context.fillStyle = "rgb(255,0,0)"
1999e41f4b71Sopenharmony_ci            this.context.fillRect(0, 0, 200, 200)
2000e41f4b71Sopenharmony_ci          })
2001e41f4b71Sopenharmony_ci      }
2002e41f4b71Sopenharmony_ci      .width('100%')
2003e41f4b71Sopenharmony_ci      .height('100%')
2004e41f4b71Sopenharmony_ci    }
2005e41f4b71Sopenharmony_ci  }
2006e41f4b71Sopenharmony_ci  ```
2007e41f4b71Sopenharmony_ci
2008e41f4b71Sopenharmony_ci  ![en-us_image_0000001211898488](figures/en-us_image_0000001211898488.png)
2009e41f4b71Sopenharmony_ci
2010e41f4b71Sopenharmony_ci
2011e41f4b71Sopenharmony_ciclip(path: Path2D, fillRule?: CanvasFillRule): void
2012e41f4b71Sopenharmony_ci
2013e41f4b71Sopenharmony_ciSets the current path to a clipping path.
2014e41f4b71Sopenharmony_ci
2015e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
2016e41f4b71Sopenharmony_ci
2017e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2018e41f4b71Sopenharmony_ci
2019e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2020e41f4b71Sopenharmony_ci
2021e41f4b71Sopenharmony_ci**Parameters** 
2022e41f4b71Sopenharmony_ci
2023e41f4b71Sopenharmony_ci| Name     | Type            | Mandatory  | Description         |
2024e41f4b71Sopenharmony_ci| -------- | -------------- | ---- | ---------------------------------------- |
2025e41f4b71Sopenharmony_ci| path     | [Path2D](ts-components-canvas-path2d.md)         | Yes   | A **Path2D** path to use as a clipping area.                             |
2026e41f4b71Sopenharmony_ci| fillRule | [CanvasFillRule](#canvasfillrule) | No | Rule by which to determine whether a point is inside or outside the area to clip.<br>The options are **"nonzero"** and **"evenodd"**.<br>Default value: **"nonzero"** |
2027e41f4b71Sopenharmony_ci
2028e41f4b71Sopenharmony_ci
2029e41f4b71Sopenharmony_ci**Example** 
2030e41f4b71Sopenharmony_ci
2031e41f4b71Sopenharmony_ci  ```ts
2032e41f4b71Sopenharmony_ci  // xxx.ets
2033e41f4b71Sopenharmony_ci  @Entry
2034e41f4b71Sopenharmony_ci  @Component
2035e41f4b71Sopenharmony_ci  struct Clip {
2036e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
2037e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
2038e41f4b71Sopenharmony_ci    build() {
2039e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
2040e41f4b71Sopenharmony_ci        Canvas(this.context)
2041e41f4b71Sopenharmony_ci          .width('100%')
2042e41f4b71Sopenharmony_ci          .height('100%')
2043e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
2044e41f4b71Sopenharmony_ci          .onReady(() =>{
2045e41f4b71Sopenharmony_ci            let region = new Path2D()
2046e41f4b71Sopenharmony_ci            region.moveTo(30, 90)
2047e41f4b71Sopenharmony_ci            region.lineTo(110, 20)
2048e41f4b71Sopenharmony_ci            region.lineTo(240, 130)
2049e41f4b71Sopenharmony_ci            region.lineTo(60, 130)
2050e41f4b71Sopenharmony_ci            region.lineTo(190, 20)
2051e41f4b71Sopenharmony_ci            region.lineTo(270, 90)
2052e41f4b71Sopenharmony_ci            region.closePath()
2053e41f4b71Sopenharmony_ci            this.context.clip(region,"evenodd")
2054e41f4b71Sopenharmony_ci            this.context.fillStyle = "rgb(0,255,0)"
2055e41f4b71Sopenharmony_ci            this.context.fillRect(0, 0, this.context.width, this.context.height)
2056e41f4b71Sopenharmony_ci          })
2057e41f4b71Sopenharmony_ci      }
2058e41f4b71Sopenharmony_ci      .width('100%')
2059e41f4b71Sopenharmony_ci      .height('100%')
2060e41f4b71Sopenharmony_ci    }
2061e41f4b71Sopenharmony_ci  }
2062e41f4b71Sopenharmony_ci  ```
2063e41f4b71Sopenharmony_ci
2064e41f4b71Sopenharmony_ci  ![en-us_image_000000127777779](figures/en-us_image_000000127777779.png)
2065e41f4b71Sopenharmony_ci
2066e41f4b71Sopenharmony_ci
2067e41f4b71Sopenharmony_ci### reset<sup>12+</sup>
2068e41f4b71Sopenharmony_ci
2069e41f4b71Sopenharmony_cireset(): void
2070e41f4b71Sopenharmony_ci
2071e41f4b71Sopenharmony_ciResets this **CanvasRenderingContext2D** object to its default state and clears the background buffer, drawing state stack, defined paths, and styles.
2072e41f4b71Sopenharmony_ci
2073e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12.
2074e41f4b71Sopenharmony_ci
2075e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2076e41f4b71Sopenharmony_ci
2077e41f4b71Sopenharmony_ci**Example**
2078e41f4b71Sopenharmony_ci
2079e41f4b71Sopenharmony_ci  ```ts
2080e41f4b71Sopenharmony_ci  // xxx.ets
2081e41f4b71Sopenharmony_ci  @Entry
2082e41f4b71Sopenharmony_ci  @Component
2083e41f4b71Sopenharmony_ci  struct Reset {
2084e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
2085e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
2086e41f4b71Sopenharmony_ci
2087e41f4b71Sopenharmony_ci    build() {
2088e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
2089e41f4b71Sopenharmony_ci        Canvas(this.context)
2090e41f4b71Sopenharmony_ci          .width('100%')
2091e41f4b71Sopenharmony_ci          .height('100%')
2092e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
2093e41f4b71Sopenharmony_ci          .onReady(() =>{
2094e41f4b71Sopenharmony_ci            this.context.fillStyle = '#0000ff'
2095e41f4b71Sopenharmony_ci            this.context.fillRect(20, 20, 150, 100)
2096e41f4b71Sopenharmony_ci            this.context.reset()
2097e41f4b71Sopenharmony_ci            this.context.fillRect(20, 150, 150, 100)
2098e41f4b71Sopenharmony_ci          })
2099e41f4b71Sopenharmony_ci      }
2100e41f4b71Sopenharmony_ci      .width('100%')
2101e41f4b71Sopenharmony_ci      .height('100%')
2102e41f4b71Sopenharmony_ci    }
2103e41f4b71Sopenharmony_ci  }
2104e41f4b71Sopenharmony_ci  ```
2105e41f4b71Sopenharmony_ci
2106e41f4b71Sopenharmony_ci  ![en-us_image_0000001239032460](figures/en-us_image_0000001239032460.png)
2107e41f4b71Sopenharmony_ci
2108e41f4b71Sopenharmony_ci
2109e41f4b71Sopenharmony_ci### saveLayer<sup>12+</sup>
2110e41f4b71Sopenharmony_ci
2111e41f4b71Sopenharmony_cisaveLayer(): void
2112e41f4b71Sopenharmony_ci
2113e41f4b71Sopenharmony_ciSaves this layer.
2114e41f4b71Sopenharmony_ci
2115e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12.
2116e41f4b71Sopenharmony_ci
2117e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2118e41f4b71Sopenharmony_ci
2119e41f4b71Sopenharmony_ci**Example**
2120e41f4b71Sopenharmony_ci
2121e41f4b71Sopenharmony_ci  ```ts
2122e41f4b71Sopenharmony_ci  // xxx.ets
2123e41f4b71Sopenharmony_ci  @Entry
2124e41f4b71Sopenharmony_ci  @Component
2125e41f4b71Sopenharmony_ci  struct saveLayer {
2126e41f4b71Sopenharmony_ci  private settings: RenderingContextSettings = new RenderingContextSettings(true)
2127e41f4b71Sopenharmony_ci  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
2128e41f4b71Sopenharmony_ci
2129e41f4b71Sopenharmony_ci  build() {
2130e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
2131e41f4b71Sopenharmony_ci      Canvas(this.context)
2132e41f4b71Sopenharmony_ci        .width('100%')
2133e41f4b71Sopenharmony_ci        .height('100%')
2134e41f4b71Sopenharmony_ci        .backgroundColor('#ffff00')
2135e41f4b71Sopenharmony_ci        .onReady(() =>{
2136e41f4b71Sopenharmony_ci          this.context.fillStyle = "#0000ff"
2137e41f4b71Sopenharmony_ci          this.context.fillRect(50,100,300,100)
2138e41f4b71Sopenharmony_ci          this.context.fillStyle = "#00ffff"
2139e41f4b71Sopenharmony_ci          this.context.fillRect(50,150,300,100)
2140e41f4b71Sopenharmony_ci          this.context.globalCompositeOperation = 'destination-over'
2141e41f4b71Sopenharmony_ci          this.context.saveLayer()
2142e41f4b71Sopenharmony_ci          this.context.globalCompositeOperation = 'source-over'
2143e41f4b71Sopenharmony_ci          this.context.fillStyle = "#ff0000"
2144e41f4b71Sopenharmony_ci          this.context.fillRect(100,50,100,300)
2145e41f4b71Sopenharmony_ci          this.context.fillStyle = "#00ff00"
2146e41f4b71Sopenharmony_ci          this.context.fillRect(150,50,100,300)
2147e41f4b71Sopenharmony_ci          this.context.restoreLayer()
2148e41f4b71Sopenharmony_ci        })
2149e41f4b71Sopenharmony_ci    }
2150e41f4b71Sopenharmony_ci    .width('100%')
2151e41f4b71Sopenharmony_ci    .height('100%')
2152e41f4b71Sopenharmony_ci  }
2153e41f4b71Sopenharmony_ci  }
2154e41f4b71Sopenharmony_ci
2155e41f4b71Sopenharmony_ci  ```
2156e41f4b71Sopenharmony_ci   ![en-us_image_CanvasSavelayer](figures/en-us_image_CanvasSavelayer.png)
2157e41f4b71Sopenharmony_ci
2158e41f4b71Sopenharmony_ci### restoreLayer<sup>12+</sup>
2159e41f4b71Sopenharmony_ci
2160e41f4b71Sopenharmony_cirestoreLayer(): void
2161e41f4b71Sopenharmony_ci
2162e41f4b71Sopenharmony_ciRestores the image transformation and cropping state to the state before **saveLayer**, and then draws the layer onto the canvas. For the sample code, see the code for **saveLayer**.
2163e41f4b71Sopenharmony_ci
2164e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 12.
2165e41f4b71Sopenharmony_ci
2166e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2167e41f4b71Sopenharmony_ci
2168e41f4b71Sopenharmony_ci### resetTransform
2169e41f4b71Sopenharmony_ci
2170e41f4b71Sopenharmony_ciresetTransform(): void
2171e41f4b71Sopenharmony_ci
2172e41f4b71Sopenharmony_ciResets the current transform to the identity matrix.
2173e41f4b71Sopenharmony_ci
2174e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
2175e41f4b71Sopenharmony_ci
2176e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2177e41f4b71Sopenharmony_ci
2178e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2179e41f4b71Sopenharmony_ci
2180e41f4b71Sopenharmony_ci**Example**
2181e41f4b71Sopenharmony_ci
2182e41f4b71Sopenharmony_ci  ```ts
2183e41f4b71Sopenharmony_ci  // xxx.ets
2184e41f4b71Sopenharmony_ci  @Entry
2185e41f4b71Sopenharmony_ci  @Component
2186e41f4b71Sopenharmony_ci  struct ResetTransform {
2187e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
2188e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
2189e41f4b71Sopenharmony_ci
2190e41f4b71Sopenharmony_ci    build() {
2191e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
2192e41f4b71Sopenharmony_ci        Canvas(this.context)
2193e41f4b71Sopenharmony_ci          .width('100%')
2194e41f4b71Sopenharmony_ci          .height('100%')
2195e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
2196e41f4b71Sopenharmony_ci          .onReady(() =>{
2197e41f4b71Sopenharmony_ci            this.context.setTransform(1,0.5, -0.5, 1, 10, 10)
2198e41f4b71Sopenharmony_ci            this.context.fillStyle = 'rgb(0,0,255)'
2199e41f4b71Sopenharmony_ci            this.context.fillRect(0, 0, 100, 100)
2200e41f4b71Sopenharmony_ci            this.context.resetTransform()
2201e41f4b71Sopenharmony_ci            this.context.fillStyle = 'rgb(255,0,0)'
2202e41f4b71Sopenharmony_ci            this.context.fillRect(0, 0, 100, 100)
2203e41f4b71Sopenharmony_ci          })
2204e41f4b71Sopenharmony_ci      }
2205e41f4b71Sopenharmony_ci      .width('100%')
2206e41f4b71Sopenharmony_ci      .height('100%')
2207e41f4b71Sopenharmony_ci    }
2208e41f4b71Sopenharmony_ci  }
2209e41f4b71Sopenharmony_ci  ```
2210e41f4b71Sopenharmony_ci
2211e41f4b71Sopenharmony_ci  ![en-us_image_0000001239032417](figures/en-us_image_ResetTransform.png)
2212e41f4b71Sopenharmony_ci
2213e41f4b71Sopenharmony_ci### rotate
2214e41f4b71Sopenharmony_ci
2215e41f4b71Sopenharmony_cirotate(angle: number): void
2216e41f4b71Sopenharmony_ci
2217e41f4b71Sopenharmony_ciRotates a canvas clockwise around its coordinate axes.
2218e41f4b71Sopenharmony_ci
2219e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
2220e41f4b71Sopenharmony_ci
2221e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2222e41f4b71Sopenharmony_ci
2223e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2224e41f4b71Sopenharmony_ci
2225e41f4b71Sopenharmony_ci**Parameters**
2226e41f4b71Sopenharmony_ci
2227e41f4b71Sopenharmony_ci| Name   | Type    | Mandatory  | Description                                      |
2228e41f4b71Sopenharmony_ci| ----- | ------ | ---- |  ---------------------------------------- |
2229e41f4b71Sopenharmony_ci| angle | number | Yes  | Clockwise rotation angle. You can use **Math.PI / 180** to convert the angle to a radian.<br>Default value: **0** |
2230e41f4b71Sopenharmony_ci
2231e41f4b71Sopenharmony_ci**Example**
2232e41f4b71Sopenharmony_ci
2233e41f4b71Sopenharmony_ci  ```ts
2234e41f4b71Sopenharmony_ci  // xxx.ets
2235e41f4b71Sopenharmony_ci  @Entry
2236e41f4b71Sopenharmony_ci  @Component
2237e41f4b71Sopenharmony_ci  struct Rotate {
2238e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
2239e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
2240e41f4b71Sopenharmony_ci
2241e41f4b71Sopenharmony_ci    build() {
2242e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
2243e41f4b71Sopenharmony_ci        Canvas(this.context)
2244e41f4b71Sopenharmony_ci          .width('100%')
2245e41f4b71Sopenharmony_ci          .height('100%')
2246e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
2247e41f4b71Sopenharmony_ci          .onReady(() =>{
2248e41f4b71Sopenharmony_ci            this.context.rotate(45 * Math.PI / 180)
2249e41f4b71Sopenharmony_ci            this.context.fillRect(70, 20, 50, 50)
2250e41f4b71Sopenharmony_ci          })
2251e41f4b71Sopenharmony_ci      }
2252e41f4b71Sopenharmony_ci      .width('100%')
2253e41f4b71Sopenharmony_ci      .height('100%')
2254e41f4b71Sopenharmony_ci    }
2255e41f4b71Sopenharmony_ci  }
2256e41f4b71Sopenharmony_ci  ```
2257e41f4b71Sopenharmony_ci
2258e41f4b71Sopenharmony_ci  ![en-us_image_0000001212218442](figures/en-us_image_0000001212218442.png)
2259e41f4b71Sopenharmony_ci
2260e41f4b71Sopenharmony_ci
2261e41f4b71Sopenharmony_ci### scale
2262e41f4b71Sopenharmony_ci
2263e41f4b71Sopenharmony_ciscale(x: number, y: number): void
2264e41f4b71Sopenharmony_ci
2265e41f4b71Sopenharmony_ciScales the canvas based on the given scale factors.
2266e41f4b71Sopenharmony_ci
2267e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
2268e41f4b71Sopenharmony_ci
2269e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2270e41f4b71Sopenharmony_ci
2271e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2272e41f4b71Sopenharmony_ci
2273e41f4b71Sopenharmony_ci**Parameters**
2274e41f4b71Sopenharmony_ci
2275e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory | Description   |
2276e41f4b71Sopenharmony_ci| ---- | ------ | ---- | ----------- |
2277e41f4b71Sopenharmony_ci| x    | number | Yes | Horizontal scale factor.<br>Default value: **0** |
2278e41f4b71Sopenharmony_ci| y    | number | Yes | Vertical scale factor.<br>Default value: **0** |
2279e41f4b71Sopenharmony_ci
2280e41f4b71Sopenharmony_ci**Example**
2281e41f4b71Sopenharmony_ci
2282e41f4b71Sopenharmony_ci  ```ts
2283e41f4b71Sopenharmony_ci  // xxx.ets
2284e41f4b71Sopenharmony_ci  @Entry
2285e41f4b71Sopenharmony_ci  @Component
2286e41f4b71Sopenharmony_ci  struct Scale {
2287e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
2288e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
2289e41f4b71Sopenharmony_ci
2290e41f4b71Sopenharmony_ci    build() {
2291e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
2292e41f4b71Sopenharmony_ci        Canvas(this.context)
2293e41f4b71Sopenharmony_ci          .width('100%')
2294e41f4b71Sopenharmony_ci          .height('100%')
2295e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
2296e41f4b71Sopenharmony_ci          .onReady(() =>{
2297e41f4b71Sopenharmony_ci            this.context.lineWidth = 3
2298e41f4b71Sopenharmony_ci            this.context.strokeRect(30, 30, 50, 50)
2299e41f4b71Sopenharmony_ci            this.context.scale(2, 2) // Scale to 200%
2300e41f4b71Sopenharmony_ci            this.context.strokeRect(30, 30, 50, 50)
2301e41f4b71Sopenharmony_ci          })
2302e41f4b71Sopenharmony_ci      }
2303e41f4b71Sopenharmony_ci      .width('100%')
2304e41f4b71Sopenharmony_ci      .height('100%')
2305e41f4b71Sopenharmony_ci    }
2306e41f4b71Sopenharmony_ci  }
2307e41f4b71Sopenharmony_ci  ```
2308e41f4b71Sopenharmony_ci
2309e41f4b71Sopenharmony_ci  ![en-us_image_0000001257138347](figures/en-us_image_0000001257138347.png)
2310e41f4b71Sopenharmony_ci
2311e41f4b71Sopenharmony_ci
2312e41f4b71Sopenharmony_ci### transform
2313e41f4b71Sopenharmony_ci
2314e41f4b71Sopenharmony_citransform(a: number, b: number, c: number, d: number, e: number, f: number): void
2315e41f4b71Sopenharmony_ci
2316e41f4b71Sopenharmony_ciDefines a transformation matrix. To transform a graph, you only need to set parameters of the matrix. The coordinates of the graph are multiplied by the matrix values to obtain new coordinates of the transformed graph. You can use the matrix to implement multiple transform effects.
2317e41f4b71Sopenharmony_ci
2318e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
2319e41f4b71Sopenharmony_ci
2320e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2321e41f4b71Sopenharmony_ci
2322e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2323e41f4b71Sopenharmony_ci
2324e41f4b71Sopenharmony_ci> **NOTE**
2325e41f4b71Sopenharmony_ci> The following formulas calculate coordinates of the transformed graph. **x** and **y** represent coordinates before transformation, and **x'** and **y'** represent coordinates after transformation.
2326e41f4b71Sopenharmony_ci>
2327e41f4b71Sopenharmony_ci> - x' = scaleX \* x + skewY \* y + translateX
2328e41f4b71Sopenharmony_ci>
2329e41f4b71Sopenharmony_ci> - y' = skewX \* x + scaleY \* y + translateY
2330e41f4b71Sopenharmony_ci
2331e41f4b71Sopenharmony_ci**Parameters**
2332e41f4b71Sopenharmony_ci
2333e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory  | Description                  |
2334e41f4b71Sopenharmony_ci| ---- | ------ | ---- | -------------------- |
2335e41f4b71Sopenharmony_ci| a    | number | Yes | X-axis scale.<br>Default value: **0**   |
2336e41f4b71Sopenharmony_ci| b    | number | Yes | Y-axis skew.<br>Default value: **0**   |
2337e41f4b71Sopenharmony_ci| c    | number | Yes | X-axis skew.<br>Default value: **0**   |
2338e41f4b71Sopenharmony_ci| d    | number | Yes | Y-axis scale.<br>Default value: **0**   |
2339e41f4b71Sopenharmony_ci| e    | number | Yes | **translateX**: distance to translate on the x-axis.<br>Default unit: vp<br>Default value: **0** |
2340e41f4b71Sopenharmony_ci| f    | number | Yes | **translateY**: distance to translate on the y-axis.<br>Default unit: vp<br>Default value: **0** |
2341e41f4b71Sopenharmony_ci
2342e41f4b71Sopenharmony_ci**Example**
2343e41f4b71Sopenharmony_ci
2344e41f4b71Sopenharmony_ci  ```ts
2345e41f4b71Sopenharmony_ci  // xxx.ets
2346e41f4b71Sopenharmony_ci  @Entry
2347e41f4b71Sopenharmony_ci  @Component
2348e41f4b71Sopenharmony_ci  struct Transform {
2349e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
2350e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
2351e41f4b71Sopenharmony_ci
2352e41f4b71Sopenharmony_ci    build() {
2353e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
2354e41f4b71Sopenharmony_ci        Canvas(this.context)
2355e41f4b71Sopenharmony_ci          .width('100%')
2356e41f4b71Sopenharmony_ci          .height('100%')
2357e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
2358e41f4b71Sopenharmony_ci          .onReady(() =>{
2359e41f4b71Sopenharmony_ci            this.context.fillStyle = 'rgb(0,0,0)'
2360e41f4b71Sopenharmony_ci            this.context.fillRect(0, 0, 100, 100)
2361e41f4b71Sopenharmony_ci            this.context.transform(1, 0.5, -0.5, 1, 10, 10)
2362e41f4b71Sopenharmony_ci            this.context.fillStyle = 'rgb(255,0,0)'
2363e41f4b71Sopenharmony_ci            this.context.fillRect(0, 0, 100, 100)
2364e41f4b71Sopenharmony_ci            this.context.transform(1, 0.5, -0.5, 1, 10, 10)
2365e41f4b71Sopenharmony_ci            this.context.fillStyle = 'rgb(0,0,255)'
2366e41f4b71Sopenharmony_ci            this.context.fillRect(0, 0, 100, 100)
2367e41f4b71Sopenharmony_ci          })
2368e41f4b71Sopenharmony_ci      }
2369e41f4b71Sopenharmony_ci      .width('100%')
2370e41f4b71Sopenharmony_ci      .height('100%')
2371e41f4b71Sopenharmony_ci    }
2372e41f4b71Sopenharmony_ci  }
2373e41f4b71Sopenharmony_ci  ```
2374e41f4b71Sopenharmony_ci
2375e41f4b71Sopenharmony_ci  ![en-us_image_0000001256858393](figures/en-us_image_0000001256858393.png)
2376e41f4b71Sopenharmony_ci
2377e41f4b71Sopenharmony_ci
2378e41f4b71Sopenharmony_ci### setTransform
2379e41f4b71Sopenharmony_ci
2380e41f4b71Sopenharmony_cisetTransform(a: number, b: number, c: number, d: number, e: number, f: number): void
2381e41f4b71Sopenharmony_ci
2382e41f4b71Sopenharmony_ciResets the existing transformation matrix and creates a new transformation matrix by using the same parameters as the **transform()** API.
2383e41f4b71Sopenharmony_ci
2384e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
2385e41f4b71Sopenharmony_ci
2386e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2387e41f4b71Sopenharmony_ci
2388e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2389e41f4b71Sopenharmony_ci
2390e41f4b71Sopenharmony_ci**Parameters**
2391e41f4b71Sopenharmony_ci
2392e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory  | Description   |
2393e41f4b71Sopenharmony_ci| ---- | ------ | ---- | -------------------- |
2394e41f4b71Sopenharmony_ci| a    | number | Yes | X-axis scale.<br>Default value: **0** |
2395e41f4b71Sopenharmony_ci| b    | number | Yes | Y-axis skew.<br>Default value: **0** |
2396e41f4b71Sopenharmony_ci| c    | number | Yes | X-axis skew.<br>Default value: **0** |
2397e41f4b71Sopenharmony_ci| d    | number | Yes | Y-axis scale.<br>Default value: **0** |
2398e41f4b71Sopenharmony_ci| e    | number | Yes | **translateX**: distance to translate on the x-axis.<br>Default unit: vp<br>Default value: **0** |
2399e41f4b71Sopenharmony_ci| f    | number | Yes | **translateY**: distance to translate on the y-axis.<br>Default unit: vp<br>Default value: **0** |
2400e41f4b71Sopenharmony_ci
2401e41f4b71Sopenharmony_ci**Example**
2402e41f4b71Sopenharmony_ci
2403e41f4b71Sopenharmony_ci  ```ts
2404e41f4b71Sopenharmony_ci  // xxx.ets
2405e41f4b71Sopenharmony_ci  @Entry
2406e41f4b71Sopenharmony_ci  @Component
2407e41f4b71Sopenharmony_ci  struct SetTransform {
2408e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
2409e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
2410e41f4b71Sopenharmony_ci
2411e41f4b71Sopenharmony_ci    build() {
2412e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
2413e41f4b71Sopenharmony_ci        Canvas(this.context)
2414e41f4b71Sopenharmony_ci          .width('100%')
2415e41f4b71Sopenharmony_ci          .height('100%')
2416e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
2417e41f4b71Sopenharmony_ci          .onReady(() =>{
2418e41f4b71Sopenharmony_ci            this.context.fillStyle = 'rgb(255,0,0)'
2419e41f4b71Sopenharmony_ci            this.context.fillRect(0, 0, 100, 100)
2420e41f4b71Sopenharmony_ci            this.context.setTransform(1,0.5, -0.5, 1, 10, 10)
2421e41f4b71Sopenharmony_ci            this.context.fillStyle = 'rgb(0,0,255)'
2422e41f4b71Sopenharmony_ci            this.context.fillRect(0, 0, 100, 100)
2423e41f4b71Sopenharmony_ci          })
2424e41f4b71Sopenharmony_ci      }
2425e41f4b71Sopenharmony_ci      .width('100%')
2426e41f4b71Sopenharmony_ci      .height('100%')
2427e41f4b71Sopenharmony_ci    }
2428e41f4b71Sopenharmony_ci  }
2429e41f4b71Sopenharmony_ci  ```
2430e41f4b71Sopenharmony_ci
2431e41f4b71Sopenharmony_ci  ![en-us_image_0000001256858395](figures/en-us_image_0000001256858395.png)
2432e41f4b71Sopenharmony_ci
2433e41f4b71Sopenharmony_ci### setTransform
2434e41f4b71Sopenharmony_ci
2435e41f4b71Sopenharmony_cisetTransform(transform?: Matrix2D): void
2436e41f4b71Sopenharmony_ci
2437e41f4b71Sopenharmony_ciResets the current transformation to the identity matrix, and then creates a new transformation matrix based on the specified **Matrix2D** object.
2438e41f4b71Sopenharmony_ci
2439e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
2440e41f4b71Sopenharmony_ci
2441e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2442e41f4b71Sopenharmony_ci
2443e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2444e41f4b71Sopenharmony_ci
2445e41f4b71Sopenharmony_ci**Parameters**
2446e41f4b71Sopenharmony_ci
2447e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description |
2448e41f4b71Sopenharmony_ci| --------- | ---------------------------------------- | ---- | ----- |
2449e41f4b71Sopenharmony_ci| transform | [Matrix2D](ts-components-canvas-matrix2d.md#Matrix2D) | No | Transformation matrix.<br>Default value: **null** |
2450e41f4b71Sopenharmony_ci
2451e41f4b71Sopenharmony_ci**Example**
2452e41f4b71Sopenharmony_ci
2453e41f4b71Sopenharmony_ci  ```ts
2454e41f4b71Sopenharmony_ci  // xxx.ets
2455e41f4b71Sopenharmony_ci  @Entry
2456e41f4b71Sopenharmony_ci  @Component
2457e41f4b71Sopenharmony_ci  struct TransFormDemo {
2458e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true);
2459e41f4b71Sopenharmony_ci    private context1: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.  settings);
2460e41f4b71Sopenharmony_ci    private context2: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
2461e41f4b71Sopenharmony_ci
2462e41f4b71Sopenharmony_ci    build() {
2463e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
2464e41f4b71Sopenharmony_ci        Text('context1');
2465e41f4b71Sopenharmony_ci        Canvas(this.context1)
2466e41f4b71Sopenharmony_ci          .width('230vp')
2467e41f4b71Sopenharmony_ci          .height('160vp')
2468e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
2469e41f4b71Sopenharmony_ci          .onReady(() =>{
2470e41f4b71Sopenharmony_ci            this.context1.fillRect(100, 20, 50, 50);
2471e41f4b71Sopenharmony_ci            this.context1.setTransform(1, 0.5, -0.5, 1, 10, 10);
2472e41f4b71Sopenharmony_ci            this.context1.fillRect(100, 20, 50, 50);
2473e41f4b71Sopenharmony_ci          })
2474e41f4b71Sopenharmony_ci        Text('context2');
2475e41f4b71Sopenharmony_ci        Canvas(this.context2)
2476e41f4b71Sopenharmony_ci          .width('230vp')
2477e41f4b71Sopenharmony_ci          .height('160vp')
2478e41f4b71Sopenharmony_ci          .backgroundColor('#0ffff0')
2479e41f4b71Sopenharmony_ci          .onReady(() =>{
2480e41f4b71Sopenharmony_ci            this.context2.fillRect(100, 20, 50, 50);
2481e41f4b71Sopenharmony_ci            let storedTransform = this.context1.getTransform();
2482e41f4b71Sopenharmony_ci            this.context2.setTransform(storedTransform);
2483e41f4b71Sopenharmony_ci            this.context2.fillRect(100, 20, 50, 50);
2484e41f4b71Sopenharmony_ci          })
2485e41f4b71Sopenharmony_ci      }
2486e41f4b71Sopenharmony_ci      .width('100%')
2487e41f4b71Sopenharmony_ci      .height('100%')
2488e41f4b71Sopenharmony_ci    }
2489e41f4b71Sopenharmony_ci  }
2490e41f4b71Sopenharmony_ci  ```
2491e41f4b71Sopenharmony_ci
2492e41f4b71Sopenharmony_ci  ![en-us_image_0000001238712422.jpeg](figures/en-us_image_0000001238712422.jpeg)
2493e41f4b71Sopenharmony_ci
2494e41f4b71Sopenharmony_ci### getTransform
2495e41f4b71Sopenharmony_ci
2496e41f4b71Sopenharmony_cigetTransform(): Matrix2D
2497e41f4b71Sopenharmony_ci
2498e41f4b71Sopenharmony_ciObtains the current transformation matrix being applied to the context.
2499e41f4b71Sopenharmony_ci
2500e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
2501e41f4b71Sopenharmony_ci
2502e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2503e41f4b71Sopenharmony_ci
2504e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2505e41f4b71Sopenharmony_ci
2506e41f4b71Sopenharmony_ci**Return value**
2507e41f4b71Sopenharmony_ci
2508e41f4b71Sopenharmony_ci| Type                                      | Description   |
2509e41f4b71Sopenharmony_ci| ---------------------------------------- | ----- |
2510e41f4b71Sopenharmony_ci| [Matrix2D](ts-components-canvas-matrix2d.md#Matrix2D) | **Matrix2D** object. |
2511e41f4b71Sopenharmony_ci
2512e41f4b71Sopenharmony_ci**Example**
2513e41f4b71Sopenharmony_ci
2514e41f4b71Sopenharmony_ci  ```ts
2515e41f4b71Sopenharmony_ci  // xxx.ets
2516e41f4b71Sopenharmony_ci  @Entry
2517e41f4b71Sopenharmony_ci  @Component
2518e41f4b71Sopenharmony_ci  struct TransFormDemo {
2519e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true);
2520e41f4b71Sopenharmony_ci    private context1: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
2521e41f4b71Sopenharmony_ci    private context2: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
2522e41f4b71Sopenharmony_ci
2523e41f4b71Sopenharmony_ci    build() {
2524e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
2525e41f4b71Sopenharmony_ci        Text('context1');
2526e41f4b71Sopenharmony_ci        Canvas(this.context1)
2527e41f4b71Sopenharmony_ci          .width('230vp')
2528e41f4b71Sopenharmony_ci          .height('120vp')
2529e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
2530e41f4b71Sopenharmony_ci          .onReady(() =>{
2531e41f4b71Sopenharmony_ci            this.context1.fillRect(50, 50, 50, 50);
2532e41f4b71Sopenharmony_ci            this.context1.setTransform(1.2, Math.PI/8, Math.PI/6, 0.5, 30, -25);
2533e41f4b71Sopenharmony_ci            this.context1.fillRect(50, 50, 50, 50);
2534e41f4b71Sopenharmony_ci          })
2535e41f4b71Sopenharmony_ci        Text('context2');
2536e41f4b71Sopenharmony_ci        Canvas(this.context2)
2537e41f4b71Sopenharmony_ci          .width('230vp')
2538e41f4b71Sopenharmony_ci          .height('120vp')
2539e41f4b71Sopenharmony_ci          .backgroundColor('#0ffff0')
2540e41f4b71Sopenharmony_ci          .onReady(() =>{
2541e41f4b71Sopenharmony_ci            this.context2.fillRect(50, 50, 50, 50);
2542e41f4b71Sopenharmony_ci            let storedTransform = this.context1.getTransform();
2543e41f4b71Sopenharmony_ci            console.log("Matrix [scaleX = " + storedTransform.scaleX + ", scaleY = " + storedTransform.scaleY +
2544e41f4b71Sopenharmony_ci            ", rotateX = " + storedTransform.rotateX + ", rotateY = " + storedTransform.rotateY +
2545e41f4b71Sopenharmony_ci            ", translateX = " + storedTransform.translateX + ", translateY = " + storedTransform.translateY + "]")
2546e41f4b71Sopenharmony_ci            this.context2.setTransform(storedTransform);
2547e41f4b71Sopenharmony_ci            this.context2.fillRect(50,50,50,50);
2548e41f4b71Sopenharmony_ci          })
2549e41f4b71Sopenharmony_ci      }
2550e41f4b71Sopenharmony_ci      .width('100%')
2551e41f4b71Sopenharmony_ci      .height('100%')
2552e41f4b71Sopenharmony_ci    }
2553e41f4b71Sopenharmony_ci  }
2554e41f4b71Sopenharmony_ci  ```
2555e41f4b71Sopenharmony_ci
2556e41f4b71Sopenharmony_ci  ![en-us_image_0000001219982726.png](figures/en-us_image_0000001219982726.png)
2557e41f4b71Sopenharmony_ci
2558e41f4b71Sopenharmony_ci### translate
2559e41f4b71Sopenharmony_ci
2560e41f4b71Sopenharmony_citranslate(x: number, y: number): void
2561e41f4b71Sopenharmony_ci
2562e41f4b71Sopenharmony_ciMoves the origin of the coordinate system.
2563e41f4b71Sopenharmony_ci
2564e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
2565e41f4b71Sopenharmony_ci
2566e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2567e41f4b71Sopenharmony_ci
2568e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2569e41f4b71Sopenharmony_ci
2570e41f4b71Sopenharmony_ci**Parameters**
2571e41f4b71Sopenharmony_ci
2572e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory  | Description |
2573e41f4b71Sopenharmony_ci| ---- | ------ | ---- | -------- |
2574e41f4b71Sopenharmony_ci| x    | number | Yes  | Distance to translate on the x-axis.<br>Default unit: vp<br>Default value: **0** |
2575e41f4b71Sopenharmony_ci| y    | number | Yes  | Distance to translate on the y-axis.<br>Default unit: vp<br>Default value: **0** |
2576e41f4b71Sopenharmony_ci
2577e41f4b71Sopenharmony_ci**Example**
2578e41f4b71Sopenharmony_ci
2579e41f4b71Sopenharmony_ci  ```ts
2580e41f4b71Sopenharmony_ci  // xxx.ets
2581e41f4b71Sopenharmony_ci  @Entry
2582e41f4b71Sopenharmony_ci  @Component
2583e41f4b71Sopenharmony_ci  struct Translate {
2584e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
2585e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
2586e41f4b71Sopenharmony_ci
2587e41f4b71Sopenharmony_ci    build() {
2588e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
2589e41f4b71Sopenharmony_ci        Canvas(this.context)
2590e41f4b71Sopenharmony_ci          .width('100%')
2591e41f4b71Sopenharmony_ci          .height('100%')
2592e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
2593e41f4b71Sopenharmony_ci          .onReady(() =>{
2594e41f4b71Sopenharmony_ci            this.context.fillRect(10, 10, 50, 50)
2595e41f4b71Sopenharmony_ci            this.context.translate(70, 70)
2596e41f4b71Sopenharmony_ci            this.context.fillRect(10, 10, 50, 50)
2597e41f4b71Sopenharmony_ci          })
2598e41f4b71Sopenharmony_ci      }
2599e41f4b71Sopenharmony_ci      .width('100%')
2600e41f4b71Sopenharmony_ci      .height('100%')
2601e41f4b71Sopenharmony_ci    }
2602e41f4b71Sopenharmony_ci  }
2603e41f4b71Sopenharmony_ci  ```
2604e41f4b71Sopenharmony_ci
2605e41f4b71Sopenharmony_ci  ![en-us_image_0000001257138357](figures/en-us_image_0000001257138357.png)
2606e41f4b71Sopenharmony_ci
2607e41f4b71Sopenharmony_ci
2608e41f4b71Sopenharmony_ci### drawImage
2609e41f4b71Sopenharmony_ci
2610e41f4b71Sopenharmony_cidrawImage(image: ImageBitmap | PixelMap, dx: number, dy: number): void
2611e41f4b71Sopenharmony_ci
2612e41f4b71Sopenharmony_cidrawImage(image: ImageBitmap | PixelMap, dx: number, dy: number, dw: number, dh: number): void
2613e41f4b71Sopenharmony_ci
2614e41f4b71Sopenharmony_cidrawImage(image: ImageBitmap | PixelMap, sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number): void
2615e41f4b71Sopenharmony_ci
2616e41f4b71Sopenharmony_ciDraws an image on the canvas.
2617e41f4b71Sopenharmony_ci
2618e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9, except that **PixelMap** objects are not supported.
2619e41f4b71Sopenharmony_ci
2620e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2621e41f4b71Sopenharmony_ci
2622e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2623e41f4b71Sopenharmony_ci
2624e41f4b71Sopenharmony_ci**Parameters**
2625e41f4b71Sopenharmony_ci
2626e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description |
2627e41f4b71Sopenharmony_ci| ----- | ---------------------------------------- | ---- | ---------------------------------------- |
2628e41f4b71Sopenharmony_ci| image | [ImageBitmap](ts-components-canvas-imagebitmap.md) or [PixelMap](../../apis-image-kit/js-apis-image.md#pixelmap7) | Yes   | Image resource. For details, see **ImageBitmap** or PixelMap.           |
2629e41f4b71Sopenharmony_ci| sx    | number                                   | No | X coordinate of the upper left corner of the rectangle used to crop the source image.<br>Default unit: vp<br>Default value: **0** |
2630e41f4b71Sopenharmony_ci| sy    | number                                   | No | Y coordinate of the upper left corner of the rectangle used to crop the source image.<br>Default unit: vp<br>Default value: **0** |
2631e41f4b71Sopenharmony_ci| sw    | number                                   | No | Target width to crop the source image.<br>Default unit: vp<br>Default value: **0** |
2632e41f4b71Sopenharmony_ci| sh    | number                                   | No | Target height to crop the source image.<br>Default unit: vp<br>Default value: **0** |
2633e41f4b71Sopenharmony_ci| dx    | number                                   | Yes | X coordinate of the upper left corner of the drawing area on the canvas.<br>Default unit: vp<br>Default value: **0** |
2634e41f4b71Sopenharmony_ci| dy    | number                                   | Yes | Y coordinate of the upper left corner of the drawing area on the canvas.<br>Default unit: vp<br>Default value: **0** |
2635e41f4b71Sopenharmony_ci| dw    | number                                   | No | Width of the drawing area. If the width of the drawing area is different from that of the cropped image, the latter will be stretched or compressed to the former.<br>Default unit: vp<br>Default value: **0** |
2636e41f4b71Sopenharmony_ci| dh    | number                                   | No | Height of the drawing area. If the height of the drawing area is different from that of the cropped image, the latter will be stretched or compressed to the former.<br>Default unit: vp<br>Default value: **0** |
2637e41f4b71Sopenharmony_ci
2638e41f4b71Sopenharmony_ci
2639e41f4b71Sopenharmony_ci**Example**
2640e41f4b71Sopenharmony_ci
2641e41f4b71Sopenharmony_ci  ```ts
2642e41f4b71Sopenharmony_ci  // xxx.ets
2643e41f4b71Sopenharmony_ci  @Entry
2644e41f4b71Sopenharmony_ci  @Component
2645e41f4b71Sopenharmony_ci  struct ImageExample {
2646e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
2647e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
2648e41f4b71Sopenharmony_ci    private img:ImageBitmap = new ImageBitmap("common/images/example.jpg")
2649e41f4b71Sopenharmony_ci
2650e41f4b71Sopenharmony_ci    build() {
2651e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
2652e41f4b71Sopenharmony_ci        Canvas(this.context)
2653e41f4b71Sopenharmony_ci          .width('100%')
2654e41f4b71Sopenharmony_ci          .height('100%')
2655e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
2656e41f4b71Sopenharmony_ci          .onReady(() =>{
2657e41f4b71Sopenharmony_ci            this.context.drawImage( this.img,0,0,500,500,0,0,400,200)
2658e41f4b71Sopenharmony_ci        })
2659e41f4b71Sopenharmony_ci      }
2660e41f4b71Sopenharmony_ci      .width('100%')
2661e41f4b71Sopenharmony_ci      .height('100%')
2662e41f4b71Sopenharmony_ci    }
2663e41f4b71Sopenharmony_ci  }
2664e41f4b71Sopenharmony_ci  ```
2665e41f4b71Sopenharmony_ci
2666e41f4b71Sopenharmony_ci  ![en-us_image_0000001194352442](figures/en-us_image_0000001194352442.png)
2667e41f4b71Sopenharmony_ci
2668e41f4b71Sopenharmony_ci
2669e41f4b71Sopenharmony_ci### createImageData
2670e41f4b71Sopenharmony_ci
2671e41f4b71Sopenharmony_cicreateImageData(sw: number, sh: number): ImageData
2672e41f4b71Sopenharmony_ci
2673e41f4b71Sopenharmony_ciCreates a blank **ImageData** object of a specified size. For details, see [ImageData](ts-components-canvas-imagedata.md). The example is the same as that of **putImageData**.
2674e41f4b71Sopenharmony_ci
2675e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
2676e41f4b71Sopenharmony_ci
2677e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2678e41f4b71Sopenharmony_ci
2679e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2680e41f4b71Sopenharmony_ci
2681e41f4b71Sopenharmony_ci**Parameters**
2682e41f4b71Sopenharmony_ci
2683e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory  | Description |
2684e41f4b71Sopenharmony_ci| ---- | ------ | ---- | ------------- |
2685e41f4b71Sopenharmony_ci| sw   | number | Yes | Width of the **ImageData** object.<br>Default unit: vp<br>Default value: **0** |
2686e41f4b71Sopenharmony_ci| sh   | number | Yes | Height of the **ImageData** object.<br>Default unit: vp<br>Default value: **0** |
2687e41f4b71Sopenharmony_ci
2688e41f4b71Sopenharmony_ci
2689e41f4b71Sopenharmony_cicreateImageData(imageData: ImageData): ImageData
2690e41f4b71Sopenharmony_ci
2691e41f4b71Sopenharmony_ciCreates an [ImageData](ts-components-canvas-imagedata.md) object with the same width and height of an existing **ImageData** object. The example is the same as that of **putImageData**.
2692e41f4b71Sopenharmony_ci
2693e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
2694e41f4b71Sopenharmony_ci
2695e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2696e41f4b71Sopenharmony_ci
2697e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2698e41f4b71Sopenharmony_ci
2699e41f4b71Sopenharmony_ci**Parameters**
2700e41f4b71Sopenharmony_ci
2701e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description |
2702e41f4b71Sopenharmony_ci| --------- | ---------------------------------------- | ---- | ----------------- |
2703e41f4b71Sopenharmony_ci| imagedata | [ImageData](ts-components-canvas-imagedata.md) | Yes | Existing **ImageData** object. |
2704e41f4b71Sopenharmony_ci
2705e41f4b71Sopenharmony_ci  **Return value**
2706e41f4b71Sopenharmony_ci
2707e41f4b71Sopenharmony_ci| Type                                      | Description            |
2708e41f4b71Sopenharmony_ci| ---------------------------------------- | -------------- |
2709e41f4b71Sopenharmony_ci| [ImageData](ts-components-canvas-imagedata.md) | New **ImageData** object. |
2710e41f4b71Sopenharmony_ci
2711e41f4b71Sopenharmony_ci
2712e41f4b71Sopenharmony_ci### getPixelMap
2713e41f4b71Sopenharmony_ci
2714e41f4b71Sopenharmony_cigetPixelMap(sx: number, sy: number, sw: number, sh: number): PixelMap
2715e41f4b71Sopenharmony_ci
2716e41f4b71Sopenharmony_ciObtains the [PixelMap](../../apis-image-kit/js-apis-image.md#pixelmap7) object created with the pixels within the specified area on the canvas. This API involves time-consuming memory copy. Therefore, avoid frequent calls to it.
2717e41f4b71Sopenharmony_ci
2718e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2719e41f4b71Sopenharmony_ci
2720e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2721e41f4b71Sopenharmony_ci
2722e41f4b71Sopenharmony_ci**Parameters**
2723e41f4b71Sopenharmony_ci
2724e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory | Description |
2725e41f4b71Sopenharmony_ci| ---- | ------ | ---- | --------------- |
2726e41f4b71Sopenharmony_ci| sx   | number | Yes | X coordinate of the upper left corner of the output area.<br>Default unit: vp<br>Default value: **0** |
2727e41f4b71Sopenharmony_ci| sy   | number | Yes | Y coordinate of the upper left corner of the output area.<br>Default unit: vp<br>Default value: **0** |
2728e41f4b71Sopenharmony_ci| sw   | number | Yes | Width of the output area.<br>Default unit: vp<br>Default value: **0** |
2729e41f4b71Sopenharmony_ci| sh   | number | Yes | Height of the output area.<br>Default unit: vp<br>Default value: **0** |
2730e41f4b71Sopenharmony_ci
2731e41f4b71Sopenharmony_ci**Return value**
2732e41f4b71Sopenharmony_ci
2733e41f4b71Sopenharmony_ci| Type                                      | Description           |
2734e41f4b71Sopenharmony_ci| ---------------------------------------- | ------------- |
2735e41f4b71Sopenharmony_ci| [PixelMap](../../apis-image-kit/js-apis-image.md#pixelmap7) | **PixelMap** object. |
2736e41f4b71Sopenharmony_ci
2737e41f4b71Sopenharmony_ci**Example**
2738e41f4b71Sopenharmony_ci
2739e41f4b71Sopenharmony_ci  ```ts
2740e41f4b71Sopenharmony_ci  // xxx.ets
2741e41f4b71Sopenharmony_ci  @Entry
2742e41f4b71Sopenharmony_ci  @Component
2743e41f4b71Sopenharmony_ci  struct GetPixelMap {
2744e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
2745e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
2746e41f4b71Sopenharmony_ci    private img:ImageBitmap = new ImageBitmap("/images/star.png")
2747e41f4b71Sopenharmony_ci
2748e41f4b71Sopenharmony_ci    build() {
2749e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
2750e41f4b71Sopenharmony_ci        Canvas(this.context)
2751e41f4b71Sopenharmony_ci          .width('100%')
2752e41f4b71Sopenharmony_ci          .height('100%')
2753e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
2754e41f4b71Sopenharmony_ci          .onReady(() =>{
2755e41f4b71Sopenharmony_ci            this.context.drawImage(this.img,0,0,130,130)
2756e41f4b71Sopenharmony_ci            let pixelmap = this.context.getPixelMap(50,50,130,130)
2757e41f4b71Sopenharmony_ci            this.context.drawImage(pixelmap,150,150)
2758e41f4b71Sopenharmony_ci          })
2759e41f4b71Sopenharmony_ci      }
2760e41f4b71Sopenharmony_ci      .width('100%')
2761e41f4b71Sopenharmony_ci      .height('100%')
2762e41f4b71Sopenharmony_ci    }
2763e41f4b71Sopenharmony_ci  } 
2764e41f4b71Sopenharmony_ci  ```
2765e41f4b71Sopenharmony_ci
2766e41f4b71Sopenharmony_ci  ![en-us_image_000000127777782](figures/en-us_image_000000127777782.jpeg)
2767e41f4b71Sopenharmony_ci
2768e41f4b71Sopenharmony_ci### getImageData
2769e41f4b71Sopenharmony_ci
2770e41f4b71Sopenharmony_cigetImageData(sx: number, sy: number, sw: number, sh: number): ImageData
2771e41f4b71Sopenharmony_ci
2772e41f4b71Sopenharmony_ciObtains the [ImageData](ts-components-canvas-imagedata.md) object created with the pixels within the specified area on the canvas. This API involves time-consuming memory copy. Therefore, avoid frequent calls to it.
2773e41f4b71Sopenharmony_ci
2774e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
2775e41f4b71Sopenharmony_ci
2776e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2777e41f4b71Sopenharmony_ci
2778e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2779e41f4b71Sopenharmony_ci
2780e41f4b71Sopenharmony_ci**Parameters**
2781e41f4b71Sopenharmony_ci
2782e41f4b71Sopenharmony_ci| Name | Type | Mandatory  | Description |
2783e41f4b71Sopenharmony_ci| ---- | ------ | ---- | --------------- |
2784e41f4b71Sopenharmony_ci| sx   | number | Yes | X coordinate of the upper left corner of the output area.<br>Default unit: vp<br>Default value: **0** |
2785e41f4b71Sopenharmony_ci| sy   | number | Yes | Y coordinate of the upper left corner of the output area.<br>Default unit: vp<br>Default value: **0** |
2786e41f4b71Sopenharmony_ci| sw   | number | Yes | Width of the output area.<br>Default unit: vp<br>Default value: **0** |
2787e41f4b71Sopenharmony_ci| sh   | number | Yes | Height of the output area.<br>Default unit: vp<br>Default value: **0** |
2788e41f4b71Sopenharmony_ci
2789e41f4b71Sopenharmony_ci  **Return value**
2790e41f4b71Sopenharmony_ci
2791e41f4b71Sopenharmony_ci| Type                                      | Description            |
2792e41f4b71Sopenharmony_ci| ---------------------------------------- | -------------- |
2793e41f4b71Sopenharmony_ci| [ImageData](ts-components-canvas-imagedata.md) | New **ImageData** object. |
2794e41f4b71Sopenharmony_ci
2795e41f4b71Sopenharmony_ci
2796e41f4b71Sopenharmony_ci**Example**
2797e41f4b71Sopenharmony_ci
2798e41f4b71Sopenharmony_ci  ```ts
2799e41f4b71Sopenharmony_ci  // xxx.ets
2800e41f4b71Sopenharmony_ci  @Entry
2801e41f4b71Sopenharmony_ci  @Component
2802e41f4b71Sopenharmony_ci  struct GetImageData {
2803e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
2804e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
2805e41f4b71Sopenharmony_ci    private img:ImageBitmap = new ImageBitmap("/common/images/1234.png")
2806e41f4b71Sopenharmony_ci
2807e41f4b71Sopenharmony_ci    build() {
2808e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
2809e41f4b71Sopenharmony_ci        Canvas(this.context)
2810e41f4b71Sopenharmony_ci          .width('100%')
2811e41f4b71Sopenharmony_ci          .height('100%')
2812e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
2813e41f4b71Sopenharmony_ci          .onReady(() =>{
2814e41f4b71Sopenharmony_ci            this.context.drawImage(this.img,0,0,130,130)
2815e41f4b71Sopenharmony_ci            let imagedata = this.context.getImageData(50,50,130,130)
2816e41f4b71Sopenharmony_ci            this.context.putImageData(imagedata,150,150)
2817e41f4b71Sopenharmony_ci          })
2818e41f4b71Sopenharmony_ci      }
2819e41f4b71Sopenharmony_ci      .width('100%')
2820e41f4b71Sopenharmony_ci      .height('100%')
2821e41f4b71Sopenharmony_ci    }
2822e41f4b71Sopenharmony_ci  }
2823e41f4b71Sopenharmony_ci  ```
2824e41f4b71Sopenharmony_ci
2825e41f4b71Sopenharmony_ci  ![en-us_image_000000127777780](figures/en-us_image_000000127777780.png)
2826e41f4b71Sopenharmony_ci
2827e41f4b71Sopenharmony_ci
2828e41f4b71Sopenharmony_ci### putImageData
2829e41f4b71Sopenharmony_ci
2830e41f4b71Sopenharmony_ciputImageData(imageData: ImageData, dx: number | string, dy: number | string): void
2831e41f4b71Sopenharmony_ci
2832e41f4b71Sopenharmony_ciputImageData(imageData: ImageData, dx: number | string, dy: number | string, dirtyX: number | string, dirtyY: number | string, dirtyWidth: number | string, dirtyHeight: number | string): void
2833e41f4b71Sopenharmony_ci
2834e41f4b71Sopenharmony_ciPuts an **[ImageData](ts-components-canvas-imagedata.md)** object onto a rectangular area on the canvas.
2835e41f4b71Sopenharmony_ci
2836e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
2837e41f4b71Sopenharmony_ci
2838e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2839e41f4b71Sopenharmony_ci
2840e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2841e41f4b71Sopenharmony_ci
2842e41f4b71Sopenharmony_ci**Parameters**
2843e41f4b71Sopenharmony_ci
2844e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description |
2845e41f4b71Sopenharmony_ci| ----------- | ---------------------------------------- | ---- | ----------------------------- |
2846e41f4b71Sopenharmony_ci| imagedata   | [ImageData](ts-components-canvas-imagedata.md) | Yes   | **ImageData** object with pixels to put onto the canvas. |
2847e41f4b71Sopenharmony_ci| dx          | number \| string<sup>10+</sup> | Yes   | X-axis offset of the rectangular area on the canvas.<br>Default unit: vp<br>Default value: **0** |
2848e41f4b71Sopenharmony_ci| dy          | number \| string<sup>10+</sup> | Yes   | Y-axis offset of the rectangular area on the canvas.<br>Default unit: vp<br>Default value: **0** |
2849e41f4b71Sopenharmony_ci| dirtyX      | number \| string<sup>10+</sup> | No   | X-axis offset of the upper left corner of the rectangular area relative to that of the source image.<br>Default unit: vp<br>Default value: **0** |
2850e41f4b71Sopenharmony_ci| dirtyY      | number \| string<sup>10+</sup> | No   | Y-axis offset of the upper left corner of the rectangular area relative to that of the source image.<br>Default unit: vp<br>Default value: **0** |
2851e41f4b71Sopenharmony_ci| dirtyWidth  | number \| string<sup>10+</sup> | No   | Width of the rectangular area to crop the source image.<br>Default unit: vp<br>Default value: width of the **ImageData** object |
2852e41f4b71Sopenharmony_ci| dirtyHeight | number \| string<sup>10+</sup> | No   | Height of the rectangular area to crop the source image.<br>Default unit: vp<br>Default value: height of the **ImageData** object |
2853e41f4b71Sopenharmony_ci
2854e41f4b71Sopenharmony_ci**Example**
2855e41f4b71Sopenharmony_ci
2856e41f4b71Sopenharmony_ci  ```ts
2857e41f4b71Sopenharmony_ci  // xxx.ets
2858e41f4b71Sopenharmony_ci  @Entry
2859e41f4b71Sopenharmony_ci  @Component
2860e41f4b71Sopenharmony_ci  struct PutImageData {
2861e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
2862e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
2863e41f4b71Sopenharmony_ci
2864e41f4b71Sopenharmony_ci    build() {
2865e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
2866e41f4b71Sopenharmony_ci        Canvas(this.context)
2867e41f4b71Sopenharmony_ci          .width('100%')
2868e41f4b71Sopenharmony_ci          .height('100%')
2869e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
2870e41f4b71Sopenharmony_ci          .onReady(() =>{
2871e41f4b71Sopenharmony_ci            let imageDataNum = this.context.createImageData(100, 100)
2872e41f4b71Sopenharmony_ci            for (let i = 0; i < imageDataNum.data.length; i += 4) {
2873e41f4b71Sopenharmony_ci              imageDataNum.data[i + 0] = 255
2874e41f4b71Sopenharmony_ci              imageDataNum.data[i + 1] = 0
2875e41f4b71Sopenharmony_ci              imageDataNum.data[i + 2] = 255
2876e41f4b71Sopenharmony_ci              imageDataNum.data[i + 3] = 255
2877e41f4b71Sopenharmony_ci            }
2878e41f4b71Sopenharmony_ci            let imageData = this.context.createImageData(imageDataNum)
2879e41f4b71Sopenharmony_ci            this.context.putImageData(imageData, 10, 10)
2880e41f4b71Sopenharmony_ci          })
2881e41f4b71Sopenharmony_ci      }
2882e41f4b71Sopenharmony_ci      .width('100%')
2883e41f4b71Sopenharmony_ci      .height('100%')
2884e41f4b71Sopenharmony_ci    }
2885e41f4b71Sopenharmony_ci  }
2886e41f4b71Sopenharmony_ci  ```
2887e41f4b71Sopenharmony_ci
2888e41f4b71Sopenharmony_ci  ![en-us_image_0000001238952387](figures/en-us_image_0000001238952387.png)
2889e41f4b71Sopenharmony_ci
2890e41f4b71Sopenharmony_ci
2891e41f4b71Sopenharmony_ci### setLineDash
2892e41f4b71Sopenharmony_ci
2893e41f4b71Sopenharmony_cisetLineDash(segments: number[]): void
2894e41f4b71Sopenharmony_ci
2895e41f4b71Sopenharmony_ciSets the dash line style.
2896e41f4b71Sopenharmony_ci
2897e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
2898e41f4b71Sopenharmony_ci
2899e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2900e41f4b71Sopenharmony_ci
2901e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2902e41f4b71Sopenharmony_ci
2903e41f4b71Sopenharmony_ci**Parameters** 
2904e41f4b71Sopenharmony_ci
2905e41f4b71Sopenharmony_ci| Name     | Type     | Mandatory | Description |
2906e41f4b71Sopenharmony_ci| -------- | -------- | ------- | ------------ |
2907e41f4b71Sopenharmony_ci| segments | number[] | Yes | An array of numbers that specify distances to alternately draw a line and a gap.<br>Default unit: vp |
2908e41f4b71Sopenharmony_ci
2909e41f4b71Sopenharmony_ci**Example** 
2910e41f4b71Sopenharmony_ci
2911e41f4b71Sopenharmony_ci  ```ts
2912e41f4b71Sopenharmony_ci  // xxx.ets
2913e41f4b71Sopenharmony_ci  @Entry
2914e41f4b71Sopenharmony_ci  @Component
2915e41f4b71Sopenharmony_ci  struct SetLineDash {
2916e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
2917e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
2918e41f4b71Sopenharmony_ci    
2919e41f4b71Sopenharmony_ci    build() {
2920e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
2921e41f4b71Sopenharmony_ci        Canvas(this.context)
2922e41f4b71Sopenharmony_ci          .width('100%')
2923e41f4b71Sopenharmony_ci          .height('100%')
2924e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
2925e41f4b71Sopenharmony_ci          .onReady(() =>{
2926e41f4b71Sopenharmony_ci            this.context.arc(100, 75, 50, 0, 6.28)
2927e41f4b71Sopenharmony_ci            this.context.setLineDash([10,20])
2928e41f4b71Sopenharmony_ci            this.context.stroke()
2929e41f4b71Sopenharmony_ci          })
2930e41f4b71Sopenharmony_ci      }
2931e41f4b71Sopenharmony_ci      .width('100%')
2932e41f4b71Sopenharmony_ci      .height('100%')
2933e41f4b71Sopenharmony_ci    }
2934e41f4b71Sopenharmony_ci  }
2935e41f4b71Sopenharmony_ci  ```
2936e41f4b71Sopenharmony_ci
2937e41f4b71Sopenharmony_ci  ![en-us_image_000000127777771](figures/en-us_image_000000127777771.png)
2938e41f4b71Sopenharmony_ci
2939e41f4b71Sopenharmony_ci
2940e41f4b71Sopenharmony_ci### getLineDash
2941e41f4b71Sopenharmony_ci
2942e41f4b71Sopenharmony_cigetLineDash(): number[]
2943e41f4b71Sopenharmony_ci
2944e41f4b71Sopenharmony_ciObtains the dash line style.
2945e41f4b71Sopenharmony_ci
2946e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
2947e41f4b71Sopenharmony_ci
2948e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2949e41f4b71Sopenharmony_ci
2950e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2951e41f4b71Sopenharmony_ci
2952e41f4b71Sopenharmony_ci**Return value** 
2953e41f4b71Sopenharmony_ci
2954e41f4b71Sopenharmony_ci| Type      | Description                      |
2955e41f4b71Sopenharmony_ci| -------- | ------------------------ |
2956e41f4b71Sopenharmony_ci| number[] | Interval of alternate line segments and the length of spacing.<br>Default unit: vp |
2957e41f4b71Sopenharmony_ci
2958e41f4b71Sopenharmony_ci
2959e41f4b71Sopenharmony_ci**Example** 
2960e41f4b71Sopenharmony_ci
2961e41f4b71Sopenharmony_ci  ```ts
2962e41f4b71Sopenharmony_ci  // xxx.ets
2963e41f4b71Sopenharmony_ci  @Entry
2964e41f4b71Sopenharmony_ci  @Component
2965e41f4b71Sopenharmony_ci  struct CanvasGetLineDash {
2966e41f4b71Sopenharmony_ci    @State message: string = 'Hello World'
2967e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
2968e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
2969e41f4b71Sopenharmony_ci
2970e41f4b71Sopenharmony_ci    build() {
2971e41f4b71Sopenharmony_ci      Row() {
2972e41f4b71Sopenharmony_ci        Column() {
2973e41f4b71Sopenharmony_ci          Text(this.message)
2974e41f4b71Sopenharmony_ci            .fontSize(50)
2975e41f4b71Sopenharmony_ci            .fontWeight(FontWeight.Bold)
2976e41f4b71Sopenharmony_ci            .onClick(()=>{
2977e41f4b71Sopenharmony_ci              console.error('before getlinedash clicked')
2978e41f4b71Sopenharmony_ci              let res = this.context.getLineDash()
2979e41f4b71Sopenharmony_ci              console.error(JSON.stringify(res))
2980e41f4b71Sopenharmony_ci            })
2981e41f4b71Sopenharmony_ci          Canvas(this.context)
2982e41f4b71Sopenharmony_ci            .width('100%')
2983e41f4b71Sopenharmony_ci            .height('100%')
2984e41f4b71Sopenharmony_ci            .backgroundColor('#ffff00')
2985e41f4b71Sopenharmony_ci            .onReady(() => {
2986e41f4b71Sopenharmony_ci              this.context.arc(100, 75, 50, 0, 6.28)
2987e41f4b71Sopenharmony_ci              this.context.setLineDash([10,20])
2988e41f4b71Sopenharmony_ci              this.context.stroke()
2989e41f4b71Sopenharmony_ci            })
2990e41f4b71Sopenharmony_ci        }
2991e41f4b71Sopenharmony_ci        .width('100%')
2992e41f4b71Sopenharmony_ci      }
2993e41f4b71Sopenharmony_ci      .height('100%')
2994e41f4b71Sopenharmony_ci    }
2995e41f4b71Sopenharmony_ci  }
2996e41f4b71Sopenharmony_ci  ```
2997e41f4b71Sopenharmony_ci![en-us_image_000000127777778](figures/en-us_image_000000127777778.png) 
2998e41f4b71Sopenharmony_ci
2999e41f4b71Sopenharmony_ci
3000e41f4b71Sopenharmony_ci### transferFromImageBitmap
3001e41f4b71Sopenharmony_ci
3002e41f4b71Sopenharmony_citransferFromImageBitmap(bitmap: ImageBitmap): void
3003e41f4b71Sopenharmony_ci
3004e41f4b71Sopenharmony_ciDisplays the specified **ImageBitmap** object.
3005e41f4b71Sopenharmony_ci
3006e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
3007e41f4b71Sopenharmony_ci
3008e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3009e41f4b71Sopenharmony_ci
3010e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3011e41f4b71Sopenharmony_ci
3012e41f4b71Sopenharmony_ci**Parameters** 
3013e41f4b71Sopenharmony_ci
3014e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description |
3015e41f4b71Sopenharmony_ci| ------ | ----------------------- | ----------------- | ------------------ |
3016e41f4b71Sopenharmony_ci| bitmap | [ImageBitmap](ts-components-canvas-imagebitmap.md)  | Yes | **ImageBitmap** object to display. |
3017e41f4b71Sopenharmony_ci
3018e41f4b71Sopenharmony_ci**Example** 
3019e41f4b71Sopenharmony_ci
3020e41f4b71Sopenharmony_ci  ```ts
3021e41f4b71Sopenharmony_ci  // xxx.ets
3022e41f4b71Sopenharmony_ci  @Entry
3023e41f4b71Sopenharmony_ci  @Component
3024e41f4b71Sopenharmony_ci  struct TransferFromImageBitmap {
3025e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
3026e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
3027e41f4b71Sopenharmony_ci    private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings)
3028e41f4b71Sopenharmony_ci
3029e41f4b71Sopenharmony_ci    build() {
3030e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
3031e41f4b71Sopenharmony_ci        Canvas(this.context)
3032e41f4b71Sopenharmony_ci          .width('100%')
3033e41f4b71Sopenharmony_ci          .height('100%')
3034e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
3035e41f4b71Sopenharmony_ci          .onReady(() =>{
3036e41f4b71Sopenharmony_ci            let imageData = this.offContext.createImageData(100, 100)
3037e41f4b71Sopenharmony_ci            for (let i = 0; i < imageData.data.length; i += 4) {
3038e41f4b71Sopenharmony_ci              imageData.data[i + 0] = 255
3039e41f4b71Sopenharmony_ci              imageData.data[i + 1] = 0
3040e41f4b71Sopenharmony_ci              imageData.data[i + 2] = 255
3041e41f4b71Sopenharmony_ci              imageData.data[i + 3] = 255
3042e41f4b71Sopenharmony_ci            }
3043e41f4b71Sopenharmony_ci            this.offContext.putImageData(imageData, 10, 10)
3044e41f4b71Sopenharmony_ci            let image = this.offContext.transferToImageBitmap()
3045e41f4b71Sopenharmony_ci            this.context.transferFromImageBitmap(image)
3046e41f4b71Sopenharmony_ci          })
3047e41f4b71Sopenharmony_ci      }
3048e41f4b71Sopenharmony_ci      .width('100%')
3049e41f4b71Sopenharmony_ci      .height('100%')
3050e41f4b71Sopenharmony_ci    }
3051e41f4b71Sopenharmony_ci  }
3052e41f4b71Sopenharmony_ci  ```
3053e41f4b71Sopenharmony_ci  ![en-us_image_0000001238952387](figures/en-us_image_0000001238952387.png)  
3054e41f4b71Sopenharmony_ci
3055e41f4b71Sopenharmony_ci
3056e41f4b71Sopenharmony_ci### toDataURL
3057e41f4b71Sopenharmony_ci
3058e41f4b71Sopenharmony_citoDataURL(type?: string, quality?: any): string
3059e41f4b71Sopenharmony_ci
3060e41f4b71Sopenharmony_ciGenerates a URL containing image display information.
3061e41f4b71Sopenharmony_ci
3062e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
3063e41f4b71Sopenharmony_ci
3064e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3065e41f4b71Sopenharmony_ci
3066e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3067e41f4b71Sopenharmony_ci
3068e41f4b71Sopenharmony_ci**Parameters** 
3069e41f4b71Sopenharmony_ci
3070e41f4b71Sopenharmony_ci| Name    | Type  | Mandatory | Description |
3071e41f4b71Sopenharmony_ci| ------- | ------ | ---- | ---------------------------------------- |
3072e41f4b71Sopenharmony_ci| type    | string | No | Image format. The default value is **image/png**.           |
3073e41f4b71Sopenharmony_ci| quality | any | No | Image quality, which ranges from 0 to 1, when the image format is **image/jpeg** or **image/webp**. If the set value is beyond the value range, the default value **0.92** is used. |
3074e41f4b71Sopenharmony_ci
3075e41f4b71Sopenharmony_ci**Return value** 
3076e41f4b71Sopenharmony_ci
3077e41f4b71Sopenharmony_ci| Type    | Description       |
3078e41f4b71Sopenharmony_ci| ------ | --------- |
3079e41f4b71Sopenharmony_ci| string | Image URL. |
3080e41f4b71Sopenharmony_ci
3081e41f4b71Sopenharmony_ci**Example**
3082e41f4b71Sopenharmony_ci
3083e41f4b71Sopenharmony_ci  ```ts
3084e41f4b71Sopenharmony_ci  // xxx.ets
3085e41f4b71Sopenharmony_ci  @Entry
3086e41f4b71Sopenharmony_ci  @Component
3087e41f4b71Sopenharmony_ci  struct CanvasExample {
3088e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
3089e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
3090e41f4b71Sopenharmony_ci    @State toDataURL: string = ""
3091e41f4b71Sopenharmony_ci
3092e41f4b71Sopenharmony_ci    build() {
3093e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
3094e41f4b71Sopenharmony_ci        Canvas(this.context)
3095e41f4b71Sopenharmony_ci          .width(100)
3096e41f4b71Sopenharmony_ci          .height(100)
3097e41f4b71Sopenharmony_ci          .onReady(() =>{
3098e41f4b71Sopenharmony_ci            this.context.fillStyle = "#00ff00"
3099e41f4b71Sopenharmony_ci            this.context.fillRect(0,0,100,100)
3100e41f4b71Sopenharmony_ci            this.toDataURL = this.context.toDataURL("image/png", 0.92)
3101e41f4b71Sopenharmony_ci          })
3102e41f4b71Sopenharmony_ci        Text(this.toDataURL)
3103e41f4b71Sopenharmony_ci      }
3104e41f4b71Sopenharmony_ci      .width('100%')
3105e41f4b71Sopenharmony_ci      .height('100%')
3106e41f4b71Sopenharmony_ci      .backgroundColor('#ffff00')
3107e41f4b71Sopenharmony_ci    }
3108e41f4b71Sopenharmony_ci  }
3109e41f4b71Sopenharmony_ci  ```
3110e41f4b71Sopenharmony_ci  ![en-us_image_0000001238952387](figures/en-us_image_0000001194192441.png)  
3111e41f4b71Sopenharmony_ci
3112e41f4b71Sopenharmony_ci
3113e41f4b71Sopenharmony_ci### restore
3114e41f4b71Sopenharmony_ci
3115e41f4b71Sopenharmony_cirestore(): void
3116e41f4b71Sopenharmony_ci
3117e41f4b71Sopenharmony_ciRestores the saved drawing context.
3118e41f4b71Sopenharmony_ci
3119e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
3120e41f4b71Sopenharmony_ci
3121e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3122e41f4b71Sopenharmony_ci
3123e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3124e41f4b71Sopenharmony_ci
3125e41f4b71Sopenharmony_ci**Example**
3126e41f4b71Sopenharmony_ci
3127e41f4b71Sopenharmony_ci  ```ts
3128e41f4b71Sopenharmony_ci  // xxx.ets
3129e41f4b71Sopenharmony_ci  @Entry
3130e41f4b71Sopenharmony_ci  @Component
3131e41f4b71Sopenharmony_ci  struct CanvasExample {
3132e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
3133e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
3134e41f4b71Sopenharmony_ci
3135e41f4b71Sopenharmony_ci    build() {
3136e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
3137e41f4b71Sopenharmony_ci        Canvas(this.context)
3138e41f4b71Sopenharmony_ci          .width('100%')
3139e41f4b71Sopenharmony_ci          .height('100%')
3140e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
3141e41f4b71Sopenharmony_ci          .onReady(() =>{
3142e41f4b71Sopenharmony_ci            this.context.save() // save the default state
3143e41f4b71Sopenharmony_ci            this.context.fillStyle = "#00ff00"
3144e41f4b71Sopenharmony_ci            this.context.fillRect(20, 20, 100, 100)
3145e41f4b71Sopenharmony_ci            this.context.restore() // restore to the default state
3146e41f4b71Sopenharmony_ci            this.context.fillRect(150, 75, 100, 100)
3147e41f4b71Sopenharmony_ci          })
3148e41f4b71Sopenharmony_ci      }
3149e41f4b71Sopenharmony_ci      .width('100%')
3150e41f4b71Sopenharmony_ci      .height('100%')
3151e41f4b71Sopenharmony_ci    }
3152e41f4b71Sopenharmony_ci  }
3153e41f4b71Sopenharmony_ci  ```
3154e41f4b71Sopenharmony_ci  ![en-us_image_000000127777781](figures/en-us_image_000000127777781.png)
3155e41f4b71Sopenharmony_ci
3156e41f4b71Sopenharmony_ci
3157e41f4b71Sopenharmony_ci### save
3158e41f4b71Sopenharmony_ci
3159e41f4b71Sopenharmony_cisave(): void
3160e41f4b71Sopenharmony_ci
3161e41f4b71Sopenharmony_ciSaves all states of the canvas in the stack. This API is usually called when the drawing state needs to be saved.
3162e41f4b71Sopenharmony_ci
3163e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
3164e41f4b71Sopenharmony_ci
3165e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3166e41f4b71Sopenharmony_ci
3167e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3168e41f4b71Sopenharmony_ci
3169e41f4b71Sopenharmony_ci**Example**
3170e41f4b71Sopenharmony_ci
3171e41f4b71Sopenharmony_ci  ```ts
3172e41f4b71Sopenharmony_ci  // xxx.ets
3173e41f4b71Sopenharmony_ci  @Entry
3174e41f4b71Sopenharmony_ci  @Component
3175e41f4b71Sopenharmony_ci  struct CanvasExample {
3176e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
3177e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
3178e41f4b71Sopenharmony_ci
3179e41f4b71Sopenharmony_ci    build() {
3180e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
3181e41f4b71Sopenharmony_ci        Canvas(this.context)
3182e41f4b71Sopenharmony_ci          .width('100%')
3183e41f4b71Sopenharmony_ci          .height('100%')
3184e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
3185e41f4b71Sopenharmony_ci          .onReady(() =>{
3186e41f4b71Sopenharmony_ci            this.context.save() // save the default state
3187e41f4b71Sopenharmony_ci            this.context.fillStyle = "#00ff00"
3188e41f4b71Sopenharmony_ci            this.context.fillRect(20, 20, 100, 100)
3189e41f4b71Sopenharmony_ci            this.context.restore() // restore to the default state
3190e41f4b71Sopenharmony_ci            this.context.fillRect(150, 75, 100, 100)
3191e41f4b71Sopenharmony_ci          })
3192e41f4b71Sopenharmony_ci      }
3193e41f4b71Sopenharmony_ci      .width('100%')
3194e41f4b71Sopenharmony_ci      .height('100%')
3195e41f4b71Sopenharmony_ci    }
3196e41f4b71Sopenharmony_ci  }
3197e41f4b71Sopenharmony_ci  ```
3198e41f4b71Sopenharmony_ci  ![en-us_image_000000127777781](figures/en-us_image_000000127777781.png)
3199e41f4b71Sopenharmony_ci
3200e41f4b71Sopenharmony_ci
3201e41f4b71Sopenharmony_ci### createLinearGradient
3202e41f4b71Sopenharmony_ci
3203e41f4b71Sopenharmony_cicreateLinearGradient(x0: number, y0: number, x1: number, y1: number): CanvasGradient
3204e41f4b71Sopenharmony_ci
3205e41f4b71Sopenharmony_ciCreates a linear gradient.
3206e41f4b71Sopenharmony_ci
3207e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
3208e41f4b71Sopenharmony_ci
3209e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3210e41f4b71Sopenharmony_ci
3211e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3212e41f4b71Sopenharmony_ci
3213e41f4b71Sopenharmony_ci**Parameters**
3214e41f4b71Sopenharmony_ci
3215e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory | Description  |
3216e41f4b71Sopenharmony_ci| ---- | ------ | ---- | -------- |
3217e41f4b71Sopenharmony_ci| x0   | number | Yes | X coordinate of the start point.<br>Default unit: vp<br>Default value: **0** |
3218e41f4b71Sopenharmony_ci| y0   | number | Yes | Y coordinate of the start point.<br>Default unit: vp<br>Default value: **0** |
3219e41f4b71Sopenharmony_ci| x1   | number | Yes | X coordinate of the end point.<br>Default unit: vp<br>Default value: **0** |
3220e41f4b71Sopenharmony_ci| y1   | number | Yes | Y coordinate of the end point.<br>Default unit: vp<br>Default value: **0** |
3221e41f4b71Sopenharmony_ci
3222e41f4b71Sopenharmony_ci**Return value** 
3223e41f4b71Sopenharmony_ci
3224e41f4b71Sopenharmony_ci| Type    | Description       |
3225e41f4b71Sopenharmony_ci| ------ | --------- |
3226e41f4b71Sopenharmony_ci| [CanvasGradient](ts-components-canvas-canvasgradient.md) | New **CanvasGradient** object used to create a gradient on the canvas. |
3227e41f4b71Sopenharmony_ci
3228e41f4b71Sopenharmony_ci**Example**
3229e41f4b71Sopenharmony_ci
3230e41f4b71Sopenharmony_ci  ```ts
3231e41f4b71Sopenharmony_ci  // xxx.ets
3232e41f4b71Sopenharmony_ci  @Entry
3233e41f4b71Sopenharmony_ci  @Component
3234e41f4b71Sopenharmony_ci  struct CreateLinearGradient {
3235e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
3236e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
3237e41f4b71Sopenharmony_ci    
3238e41f4b71Sopenharmony_ci    build() {
3239e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
3240e41f4b71Sopenharmony_ci        Canvas(this.context)
3241e41f4b71Sopenharmony_ci          .width('100%')
3242e41f4b71Sopenharmony_ci          .height('100%')
3243e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
3244e41f4b71Sopenharmony_ci          .onReady(() =>{
3245e41f4b71Sopenharmony_ci            let grad = this.context.createLinearGradient(50,0, 300,100)
3246e41f4b71Sopenharmony_ci            grad.addColorStop(0.0, '#ff0000')
3247e41f4b71Sopenharmony_ci            grad.addColorStop(0.5, '#ffffff')
3248e41f4b71Sopenharmony_ci            grad.addColorStop(1.0, '#00ff00')
3249e41f4b71Sopenharmony_ci            this.context.fillStyle = grad
3250e41f4b71Sopenharmony_ci            this.context.fillRect(0, 0, 400, 400)
3251e41f4b71Sopenharmony_ci          })
3252e41f4b71Sopenharmony_ci      }
3253e41f4b71Sopenharmony_ci      .width('100%')
3254e41f4b71Sopenharmony_ci      .height('100%')
3255e41f4b71Sopenharmony_ci    }
3256e41f4b71Sopenharmony_ci  }
3257e41f4b71Sopenharmony_ci  ```
3258e41f4b71Sopenharmony_ci
3259e41f4b71Sopenharmony_ci  ![en-us_image_0000001194032516](figures/en-us_image_0000001194032516.jpeg)
3260e41f4b71Sopenharmony_ci
3261e41f4b71Sopenharmony_ci
3262e41f4b71Sopenharmony_ci### createRadialGradient
3263e41f4b71Sopenharmony_ci
3264e41f4b71Sopenharmony_cicreateRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number, r1: number): CanvasGradient
3265e41f4b71Sopenharmony_ci
3266e41f4b71Sopenharmony_ciCreates a linear gradient.
3267e41f4b71Sopenharmony_ci
3268e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
3269e41f4b71Sopenharmony_ci
3270e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3271e41f4b71Sopenharmony_ci
3272e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3273e41f4b71Sopenharmony_ci
3274e41f4b71Sopenharmony_ci**Parameters**
3275e41f4b71Sopenharmony_ci
3276e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory  | Description   |
3277e41f4b71Sopenharmony_ci| ---- | ------ | ---- | ----------------- |
3278e41f4b71Sopenharmony_ci| x0   | number | Yes | X coordinate of the center of the start circle.<br>Default unit: vp<br>Default value: **0** |
3279e41f4b71Sopenharmony_ci| y0   | number | Yes | Y coordinate of the center of the start circle.<br>Default unit: vp<br>Default value: **0** |
3280e41f4b71Sopenharmony_ci| r0   | number | Yes | Radius of the start circle, which must be a non-negative finite number.<br>Default unit: vp<br>Default value: **0** |
3281e41f4b71Sopenharmony_ci| x1   | number | Yes | X coordinate of the center of the end circle.<br>Default unit: vp<br>Default value: **0** |
3282e41f4b71Sopenharmony_ci| y1   | number | Yes | Y coordinate of the center of the end circle.<br>Default unit: vp<br>Default value: **0** |
3283e41f4b71Sopenharmony_ci| r1   | number | Yes | Radius of the end circle, which must be a non-negative finite number.<br>Default unit: vp<br>Default value: **0** |
3284e41f4b71Sopenharmony_ci
3285e41f4b71Sopenharmony_ci**Return value** 
3286e41f4b71Sopenharmony_ci
3287e41f4b71Sopenharmony_ci| Type    | Description       |
3288e41f4b71Sopenharmony_ci| ------ | --------- |
3289e41f4b71Sopenharmony_ci| [CanvasGradient](ts-components-canvas-canvasgradient.md) | New **CanvasGradient** object used to create a gradient on the canvas. |
3290e41f4b71Sopenharmony_ci
3291e41f4b71Sopenharmony_ci**Example**
3292e41f4b71Sopenharmony_ci
3293e41f4b71Sopenharmony_ci  ```ts
3294e41f4b71Sopenharmony_ci  // xxx.ets
3295e41f4b71Sopenharmony_ci  @Entry
3296e41f4b71Sopenharmony_ci  @Component
3297e41f4b71Sopenharmony_ci  struct CreateRadialGradient {
3298e41f4b71Sopenharmony_ci    private settings: RenderingContextSettings = new RenderingContextSettings(true)
3299e41f4b71Sopenharmony_ci    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
3300e41f4b71Sopenharmony_ci    
3301e41f4b71Sopenharmony_ci    build() {
3302e41f4b71Sopenharmony_ci      Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
3303e41f4b71Sopenharmony_ci        Canvas(this.context)
3304e41f4b71Sopenharmony_ci          .width('100%')
3305e41f4b71Sopenharmony_ci          .height('100%')
3306e41f4b71Sopenharmony_ci          .backgroundColor('#ffff00')
3307e41f4b71Sopenharmony_ci          .onReady(() =>{
3308e41f4b71Sopenharmony_ci            let grad = this.context.createRadialGradient(200,200,50, 200,200,200)
3309e41f4b71Sopenharmony_ci            grad.addColorStop(0.0, '#ff0000')
3310e41f4b71Sopenharmony_ci            grad.addColorStop(0.5, '#ffffff')
3311e41f4b71Sopenharmony_ci            grad.addColorStop(1.0, '#00ff00')
3312e41f4b71Sopenharmony_ci            this.context.fillStyle = grad
3313e41f4b71Sopenharmony_ci            this.context.fillRect(0, 0, 440, 440)
3314e41f4b71Sopenharmony_ci          })
3315e41f4b71Sopenharmony_ci      }
3316e41f4b71Sopenharmony_ci      .width('100%')
3317e41f4b71Sopenharmony_ci      .height('100%')
3318e41f4b71Sopenharmony_ci    }
3319e41f4b71Sopenharmony_ci  }
3320e41f4b71Sopenharmony_ci  ```
3321e41f4b71Sopenharmony_ci
3322e41f4b71Sopenharmony_ci  ![en-us_image_0000001238952407](figures/en-us_image_0000001238952407.jpeg)
3323e41f4b71Sopenharmony_ci
3324e41f4b71Sopenharmony_ci### createConicGradient<sup>10+</sup>
3325e41f4b71Sopenharmony_ci
3326e41f4b71Sopenharmony_cicreateConicGradient(startAngle: number, x: number, y: number): CanvasGradient
3327e41f4b71Sopenharmony_ci
3328e41f4b71Sopenharmony_ciCreates a conic gradient.
3329e41f4b71Sopenharmony_ci
3330e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3331e41f4b71Sopenharmony_ci
3332e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3333e41f4b71Sopenharmony_ci
3334e41f4b71Sopenharmony_ci**Parameters**
3335e41f4b71Sopenharmony_ci
3336e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory | Description |
3337e41f4b71Sopenharmony_ci| ---------- | ------ | ---- | ----------------------------------- |
3338e41f4b71Sopenharmony_ci| startAngle | number | Yes   | Angle at which the gradient starts, in radians. The angle measurement starts horizontally from the right side of the center and moves clockwise.<br>Default value: **0** |
3339e41f4b71Sopenharmony_ci| x          | number | Yes   | X coordinate of the center of the conic gradient,<br>Default unit: vp<br>Default value: **0** |
3340e41f4b71Sopenharmony_ci| y          | number | Yes   | Y coordinate of the center of the conic gradient,<br>Default unit: vp<br>Default value: **0** |
3341e41f4b71Sopenharmony_ci
3342e41f4b71Sopenharmony_ci**Return value** 
3343e41f4b71Sopenharmony_ci
3344e41f4b71Sopenharmony_ci| Type    | Description       |
3345e41f4b71Sopenharmony_ci| ------ | --------- |
3346e41f4b71Sopenharmony_ci| [CanvasGradient](ts-components-canvas-canvasgradient.md) | New **CanvasGradient** object used to create a gradient on the canvas. |
3347e41f4b71Sopenharmony_ci
3348e41f4b71Sopenharmony_ci**Example**
3349e41f4b71Sopenharmony_ci
3350e41f4b71Sopenharmony_ci```ts
3351e41f4b71Sopenharmony_ci// xxx.ets
3352e41f4b71Sopenharmony_ci@Entry
3353e41f4b71Sopenharmony_ci@Component
3354e41f4b71Sopenharmony_cistruct CanvasExample {
3355e41f4b71Sopenharmony_ci  private settings: RenderingContextSettings = new RenderingContextSettings(true)
3356e41f4b71Sopenharmony_ci  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
3357e41f4b71Sopenharmony_ci
3358e41f4b71Sopenharmony_ci  build() {
3359e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
3360e41f4b71Sopenharmony_ci      Canvas(this.context)
3361e41f4b71Sopenharmony_ci        .width('100%')
3362e41f4b71Sopenharmony_ci        .height('100%')
3363e41f4b71Sopenharmony_ci        .backgroundColor('#ffffff')
3364e41f4b71Sopenharmony_ci        .onReady(() => {
3365e41f4b71Sopenharmony_ci          let grad = this.context.createConicGradient(0, 50, 80)
3366e41f4b71Sopenharmony_ci          grad.addColorStop(0.0, '#ff0000')
3367e41f4b71Sopenharmony_ci          grad.addColorStop(0.5, '#ffffff')
3368e41f4b71Sopenharmony_ci          grad.addColorStop(1.0, '#00ff00')
3369e41f4b71Sopenharmony_ci          this.context.fillStyle = grad
3370e41f4b71Sopenharmony_ci          this.context.fillRect(0, 30, 100, 100)
3371e41f4b71Sopenharmony_ci        })
3372e41f4b71Sopenharmony_ci    }
3373e41f4b71Sopenharmony_ci    .width('100%')
3374e41f4b71Sopenharmony_ci    .height('100%')
3375e41f4b71Sopenharmony_ci  }
3376e41f4b71Sopenharmony_ci}
3377e41f4b71Sopenharmony_ci```
3378e41f4b71Sopenharmony_ci
3379e41f4b71Sopenharmony_ci  ![en-us_image_0000001239032419](figures/en-us_image_0000001239032420.png)
3380e41f4b71Sopenharmony_ci
3381e41f4b71Sopenharmony_ci### startImageAnalyzer<sup>12+</sup>
3382e41f4b71Sopenharmony_ci
3383e41f4b71Sopenharmony_cistartImageAnalyzer(config: ImageAnalyzerConfig): Promise\<void>
3384e41f4b71Sopenharmony_ci
3385e41f4b71Sopenharmony_ciStarts AI image analysis in the given settings. Before calling this API, make sure the AI analyzer is [enabled](ts-components-canvas-canvas.md#enableanalyzer12).<br>Because the image frame used for analysis is the one captured when this API is called, pay attention to the invoking time of this API.<br>If this method is repeatedly called before the execution is complete, an error callback is triggered. For the sample code, see the code for **stopImageAnalyzer**.
3386e41f4b71Sopenharmony_ci
3387e41f4b71Sopenharmony_ci> **NOTE**
3388e41f4b71Sopenharmony_ci> 
3389e41f4b71Sopenharmony_ci> The type of the AI analyzer cannot be dynamically modified.
3390e41f4b71Sopenharmony_ci> When image changes are detected, the analysis result is automatically destroyed. You can call this API again to start analysis.
3391e41f4b71Sopenharmony_ci> This API depends on device capabilities. If it is called on an incompatible device, an error code is returned.
3392e41f4b71Sopenharmony_ci
3393e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3394e41f4b71Sopenharmony_ci
3395e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3396e41f4b71Sopenharmony_ci
3397e41f4b71Sopenharmony_ci**Parameters**
3398e41f4b71Sopenharmony_ci
3399e41f4b71Sopenharmony_ci| Name | Type     | Mandatory | Description                                                                  |
3400e41f4b71Sopenharmony_ci| ------ | --------- | ---- | ---------------------------------------------------------------------- |
3401e41f4b71Sopenharmony_ci| config   | [ImageAnalyzerConfig](ts-image-common.md#imageanalyzerconfig) | Yes  | Settings of the AI analyzer. |
3402e41f4b71Sopenharmony_ci
3403e41f4b71Sopenharmony_ci**Return value**
3404e41f4b71Sopenharmony_ci
3405e41f4b71Sopenharmony_ci| Type             | Description                                |
3406e41f4b71Sopenharmony_ci| ----------------- | ------------------------------------ |
3407e41f4b71Sopenharmony_ci| Promise\<void>  | Promise used to return the result. |
3408e41f4b71Sopenharmony_ci
3409e41f4b71Sopenharmony_ci**Error codes**
3410e41f4b71Sopenharmony_ci
3411e41f4b71Sopenharmony_ciFor details about the error codes, see [AI Analysis Error Codes](../errorcode-image-analyzer.md).
3412e41f4b71Sopenharmony_ci
3413e41f4b71Sopenharmony_ci| ID | Error Message                                     |
3414e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- |
3415e41f4b71Sopenharmony_ci| 110001 | AI analysis is unsupported.               |
3416e41f4b71Sopenharmony_ci| 110002 | AI analysis is ongoing.  |
3417e41f4b71Sopenharmony_ci
3418e41f4b71Sopenharmony_ci### stopImageAnalyzer<sup>12+</sup>
3419e41f4b71Sopenharmony_ci
3420e41f4b71Sopenharmony_cistopImageAnalyzer(): void
3421e41f4b71Sopenharmony_ci
3422e41f4b71Sopenharmony_ciStops AI image analysis. The content displayed by the AI analyzer will be destroyed.
3423e41f4b71Sopenharmony_ci
3424e41f4b71Sopenharmony_ci> **NOTE**
3425e41f4b71Sopenharmony_ci> 
3426e41f4b71Sopenharmony_ci> If this API is called when the **startImageAnalyzer** API has not yet returned any result, an error is reported.
3427e41f4b71Sopenharmony_ci> This feature depends on device capabilities.
3428e41f4b71Sopenharmony_ci
3429e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3430e41f4b71Sopenharmony_ci
3431e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3432e41f4b71Sopenharmony_ci
3433e41f4b71Sopenharmony_ci**Example**
3434e41f4b71Sopenharmony_ci
3435e41f4b71Sopenharmony_ci```ts
3436e41f4b71Sopenharmony_ci// xxx.ets
3437e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3438e41f4b71Sopenharmony_ci
3439e41f4b71Sopenharmony_ci@Entry
3440e41f4b71Sopenharmony_ci@Component
3441e41f4b71Sopenharmony_cistruct ImageAnalyzerExample {
3442e41f4b71Sopenharmony_ci  private settings: RenderingContextSettings = new RenderingContextSettings(true)
3443e41f4b71Sopenharmony_ci  private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)
3444e41f4b71Sopenharmony_ci  private config: ImageAnalyzerConfig = {
3445e41f4b71Sopenharmony_ci    types: [ImageAnalyzerType.SUBJECT, ImageAnalyzerType.TEXT]
3446e41f4b71Sopenharmony_ci  }
3447e41f4b71Sopenharmony_ci  private img = new ImageBitmap('page/common/test.jpg')
3448e41f4b71Sopenharmony_ci  private aiController: ImageAnalyzerController = new ImageAnalyzerController()
3449e41f4b71Sopenharmony_ci  private options: ImageAIOptions = {
3450e41f4b71Sopenharmony_ci    types: [ImageAnalyzerType.SUBJECT, ImageAnalyzerType.TEXT],
3451e41f4b71Sopenharmony_ci    aiController: this.aiController
3452e41f4b71Sopenharmony_ci  }
3453e41f4b71Sopenharmony_ci
3454e41f4b71Sopenharmony_ci  build() {
3455e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
3456e41f4b71Sopenharmony_ci      Button('start')
3457e41f4b71Sopenharmony_ci        .width(80)
3458e41f4b71Sopenharmony_ci        .height(80)
3459e41f4b71Sopenharmony_ci        .onClick(() => {
3460e41f4b71Sopenharmony_ci          this.context.startImageAnalyzer(this.config)
3461e41f4b71Sopenharmony_ci            .then(() => {
3462e41f4b71Sopenharmony_ci              console.log("analysis complete")
3463e41f4b71Sopenharmony_ci            })
3464e41f4b71Sopenharmony_ci            .catch((error: BusinessError) => {
3465e41f4b71Sopenharmony_ci              console.log("error code: " + error.code)
3466e41f4b71Sopenharmony_ci            })
3467e41f4b71Sopenharmony_ci        })
3468e41f4b71Sopenharmony_ci      Button('stop')
3469e41f4b71Sopenharmony_ci        .width(80)
3470e41f4b71Sopenharmony_ci        .height(80)
3471e41f4b71Sopenharmony_ci        .onClick(() => {
3472e41f4b71Sopenharmony_ci          this.context.stopImageAnalyzer()
3473e41f4b71Sopenharmony_ci        })
3474e41f4b71Sopenharmony_ci      Button('getTypes')
3475e41f4b71Sopenharmony_ci        .width(80)
3476e41f4b71Sopenharmony_ci        .height(80)
3477e41f4b71Sopenharmony_ci        .onClick(() => {
3478e41f4b71Sopenharmony_ci          this.aiController.getImageAnalyzerSupportTypes()
3479e41f4b71Sopenharmony_ci        })
3480e41f4b71Sopenharmony_ci      Canvas(this.context, this.options)
3481e41f4b71Sopenharmony_ci        .width(200)
3482e41f4b71Sopenharmony_ci        .height(200)
3483e41f4b71Sopenharmony_ci        .enableAnalyzer(true)
3484e41f4b71Sopenharmony_ci        .onReady(() => {
3485e41f4b71Sopenharmony_ci          this.context.drawImage(this.img, 0, 0, 200, 200)
3486e41f4b71Sopenharmony_ci        })
3487e41f4b71Sopenharmony_ci    }
3488e41f4b71Sopenharmony_ci    .width('100%')
3489e41f4b71Sopenharmony_ci    .height('100%')
3490e41f4b71Sopenharmony_ci  }
3491e41f4b71Sopenharmony_ci}
3492e41f4b71Sopenharmony_ci```
3493e41f4b71Sopenharmony_ci
3494e41f4b71Sopenharmony_ci## CanvasDirection
3495e41f4b71Sopenharmony_ci
3496e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
3497e41f4b71Sopenharmony_ci
3498e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3499e41f4b71Sopenharmony_ci
3500e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3501e41f4b71Sopenharmony_ci
3502e41f4b71Sopenharmony_ci| Type     | Description                 |
3503e41f4b71Sopenharmony_ci| ------- | ------------------- |
3504e41f4b71Sopenharmony_ci| inherit | The text direction is inherited from the **\<canvas>** component. |
3505e41f4b71Sopenharmony_ci| ltr     | The text direction is from left to right.              |
3506e41f4b71Sopenharmony_ci| rtl     | The text direction is from right to left.              |
3507e41f4b71Sopenharmony_ci
3508e41f4b71Sopenharmony_ci## CanvasFillRule
3509e41f4b71Sopenharmony_ci
3510e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
3511e41f4b71Sopenharmony_ci
3512e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3513e41f4b71Sopenharmony_ci
3514e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3515e41f4b71Sopenharmony_ci
3516e41f4b71Sopenharmony_ci| Type     | Description   |
3517e41f4b71Sopenharmony_ci| ------- | ----- |
3518e41f4b71Sopenharmony_ci| evenodd | The inside part of a shape is determined based on whether the counting result is an odd number or not. |
3519e41f4b71Sopenharmony_ci| nonzero | The inside part of a shape is determined based on whether the counting result is zero or not. |
3520e41f4b71Sopenharmony_ci
3521e41f4b71Sopenharmony_ci## CanvasLineCap
3522e41f4b71Sopenharmony_ci
3523e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
3524e41f4b71Sopenharmony_ci
3525e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3526e41f4b71Sopenharmony_ci
3527e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3528e41f4b71Sopenharmony_ci
3529e41f4b71Sopenharmony_ci| Type     | Description                          |
3530e41f4b71Sopenharmony_ci| ------ | ----------------------------- |
3531e41f4b71Sopenharmony_ci| butt   | The ends of the line are squared off, and the line does not extend beyond its two endpoints.              |
3532e41f4b71Sopenharmony_ci| round  | The line is extended at the endpoints by a half circle whose diameter is equal to the line width.           |
3533e41f4b71Sopenharmony_ci| square | The line is extended at the endpoints by a rectangle whose width is equal to half the line width and height equal to the line width. |
3534e41f4b71Sopenharmony_ci
3535e41f4b71Sopenharmony_ci## CanvasLineJoin
3536e41f4b71Sopenharmony_ci
3537e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
3538e41f4b71Sopenharmony_ci
3539e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3540e41f4b71Sopenharmony_ci
3541e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3542e41f4b71Sopenharmony_ci
3543e41f4b71Sopenharmony_ci| Type     | Description                                      |
3544e41f4b71Sopenharmony_ci| ----- | ---------------------------------------- |
3545e41f4b71Sopenharmony_ci| bevel | The intersection is a triangle. The rectangular corner of each line is independent.            |
3546e41f4b71Sopenharmony_ci| miter | The intersection has a miter corner by extending the outside edges of the lines until they meet. You can view the effect of this attribute in **miterLimit**. |
3547e41f4b71Sopenharmony_ci| round | The intersection is a sector, whose radius at the rounded corner is equal to the line width.             |
3548e41f4b71Sopenharmony_ci
3549e41f4b71Sopenharmony_ci## CanvasTextAlign
3550e41f4b71Sopenharmony_ci
3551e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
3552e41f4b71Sopenharmony_ci
3553e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3554e41f4b71Sopenharmony_ci
3555e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3556e41f4b71Sopenharmony_ci
3557e41f4b71Sopenharmony_ci| Type     | Description          |
3558e41f4b71Sopenharmony_ci| ------ | ------------ |
3559e41f4b71Sopenharmony_ci| center | The text is center-aligned.     |
3560e41f4b71Sopenharmony_ci| start  | The text is aligned with the start bound. |
3561e41f4b71Sopenharmony_ci| end    | The text is aligned with the end bound. |
3562e41f4b71Sopenharmony_ci| left   | The text is left-aligned.      |
3563e41f4b71Sopenharmony_ci| right  | The text is right-aligned.      |
3564e41f4b71Sopenharmony_ci
3565e41f4b71Sopenharmony_ci## CanvasTextBaseline
3566e41f4b71Sopenharmony_ci
3567e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
3568e41f4b71Sopenharmony_ci
3569e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3570e41f4b71Sopenharmony_ci
3571e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3572e41f4b71Sopenharmony_ci
3573e41f4b71Sopenharmony_ci| Type     | Description                                      |
3574e41f4b71Sopenharmony_ci| ----------- | ---------------------------------------- |
3575e41f4b71Sopenharmony_ci| alphabetic  | The text baseline is the normal alphabetic baseline.                           |
3576e41f4b71Sopenharmony_ci| bottom      | The text baseline is at the bottom of the text bounding box. Its difference from the ideographic baseline is that the ideographic baseline does not consider letters in the next line. |
3577e41f4b71Sopenharmony_ci| hanging     | The text baseline is a hanging baseline over the text.                              |
3578e41f4b71Sopenharmony_ci| ideographic | The text baseline is the ideographic baseline. If a character exceeds the alphabetic baseline, the ideographic baseline is located at the bottom of the excessive character. |
3579e41f4b71Sopenharmony_ci| middle      | The text baseline is in the middle of the text bounding box.                            |
3580e41f4b71Sopenharmony_ci| top         | The text baseline is on the top of the text bounding box.                            |
3581e41f4b71Sopenharmony_ci
3582e41f4b71Sopenharmony_ci## ImageSmoothingQuality
3583e41f4b71Sopenharmony_ci
3584e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
3585e41f4b71Sopenharmony_ci
3586e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3587e41f4b71Sopenharmony_ci
3588e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3589e41f4b71Sopenharmony_ci
3590e41f4b71Sopenharmony_ci| Type     | Description  |
3591e41f4b71Sopenharmony_ci| ------ | ---- |
3592e41f4b71Sopenharmony_ci| low    | Low quality. |
3593e41f4b71Sopenharmony_ci| medium | Medium quality. |
3594e41f4b71Sopenharmony_ci| high   | High quality. |
3595e41f4b71Sopenharmony_ci
3596e41f4b71Sopenharmony_ci## TextMetrics
3597e41f4b71Sopenharmony_ci
3598e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
3599e41f4b71Sopenharmony_ci
3600e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3601e41f4b71Sopenharmony_ci
3602e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3603e41f4b71Sopenharmony_ci
3604e41f4b71Sopenharmony_ci| Name | Type | Read Only | Optional | Description |
3605e41f4b71Sopenharmony_ci| ---------- | -------------- | ------ | ---------------- | ------------------------ |
3606e41f4b71Sopenharmony_ci| width                    | number | Yes | No | Width of the text. Read-only. |
3607e41f4b71Sopenharmony_ci| height                   | number | Yes | No | Height of the text. Read-only. |
3608e41f4b71Sopenharmony_ci| actualBoundingBoxAscent  | number | Yes | No | Distance from the horizontal line specified by the [CanvasRenderingContext2D.textBaseline](#canvastextbaseline) attribute to the top of the bounding rectangle used to render the text. Read-only. |
3609e41f4b71Sopenharmony_ci| actualBoundingBoxDescent | number | Yes | No | Distance from the horizontal line specified by the [CanvasRenderingContext2D.textBaseline](#canvastextbaseline) attribute to the bottom of the bounding rectangle used to render the text. Read-only. |
3610e41f4b71Sopenharmony_ci| actualBoundingBoxLeft    | number | Yes | No | Distance parallel to the baseline from the alignment point determined by the [CanvasRenderingContext2D.textAlign](#canvastextalign) attribute to the left side of the bounding rectangle of the text. Read-only. |
3611e41f4b71Sopenharmony_ci| actualBoundingBoxRight   | number | Yes | No | Distance parallel to the baseline from the alignment point determined by the [CanvasRenderingContext2D.textAlign](#canvastextalign) attribute to the right side of the bounding rectangle of the text. Read-only. |
3612e41f4b71Sopenharmony_ci| alphabeticBaseline       | number | Yes | No | Distance from the horizontal line specified by the [CanvasRenderingContext2D.textBaseline](#canvastextbaseline) attribute to the alphabetic baseline of the line box. Read-only. |
3613e41f4b71Sopenharmony_ci| emHeightAscent           | number | Yes | No | Distance from the horizontal line specified by the [CanvasRenderingContext2D.textBaseline](#canvastextbaseline) attribute to the top of the em square in the line box. Read-only. |
3614e41f4b71Sopenharmony_ci| emHeightDescent          | number | Yes | No | Distance from the horizontal line specified by the [CanvasRenderingContext2D.textBaseline](#canvastextbaseline) attribute to the bottom of the em square in the line box. Read-only. |
3615e41f4b71Sopenharmony_ci| fontBoundingBoxAscent    | number | Yes | No | Distance from the horizontal line specified by the [CanvasRenderingContext2D.textBaseline](#canvastextbaseline) attribute to the top of the bounding rectangle of all the fonts used to render the text. Read-only. |
3616e41f4b71Sopenharmony_ci| fontBoundingBoxDescent   | number | Yes | No | Distance from the horizontal line specified by the [CanvasRenderingContext2D.textBaseline](#canvastextbaseline) attribute to the bottom of the bounding rectangle of all the fonts used to render the text. Read-only. |
3617e41f4b71Sopenharmony_ci| hangingBaseline          | number | Yes | No | Distance from the horizontal line specified by the [CanvasRenderingContext2D.textBaseline](#canvastextbaseline) attribute to the hanging baseline of the line box. Read-only. |
3618e41f4b71Sopenharmony_ci| ideographicBaseline      | number | Yes | No | Distance from the horizontal line specified by the [CanvasRenderingContext2D.textBaseline](#canvastextbaseline) attribute to the ideographic baseline of the line box. Read-only. |
3619