1e41f4b71Sopenharmony_ci# @ohos.graphics.drawing (Drawing)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe Drawing module provides basic drawing capabilities, such as drawing rectangles, circles, points, straight lines, custom paths, and fonts.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> - The initial APIs of this module are supported since API version 11. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci> - This module uses the physical pixel unit, px.
10e41f4b71Sopenharmony_ci>
11e41f4b71Sopenharmony_ci> - The module operates under a single-threaded model. The caller needs to manage thread safety and context state transitions.
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci## Modules to Import
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci```ts
16e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
17e41f4b71Sopenharmony_ci```
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci## BlendMode
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ciEnumerates the blend modes. In blend mode, each operation generates a new color from two colors (source color and target color). These operations are the same on the four channels (red, green, blue, and alpha). The operations for the alpha channel are used as examples.
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ciFor brevity, the following abbreviations are used:
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**s**: source. **d**: destination. **sa**: source alpha. **da**: destination alpha.
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ciThe following abbreviations are used in the calculation result:
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci**r**: The calculation methods of the four channels are the same. **ra**: Only the alpha channel is manipulated. **rc**: The other three color channels are manipulated.
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ciThe table below shows the effect of each blend mode, where the yellow rectangle is the source and the blue circle is the destination.
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci| Name       | Value  | Description                                                        | Diagram  |
36e41f4b71Sopenharmony_ci| ----------- | ---- | ------------------------------------------------------------ | -------- |
37e41f4b71Sopenharmony_ci| CLEAR       | 0    | Clear mode. r = 0.                                           | ![CLEAR](./figures/image_BlendMode_Clear.png) |
38e41f4b71Sopenharmony_ci| SRC         | 1    | r = s (The four channels of **result** are equal to the four channels of **source**, that is, the result is equal to the source.)| ![SRC](./figures/image_BlendMode_Src.png) |
39e41f4b71Sopenharmony_ci| DST         | 2    | r = d (The four channels of **result** are equal to the four channels of **destination**, that is, the result is equal to the destination.)| ![DST](./figures/image_BlendMode_Dst.png) |
40e41f4b71Sopenharmony_ci| SRC_OVER    | 3    | r = s + (1 - sa) * d                                         | ![SRC_OVER](./figures/image_BlendMode_SrcOver.png) |
41e41f4b71Sopenharmony_ci| DST_OVER    | 4    | r = d + (1 - da) * s                                         | ![DST_OVER](./figures/image_BlendMode_DstOver.png) |
42e41f4b71Sopenharmony_ci| SRC_IN      | 5    | r = s * da                                                   | ![SRC_IN](./figures/image_BlendMode_SrcIn.png) |
43e41f4b71Sopenharmony_ci| DST_IN      | 6    | r = d * sa                                                   | ![DST_IN](./figures/image_BlendMode_DstIn.png) |
44e41f4b71Sopenharmony_ci| SRC_OUT     | 7    | r = s * (1 - da)                                             | ![SRC_OUT](./figures/image_BlendMode_SrcOut.png) |
45e41f4b71Sopenharmony_ci| DST_OUT     | 8    | r = d * (1 - sa)                                             | ![DST_OUT](./figures/image_BlendMode_DstOut.png) |
46e41f4b71Sopenharmony_ci| SRC_ATOP    | 9    | r = s * da + d * (1 - sa)                                    | ![SRC_ATOP](./figures/image_BlendMode_SrcATop.png) |
47e41f4b71Sopenharmony_ci| DST_ATOP    | 10   | r = d * sa + s * (1 - da)                                    | ![DST_ATOP](./figures/image_BlendMode_DstATop.png) |
48e41f4b71Sopenharmony_ci| XOR         | 11   | r = s * (1 - da) + d * (1 - sa)                              | ![XOR](./figures/image_BlendMode_Xor.png) |
49e41f4b71Sopenharmony_ci| PLUS        | 12   | r = min(s + d, 1)                                            | ![PLUS](./figures/image_BlendMode_Plus.png) |
50e41f4b71Sopenharmony_ci| MODULATE    | 13   | r = s * d                                                    | ![MODULATE](./figures/image_BlendMode_Modulate.png) |
51e41f4b71Sopenharmony_ci| SCREEN      | 14   | Screen mode. r = s + d - s * d                                  | ![SCREEN](./figures/image_BlendMode_Screen.png) |
52e41f4b71Sopenharmony_ci| OVERLAY     | 15   | Overlay mode.                                                    | ![OVERLAY](./figures/image_BlendMode_Overlay.png) |
53e41f4b71Sopenharmony_ci| DARKEN      | 16   | Darken mode. rc = s + d - max(s * da, d * sa), ra = s + (1 - sa) * d | ![DARKEN](./figures/image_BlendMode_Darken.png) |
54e41f4b71Sopenharmony_ci| LIGHTEN     | 17   | Lighten mode. rc = rc = s + d - min(s * da, d * sa), ra = s + (1 - sa) * d | ![LIGHTEN](./figures/image_BlendMode_Lighten.png) |
55e41f4b71Sopenharmony_ci| COLOR_DODGE | 18   | Color dodge mode.                                                | ![COLOR_DODGE](./figures/image_BlendMode_ColorDodge.png) |
56e41f4b71Sopenharmony_ci| COLOR_BURN  | 19   | Color burn mode.                                                | ![COLOR_BURN](./figures/image_BlendMode_ColorBurn.png) |
57e41f4b71Sopenharmony_ci| HARD_LIGHT  | 20   | Hard light mode.                                                    | ![HARD_LIGHT](./figures/image_BlendMode_HardLight.png) |
58e41f4b71Sopenharmony_ci| SOFT_LIGHT  | 21   | Soft light mode.                                                    | ![SOFT_LIGHT](./figures/image_BlendMode_SoftLight.png) |
59e41f4b71Sopenharmony_ci| DIFFERENCE  | 22   | Difference mode. rc = s + d - 2 * (min(s * da, d * sa)), ra = s + (1 - sa) * d | ![DIFFERENCE](./figures/image_BlendMode_Difference.png) |
60e41f4b71Sopenharmony_ci| EXCLUSION   | 23   | Exclusion mode. rc = s + d - two(s * d), ra = s + (1 - sa) * d     | ![EXCLUSION](./figures/image_BlendMode_Exclusion.png) |
61e41f4b71Sopenharmony_ci| MULTIPLY    | 24   | Multiply mode. r = s * (1 - da) + d * (1 - sa) + s * d            | ![MULTIPLY](./figures/image_BlendMode_Multiply.png) |
62e41f4b71Sopenharmony_ci| HUE         | 25   | Hue mode.                                                    | ![HUE](./figures/image_BlendMode_Hue.png) |
63e41f4b71Sopenharmony_ci| SATURATION  | 26   | Saturation mode.                                                  | ![SATURATION](./figures/image_BlendMode_Saturation.png) |
64e41f4b71Sopenharmony_ci| COLOR       | 27   | Color mode.                                                    | ![COLOR](./figures/image_BlendMode_Color.png) |
65e41f4b71Sopenharmony_ci| LUMINOSITY  | 28   | Luminosity mode.                                                    | ![LUMINOSITY](./figures/image_BlendMode_Luminosity.png) |
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci## PathMeasureMatrixFlags<sup>12+</sup>
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ciEnumerates the types of matrix information obtained during path measurement.
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci| Name       | Value  | Description                                                        |
74e41f4b71Sopenharmony_ci| ----------- | ---- | ------------------------------------------------------------ |
75e41f4b71Sopenharmony_ci| GET_POSITION_MATRIX        | 0    | Matrix corresponding to the position information.                                           |
76e41f4b71Sopenharmony_ci| GET_TANGENT_MATRIX          | 1    | Matrix corresponding to the tangent information.|
77e41f4b71Sopenharmony_ci| GET_POSITION_AND_TANGENT_MATRIX    | 2     | Matrix corresponding to the position and tangent information.|
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci## SrcRectConstraint<sup>12+</sup>
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ciEnumerates the constraint types of the source rectangle.
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ci| Name       | Value  | Description                                                        |
86e41f4b71Sopenharmony_ci| ----------- | ---- | ------------------------------------------------------------ |
87e41f4b71Sopenharmony_ci| STRICT         | 0    | The sampling range is strictly confined to the source rectangle, resulting in a slow sampling speed.                                           |
88e41f4b71Sopenharmony_ci| FAST           | 1    | The sampling range is not limited to the source rectangle and can extend beyond it, allowing for a high sampling speed.|
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci## ShadowFlag<sup>12+</sup>
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ciEnumerates the flags used to control shadow drawing to create various shadow effects.
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci| Name                        | Value   | Description                |
97e41f4b71Sopenharmony_ci| -------------------------- | ---- | ------------------ |
98e41f4b71Sopenharmony_ci| NONE      | 0    | None of the flags are enabled.       |
99e41f4b71Sopenharmony_ci| TRANSPARENT_OCCLUDER | 1    | The occluder is transparent.        |
100e41f4b71Sopenharmony_ci| GEOMETRIC_ONLY    | 2    | Only the geometric shadow effect is used.       |
101e41f4b71Sopenharmony_ci| ALL           | 3    | All the flags are enabled.|
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci## PathOp<sup>12+</sup>
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ciEnumerates the operation modes available for a path.
106e41f4b71Sopenharmony_ci
107e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
108e41f4b71Sopenharmony_ci
109e41f4b71Sopenharmony_ci| Name                  | Value  | Description                          |
110e41f4b71Sopenharmony_ci| ---------------------- | ---- | ------------------------------ |
111e41f4b71Sopenharmony_ci| DIFFERENCE     | 0    | Difference operation.|
112e41f4b71Sopenharmony_ci| INTERSECT    | 1    | Intersection operation.|
113e41f4b71Sopenharmony_ci| UNION    | 2    | Union operation.|
114e41f4b71Sopenharmony_ci| XOR     | 3    | XOR operation.|
115e41f4b71Sopenharmony_ci| REVERSE_DIFFERENCE     | 4    | Reverse difference operation.|
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_ci## Path
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ciA compound geometric path consisting of line segments, arcs, quadratic Bezier curves, and cubic Bezier curves.
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ci### constructor<sup>12+</sup>
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ciconstructor()
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_ciConstructs a path.
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ci**Example**
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci```ts
132e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
133e41f4b71Sopenharmony_cilet path: drawing.Path = new drawing.Path();
134e41f4b71Sopenharmony_ci```
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci### constructor<sup>12+</sup>
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ciconstructor(path: Path)
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ciConstructs a copy of an existing path.
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ci**Parameters**
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_ci| Name  | Type                                        | Mandatory| Description                           |
147e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | ---- | ------------------------------- |
148e41f4b71Sopenharmony_ci| path | [Path](#path) | Yes  | Path to copy.                |
149e41f4b71Sopenharmony_ci
150e41f4b71Sopenharmony_ci**Example**
151e41f4b71Sopenharmony_ci
152e41f4b71Sopenharmony_ci```ts
153e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
154e41f4b71Sopenharmony_cilet path: drawing.Path = new drawing.Path();
155e41f4b71Sopenharmony_cipath.moveTo(0, 0);
156e41f4b71Sopenharmony_cipath.lineTo(0, 700);
157e41f4b71Sopenharmony_cipath.lineTo(700, 0);
158e41f4b71Sopenharmony_cipath.close();
159e41f4b71Sopenharmony_cilet path1: drawing.Path =  new drawing.Path(path);
160e41f4b71Sopenharmony_ci```
161e41f4b71Sopenharmony_ci
162e41f4b71Sopenharmony_ci### moveTo
163e41f4b71Sopenharmony_ci
164e41f4b71Sopenharmony_cimoveTo(x: number, y: number) : void
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ciSets the start point of this path.
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci**Parameters**
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                   |
173e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------- |
174e41f4b71Sopenharmony_ci| x      | number | Yes  | X coordinate of the start point. The value is a floating point number.|
175e41f4b71Sopenharmony_ci| y      | number | Yes  | Y coordinate of the start point. The value is a floating point number.|
176e41f4b71Sopenharmony_ci
177e41f4b71Sopenharmony_ci**Error codes**
178e41f4b71Sopenharmony_ci
179e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
180e41f4b71Sopenharmony_ci
181e41f4b71Sopenharmony_ci| ID| Error Message|
182e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
183e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
184e41f4b71Sopenharmony_ci
185e41f4b71Sopenharmony_ci**Example**
186e41f4b71Sopenharmony_ci
187e41f4b71Sopenharmony_ci```ts
188e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
189e41f4b71Sopenharmony_cilet path = new drawing.Path();
190e41f4b71Sopenharmony_cipath.moveTo(10,10);
191e41f4b71Sopenharmony_ci```
192e41f4b71Sopenharmony_ci
193e41f4b71Sopenharmony_ci### lineTo
194e41f4b71Sopenharmony_ci
195e41f4b71Sopenharmony_cilineTo(x: number, y: number) : void
196e41f4b71Sopenharmony_ci
197e41f4b71Sopenharmony_ciDraws a line segment from the last point of this path to the target point. If the path is empty, the start point (0, 0) is used.
198e41f4b71Sopenharmony_ci
199e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
200e41f4b71Sopenharmony_ci
201e41f4b71Sopenharmony_ci**Parameters**
202e41f4b71Sopenharmony_ci
203e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                   |
204e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------- |
205e41f4b71Sopenharmony_ci| x      | number | Yes  | X coordinate of the target point. The value is a floating point number.|
206e41f4b71Sopenharmony_ci| y      | number | Yes  | Y coordinate of the target point. The value is a floating point number.|
207e41f4b71Sopenharmony_ci
208e41f4b71Sopenharmony_ci**Error codes**
209e41f4b71Sopenharmony_ci
210e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
211e41f4b71Sopenharmony_ci
212e41f4b71Sopenharmony_ci| ID| Error Message|
213e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
214e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
215e41f4b71Sopenharmony_ci
216e41f4b71Sopenharmony_ci**Example**
217e41f4b71Sopenharmony_ci
218e41f4b71Sopenharmony_ci```ts
219e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
220e41f4b71Sopenharmony_cilet path = new drawing.Path();
221e41f4b71Sopenharmony_cipath.moveTo(10,10);
222e41f4b71Sopenharmony_cipath.lineTo(10, 15);
223e41f4b71Sopenharmony_ci```
224e41f4b71Sopenharmony_ci
225e41f4b71Sopenharmony_ci### arcTo
226e41f4b71Sopenharmony_ci
227e41f4b71Sopenharmony_ciarcTo(x1: number, y1: number, x2: number, y2: number, startDeg: number, sweepDeg: number): void
228e41f4b71Sopenharmony_ci
229e41f4b71Sopenharmony_ciDraws an arc to this path. This is done by using angle arc mode. In this mode, a rectangle that encloses an ellipse is specified first, and then a start angle and a sweep angle are specified. The arc is a portion of the ellipse defined by the start angle and the sweep angle. By default, a line segment from the last point of the path to the start point of the arc is also added.
230e41f4b71Sopenharmony_ci
231e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
232e41f4b71Sopenharmony_ci
233e41f4b71Sopenharmony_ci**Parameters**
234e41f4b71Sopenharmony_ci
235e41f4b71Sopenharmony_ci| Name  | Type  | Mandatory| Description                      |
236e41f4b71Sopenharmony_ci| -------- | ------ | ---- | -------------------------- |
237e41f4b71Sopenharmony_ci| x1       | number | Yes  | X coordinate of the upper left corner of the rectangle. The value is a floating point number.|
238e41f4b71Sopenharmony_ci| y1       | number | Yes  | Y coordinate of the upper left corner of the rectangle. The value is a floating point number.|
239e41f4b71Sopenharmony_ci| x2       | number | Yes  | X coordinate of the lower right corner of the rectangle. The value is a floating point number.|
240e41f4b71Sopenharmony_ci| y2       | number | Yes  | Y coordinate of the lower right corner of the rectangle. The value is a floating point number.|
241e41f4b71Sopenharmony_ci| startDeg | number | Yes  | Start angle, in degrees. The value is a floating point number.|
242e41f4b71Sopenharmony_ci| sweepDeg | number | Yes  | Sweep degree. The value is a floating point number.|
243e41f4b71Sopenharmony_ci
244e41f4b71Sopenharmony_ci**Error codes**
245e41f4b71Sopenharmony_ci
246e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
247e41f4b71Sopenharmony_ci
248e41f4b71Sopenharmony_ci| ID| Error Message|
249e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
250e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
251e41f4b71Sopenharmony_ci
252e41f4b71Sopenharmony_ci**Example**
253e41f4b71Sopenharmony_ci
254e41f4b71Sopenharmony_ci```ts
255e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
256e41f4b71Sopenharmony_cilet path = new drawing.Path();
257e41f4b71Sopenharmony_cipath.moveTo(10,10);
258e41f4b71Sopenharmony_cipath.arcTo(10, 15, 10, 10, 10, 10);
259e41f4b71Sopenharmony_ci```
260e41f4b71Sopenharmony_ci
261e41f4b71Sopenharmony_ci### quadTo
262e41f4b71Sopenharmony_ci
263e41f4b71Sopenharmony_ciquadTo(ctrlX: number, ctrlY: number, endX: number, endY: number): void
264e41f4b71Sopenharmony_ci
265e41f4b71Sopenharmony_ciDraws a quadratic Bezier curve from the last point of this path to the target point. If the path is empty, the start point (0, 0) is used.
266e41f4b71Sopenharmony_ci
267e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
268e41f4b71Sopenharmony_ci
269e41f4b71Sopenharmony_ci**Parameters**
270e41f4b71Sopenharmony_ci
271e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                 |
272e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------------- |
273e41f4b71Sopenharmony_ci| ctrlX  | number | Yes  | X coordinate of the control point. The value is a floating point number.|
274e41f4b71Sopenharmony_ci| ctrlY  | number | Yes  | Y coordinate of the control point. The value is a floating point number.|
275e41f4b71Sopenharmony_ci| endX   | number | Yes  | X coordinate of the target point. The value is a floating point number.|
276e41f4b71Sopenharmony_ci| endY   | number | Yes  | Y coordinate of the target point. The value is a floating point number.|
277e41f4b71Sopenharmony_ci
278e41f4b71Sopenharmony_ci**Error codes**
279e41f4b71Sopenharmony_ci
280e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
281e41f4b71Sopenharmony_ci
282e41f4b71Sopenharmony_ci| ID| Error Message|
283e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
284e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
285e41f4b71Sopenharmony_ci
286e41f4b71Sopenharmony_ci**Example**
287e41f4b71Sopenharmony_ci
288e41f4b71Sopenharmony_ci```ts
289e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
290e41f4b71Sopenharmony_cilet path = new drawing.Path();
291e41f4b71Sopenharmony_cipath.moveTo(10,10);
292e41f4b71Sopenharmony_cipath.quadTo(10, 15, 10, 10);
293e41f4b71Sopenharmony_ci```
294e41f4b71Sopenharmony_ci
295e41f4b71Sopenharmony_ci### conicTo<sup>12+</sup>
296e41f4b71Sopenharmony_ci
297e41f4b71Sopenharmony_ciconicTo(ctrlX: number, ctrlY: number, endX: number, endY: number, weight: number): void
298e41f4b71Sopenharmony_ci
299e41f4b71Sopenharmony_ciDraws a conic curve from the last point of this path to the target point. If the path is empty, the start point (0, 0) is used.
300e41f4b71Sopenharmony_ci
301e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
302e41f4b71Sopenharmony_ci
303e41f4b71Sopenharmony_ci**Parameters**
304e41f4b71Sopenharmony_ci
305e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                 |
306e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------------- |
307e41f4b71Sopenharmony_ci| ctrlX  | number | Yes  | X coordinate of the control point. The value is a floating point number.|
308e41f4b71Sopenharmony_ci| ctrlY  | number | Yes  | Y coordinate of the control point. The value is a floating point number.|
309e41f4b71Sopenharmony_ci| endX   | number | Yes  | X coordinate of the target point. The value is a floating point number.|
310e41f4b71Sopenharmony_ci| endY   | number | Yes  | Y coordinate of the target point. The value is a floating point number.|
311e41f4b71Sopenharmony_ci| weight | number | Yes  | Weight of the curve, which determines its shape. The larger the value, the closer of the curve to the control point. If the value is less than or equal to 0, this API is equivalent to [lineTo](#lineto), that is, adding a line segment from the last point of the path to the target point. If the value is 1, this API is equivalent to [quadTo](#quadto). The value is a floating point number.|
312e41f4b71Sopenharmony_ci
313e41f4b71Sopenharmony_ci**Error codes**
314e41f4b71Sopenharmony_ci
315e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
316e41f4b71Sopenharmony_ci
317e41f4b71Sopenharmony_ci| ID| Error Message|
318e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
319e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
320e41f4b71Sopenharmony_ci
321e41f4b71Sopenharmony_ci**Example**
322e41f4b71Sopenharmony_ci
323e41f4b71Sopenharmony_ci```ts
324e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
325e41f4b71Sopenharmony_ci
326e41f4b71Sopenharmony_ciconst path = new drawing.Path();
327e41f4b71Sopenharmony_cipath.conicTo(200, 400, 100, 200, 0);
328e41f4b71Sopenharmony_ci```
329e41f4b71Sopenharmony_ci
330e41f4b71Sopenharmony_ci### cubicTo
331e41f4b71Sopenharmony_ci
332e41f4b71Sopenharmony_cicubicTo(ctrlX1: number, ctrlY1: number, ctrlX2: number, ctrlY2: number, endX: number, endY: number): void
333e41f4b71Sopenharmony_ci
334e41f4b71Sopenharmony_ciDraws a cubic Bezier curve from the last point of this path to the target point. If the path is empty, the start point (0, 0) is used.
335e41f4b71Sopenharmony_ci
336e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
337e41f4b71Sopenharmony_ci
338e41f4b71Sopenharmony_ci**Parameters**
339e41f4b71Sopenharmony_ci
340e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                       |
341e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------------------- |
342e41f4b71Sopenharmony_ci| ctrlX1 | number | Yes  | X coordinate of the first control point. The value is a floating point number.|
343e41f4b71Sopenharmony_ci| ctrlY1 | number | Yes  | Y coordinate of the first control point. The value is a floating point number.|
344e41f4b71Sopenharmony_ci| ctrlX2 | number | Yes  | X coordinate of the second control point. The value is a floating point number.|
345e41f4b71Sopenharmony_ci| ctrlY2 | number | Yes  | Y coordinate of the second control point. The value is a floating point number.|
346e41f4b71Sopenharmony_ci| endX   | number | Yes  | X coordinate of the target point. The value is a floating point number.|
347e41f4b71Sopenharmony_ci| endY   | number | Yes  | Y coordinate of the target point. The value is a floating point number.|
348e41f4b71Sopenharmony_ci
349e41f4b71Sopenharmony_ci**Error codes**
350e41f4b71Sopenharmony_ci
351e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
352e41f4b71Sopenharmony_ci
353e41f4b71Sopenharmony_ci| ID| Error Message|
354e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
355e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
356e41f4b71Sopenharmony_ci
357e41f4b71Sopenharmony_ci**Example**
358e41f4b71Sopenharmony_ci
359e41f4b71Sopenharmony_ci```ts
360e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
361e41f4b71Sopenharmony_cilet path = new drawing.Path();
362e41f4b71Sopenharmony_cipath.moveTo(10,10);
363e41f4b71Sopenharmony_cipath.cubicTo(10, 10, 10, 10, 15, 15);
364e41f4b71Sopenharmony_ci```
365e41f4b71Sopenharmony_ci
366e41f4b71Sopenharmony_ci### rMoveTo<sup>12+</sup>
367e41f4b71Sopenharmony_ci
368e41f4b71Sopenharmony_cirMoveTo(dx : number, dy : number): void
369e41f4b71Sopenharmony_ci
370e41f4b71Sopenharmony_ciSets the start position relative to the last point of this path. If the path is empty, the start point (0, 0) is used.
371e41f4b71Sopenharmony_ci
372e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
373e41f4b71Sopenharmony_ci
374e41f4b71Sopenharmony_ci**Parameters**
375e41f4b71Sopenharmony_ci
376e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                   |
377e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------- |
378e41f4b71Sopenharmony_ci| dx     | number | Yes  | X offset of the start point relative to the last point. A positive number indicates a rightward shift from the last point, and a negative number indicates a leftward shift from the last point. The value is a floating point number.|
379e41f4b71Sopenharmony_ci| dy     | number | Yes  | Y offset of the start point relative to the last point. A positive number indicates an upward shift from the last point, and a negative number indicates a downward shift from the last point. The value is a floating point number.|
380e41f4b71Sopenharmony_ci
381e41f4b71Sopenharmony_ci**Error codes**
382e41f4b71Sopenharmony_ci
383e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
384e41f4b71Sopenharmony_ci
385e41f4b71Sopenharmony_ci| ID| Error Message|
386e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
387e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
388e41f4b71Sopenharmony_ci
389e41f4b71Sopenharmony_ci**Example**
390e41f4b71Sopenharmony_ci
391e41f4b71Sopenharmony_ci```ts
392e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
393e41f4b71Sopenharmony_ci
394e41f4b71Sopenharmony_ciconst path = new drawing.Path();
395e41f4b71Sopenharmony_cipath.rMoveTo(10, 10);
396e41f4b71Sopenharmony_ci```
397e41f4b71Sopenharmony_ci
398e41f4b71Sopenharmony_ci### rLineTo<sup>12+</sup>
399e41f4b71Sopenharmony_ci
400e41f4b71Sopenharmony_cirLineTo(dx : number, dy : number): void
401e41f4b71Sopenharmony_ci
402e41f4b71Sopenharmony_ciDraws a line segment from the last point of this path to a point relative to the last point. If the path is empty, the start point (0, 0) is used.
403e41f4b71Sopenharmony_ci
404e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
405e41f4b71Sopenharmony_ci
406e41f4b71Sopenharmony_ci**Parameters**
407e41f4b71Sopenharmony_ci
408e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                   |
409e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------- |
410e41f4b71Sopenharmony_ci| dx     | number | Yes  | X offset of the target point relative to the last point. A positive number indicates a rightward shift from the last point, and a negative number indicates a leftward shift from the last point. The value is a floating point number.|
411e41f4b71Sopenharmony_ci| dy     | number | Yes  | Y offset of the target point relative to the last point. A positive number indicates an upward shift from the last point, and a negative number indicates a downward shift from the last point. The value is a floating point number.|
412e41f4b71Sopenharmony_ci
413e41f4b71Sopenharmony_ci**Error codes**
414e41f4b71Sopenharmony_ci
415e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
416e41f4b71Sopenharmony_ci
417e41f4b71Sopenharmony_ci| ID| Error Message|
418e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
419e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
420e41f4b71Sopenharmony_ci
421e41f4b71Sopenharmony_ci**Example**
422e41f4b71Sopenharmony_ci
423e41f4b71Sopenharmony_ci```ts
424e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
425e41f4b71Sopenharmony_ci
426e41f4b71Sopenharmony_ciconst path = new drawing.Path();
427e41f4b71Sopenharmony_cipath.rLineTo(400, 200);
428e41f4b71Sopenharmony_ci```
429e41f4b71Sopenharmony_ci
430e41f4b71Sopenharmony_ci### rQuadTo<sup>12+</sup>
431e41f4b71Sopenharmony_ci
432e41f4b71Sopenharmony_cirQuadTo(dx1: number, dy1: number, dx2: number, dy2: number): void
433e41f4b71Sopenharmony_ci
434e41f4b71Sopenharmony_ciDraws a quadratic Bezier curve from the last point of this path to a point relative to the last point. If the path is empty, the start point (0, 0) is used.
435e41f4b71Sopenharmony_ci
436e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
437e41f4b71Sopenharmony_ci
438e41f4b71Sopenharmony_ci**Parameters**
439e41f4b71Sopenharmony_ci
440e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                 |
441e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------------- |
442e41f4b71Sopenharmony_ci| dx1  | number | Yes  | X offset of the control point relative to the last point. A positive number indicates a rightward shift from the last point, and a negative number indicates a leftward shift from the last point. The value is a floating point number.|
443e41f4b71Sopenharmony_ci| dy1  | number | Yes  | Y offset of the control point relative to the last point. A positive number indicates an upward shift from the last point, and a negative number indicates a downward shift from the last point. The value is a floating point number.|
444e41f4b71Sopenharmony_ci| dx2   | number | Yes  | X offset of the target point relative to the last point. A positive number indicates a rightward shift from the last point, and a negative number indicates a leftward shift from the last point. The value is a floating point number.|
445e41f4b71Sopenharmony_ci| dy2   | number | Yes  | Y offset of the target point relative to the last point. A positive number indicates an upward shift from the last point, and a negative number indicates a downward shift from the last point. The value is a floating point number.|
446e41f4b71Sopenharmony_ci
447e41f4b71Sopenharmony_ci**Error codes**
448e41f4b71Sopenharmony_ci
449e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
450e41f4b71Sopenharmony_ci
451e41f4b71Sopenharmony_ci| ID| Error Message|
452e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
453e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
454e41f4b71Sopenharmony_ci
455e41f4b71Sopenharmony_ci**Example**
456e41f4b71Sopenharmony_ci
457e41f4b71Sopenharmony_ci```ts
458e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
459e41f4b71Sopenharmony_ci
460e41f4b71Sopenharmony_ciconst path = new drawing.Path();
461e41f4b71Sopenharmony_cipath.rQuadTo(100, 0, 0, 200);
462e41f4b71Sopenharmony_ci```
463e41f4b71Sopenharmony_ci
464e41f4b71Sopenharmony_ci### rConicTo<sup>12+</sup>
465e41f4b71Sopenharmony_ci
466e41f4b71Sopenharmony_cirConicTo(ctrlX: number, ctrlY: number, endX: number, endY: number, weight: number): void
467e41f4b71Sopenharmony_ci
468e41f4b71Sopenharmony_ciDraws a conic curve from the last point of this path to a point relative to the last point. If the path is empty, the start point (0, 0) is used.
469e41f4b71Sopenharmony_ci
470e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
471e41f4b71Sopenharmony_ci
472e41f4b71Sopenharmony_ci**Parameters**
473e41f4b71Sopenharmony_ci
474e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                 |
475e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------------- |
476e41f4b71Sopenharmony_ci| ctrlX  | number | Yes  | X offset of the control point relative to the last point. A positive number indicates a rightward shift from the last point, and a negative number indicates a leftward shift from the last point. The value is a floating point number.|
477e41f4b71Sopenharmony_ci| ctrlY  | number | Yes  | Y offset of the control point relative to the last point. A positive number indicates an upward shift from the last point, and a negative number indicates a downward shift from the last point. The value is a floating point number.|
478e41f4b71Sopenharmony_ci| endX   | number | Yes  | X offset of the target point relative to the last point. A positive number indicates a rightward shift from the last point, and a negative number indicates a leftward shift from the last point. The value is a floating point number.|
479e41f4b71Sopenharmony_ci| endY   | number | Yes  | Y offset of the target point relative to the last point. A positive number indicates an upward shift from the last point, and a negative number indicates a downward shift from the last point. The value is a floating point number.|
480e41f4b71Sopenharmony_ci| weight | number | Yes  | Weight of the curve, which determines its shape. The larger the value, the closer of the curve to the control point. If the value is less than or equal to 0, this API is equivalent to [rLineTo](#rlineto12), that is, adding a line segment from the last point of the path to the target point. If the value is 1, this API is equivalent to [rQuadTo](#rquadto12). The value is a floating point number.|
481e41f4b71Sopenharmony_ci
482e41f4b71Sopenharmony_ci**Error codes**
483e41f4b71Sopenharmony_ci
484e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
485e41f4b71Sopenharmony_ci
486e41f4b71Sopenharmony_ci| ID| Error Message|
487e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
488e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
489e41f4b71Sopenharmony_ci
490e41f4b71Sopenharmony_ci**Example**
491e41f4b71Sopenharmony_ci
492e41f4b71Sopenharmony_ci```ts
493e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
494e41f4b71Sopenharmony_ci
495e41f4b71Sopenharmony_ciconst path = new drawing.Path();
496e41f4b71Sopenharmony_cipath.rConicTo(200, 400, 100, 200, 0);
497e41f4b71Sopenharmony_ci```
498e41f4b71Sopenharmony_ci
499e41f4b71Sopenharmony_ci### rCubicTo<sup>12+</sup>
500e41f4b71Sopenharmony_ci
501e41f4b71Sopenharmony_cirCubicTo(ctrlX1: number, ctrlY1: number, ctrlX2: number, ctrlY2: number, endX: number, endY: number): void
502e41f4b71Sopenharmony_ci
503e41f4b71Sopenharmony_ciDraws a cubic Bezier curve from the last point of this path to a point relative to the last point. If the path is empty, the start point (0, 0) is used.
504e41f4b71Sopenharmony_ci
505e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
506e41f4b71Sopenharmony_ci
507e41f4b71Sopenharmony_ci**Parameters**
508e41f4b71Sopenharmony_ci
509e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                       |
510e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------------------- |
511e41f4b71Sopenharmony_ci| ctrlX1 | number | Yes  | X offset of the first control point relative to the last point. A positive number indicates a rightward shift from the last point, and a negative number indicates a leftward shift from the last point. The value is a floating point number.|
512e41f4b71Sopenharmony_ci| ctrlY1 | number | Yes  | Y offset of the first control point relative to the last point. A positive number indicates an upward shift from the last point, and a negative number indicates a downward shift from the last point. The value is a floating point number.|
513e41f4b71Sopenharmony_ci| ctrlX2 | number | Yes  | X offset of the second control point relative to the last point. A positive number indicates a rightward shift from the last point, and a negative number indicates a leftward shift from the last point. The value is a floating point number.|
514e41f4b71Sopenharmony_ci| ctrlY2 | number | Yes  | Y offset of the second control point relative to the last point. A positive number indicates an upward shift from the last point, and a negative number indicates a downward shift from the last point. The value is a floating point number.|
515e41f4b71Sopenharmony_ci| endX   | number | Yes  | X offset of the target point relative to the last point. A positive number indicates a rightward shift from the last point, and a negative number indicates a leftward shift from the last point. The value is a floating point number.|
516e41f4b71Sopenharmony_ci| endY   | number | Yes  | Y offset of the target point relative to the last point. A positive number indicates an upward shift from the last point, and a negative number indicates a downward shift from the last point. The value is a floating point number.|
517e41f4b71Sopenharmony_ci
518e41f4b71Sopenharmony_ci**Error codes**
519e41f4b71Sopenharmony_ci
520e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
521e41f4b71Sopenharmony_ci
522e41f4b71Sopenharmony_ci| ID| Error Message|
523e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
524e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
525e41f4b71Sopenharmony_ci
526e41f4b71Sopenharmony_ci**Example**
527e41f4b71Sopenharmony_ci
528e41f4b71Sopenharmony_ci```ts
529e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
530e41f4b71Sopenharmony_ci
531e41f4b71Sopenharmony_ciconst path = new drawing.Path();
532e41f4b71Sopenharmony_cipath.rCubicTo(200, 0, 0, 200, -20, 0);
533e41f4b71Sopenharmony_ci```
534e41f4b71Sopenharmony_ci
535e41f4b71Sopenharmony_ci### addArc<sup>12+</sup>
536e41f4b71Sopenharmony_ci
537e41f4b71Sopenharmony_ciaddArc(rect: common2D.Rect, startAngle: number, sweepAngle: number): void
538e41f4b71Sopenharmony_ci
539e41f4b71Sopenharmony_ciAdds an arc to this path.
540e41f4b71Sopenharmony_ciWhen **startAngle** and **sweepAngle** meet the following conditions, an oval instead of an arc is added:
541e41f4b71Sopenharmony_ci1. The result of **startAngle** modulo 90 is close to 0.
542e41f4b71Sopenharmony_ci2. The value of **sweepAngle** is not in the range of (-360, 360).
543e41f4b71Sopenharmony_ciIn other cases, this API adds an arc by applying the result of **sweepAngle** modulo 360 to the path.
544e41f4b71Sopenharmony_ci
545e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
546e41f4b71Sopenharmony_ci
547e41f4b71Sopenharmony_ci**Parameters**
548e41f4b71Sopenharmony_ci
549e41f4b71Sopenharmony_ci| Name        | Type                                      | Mandatory  | Description                 |
550e41f4b71Sopenharmony_ci| ----------- | ---------------------------------------- | ---- | ------------------- |
551e41f4b71Sopenharmony_ci| rect        | [common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes   | Rectangular boundary that encapsulates the oval including the arc.     |
552e41f4b71Sopenharmony_ci| startAngle   | number | Yes  | Start angle of the arc, in degrees. The value 0 indicates the positive direction of the X axis. The value is a floating point number.|
553e41f4b71Sopenharmony_ci| sweepAngle   | number | Yes  | Angle to sweep, in degrees. A positive number indicates a clockwise sweep, and a negative number indicates a counterclockwise sweep. The value is a floating point number.|
554e41f4b71Sopenharmony_ci
555e41f4b71Sopenharmony_ci**Error codes**
556e41f4b71Sopenharmony_ci
557e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
558e41f4b71Sopenharmony_ci
559e41f4b71Sopenharmony_ci| ID| Error Message|
560e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
561e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
562e41f4b71Sopenharmony_ci
563e41f4b71Sopenharmony_ci**Example**
564e41f4b71Sopenharmony_ci
565e41f4b71Sopenharmony_ci```ts
566e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
567e41f4b71Sopenharmony_ci
568e41f4b71Sopenharmony_cilet path = new drawing.Path();
569e41f4b71Sopenharmony_ciconst rect: common2D.Rect = {left:100, top:100, right:500, bottom:500};
570e41f4b71Sopenharmony_cipath.addArc(rect, 90, 180);
571e41f4b71Sopenharmony_ci```
572e41f4b71Sopenharmony_ci
573e41f4b71Sopenharmony_ci### addCircle<sup>12+</sup>
574e41f4b71Sopenharmony_ci
575e41f4b71Sopenharmony_ciaddCircle(x: number, y: number, radius: number, pathDirection?: PathDirection): void
576e41f4b71Sopenharmony_ci
577e41f4b71Sopenharmony_ciAdds a circle to this path in the specified direction. The start point of the circle is (x + radius, y).
578e41f4b71Sopenharmony_ci
579e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
580e41f4b71Sopenharmony_ci
581e41f4b71Sopenharmony_ci**Parameters**
582e41f4b71Sopenharmony_ci
583e41f4b71Sopenharmony_ci| Name        | Type                                      | Mandatory  | Description                 |
584e41f4b71Sopenharmony_ci| ----------- | ---------------------------------------- | ---- | ------------------- |
585e41f4b71Sopenharmony_ci| x   | number | Yes  | X coordinate of the center of the circle. The value is a floating point number.|
586e41f4b71Sopenharmony_ci| y   | number | Yes  | Y coordinate of the center of the circle. The value is a floating point number.|
587e41f4b71Sopenharmony_ci| radius   | number | Yes  | Radius of the circle. The value is a floating point number. If the value is less than or equal to 0, there is no effect.|
588e41f4b71Sopenharmony_ci| pathDirection   | [PathDirection](#pathdirection12)  | No  | Direction of the path. The default direction is clockwise.|
589e41f4b71Sopenharmony_ci
590e41f4b71Sopenharmony_ci**Error codes**
591e41f4b71Sopenharmony_ci
592e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
593e41f4b71Sopenharmony_ci
594e41f4b71Sopenharmony_ci| ID| Error Message|
595e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
596e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
597e41f4b71Sopenharmony_ci
598e41f4b71Sopenharmony_ci**Example**
599e41f4b71Sopenharmony_ci
600e41f4b71Sopenharmony_ci```ts
601e41f4b71Sopenharmony_ci
602e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
603e41f4b71Sopenharmony_ci
604e41f4b71Sopenharmony_cilet path = new drawing.Path();
605e41f4b71Sopenharmony_cipath.addCircle(100, 200, 50, drawing.PathDirection.CLOCKWISE);
606e41f4b71Sopenharmony_ci```
607e41f4b71Sopenharmony_ci
608e41f4b71Sopenharmony_ci### addOval<sup>12+</sup>
609e41f4b71Sopenharmony_ci
610e41f4b71Sopenharmony_ciaddOval(rect: common2D.Rect, start: number, pathDirection?: PathDirection): void
611e41f4b71Sopenharmony_ci
612e41f4b71Sopenharmony_ciAdds an oval to this path in the specified direction, where the **common2D.Rect** object specifies the outer tangent rectangle of the oval.
613e41f4b71Sopenharmony_ci
614e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
615e41f4b71Sopenharmony_ci
616e41f4b71Sopenharmony_ci**Parameters**
617e41f4b71Sopenharmony_ci
618e41f4b71Sopenharmony_ci| Name        | Type                                      | Mandatory  | Description                 |
619e41f4b71Sopenharmony_ci| ----------- | ---------------------------------------- | ---- | ------------------- |
620e41f4b71Sopenharmony_ci| rect        | [common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes   | Rectangular boundary of the oval.     |
621e41f4b71Sopenharmony_ci| start   | number | Yes  | Start point of the oval, where 0, 1, 2, and 3 correspond to the upper, right, lower, and left points, respectively. The value is an integer greater than or equal to 0. If the value is greater than or equal to 4, the remainder of 4 is used.|
622e41f4b71Sopenharmony_ci| pathDirection   | [PathDirection](#pathdirection12)  | No  | Direction of the path. The default direction is clockwise.|
623e41f4b71Sopenharmony_ci
624e41f4b71Sopenharmony_ci**Error codes**
625e41f4b71Sopenharmony_ci
626e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
627e41f4b71Sopenharmony_ci
628e41f4b71Sopenharmony_ci| ID| Error Message|
629e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
630e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.|
631e41f4b71Sopenharmony_ci
632e41f4b71Sopenharmony_ci**Example**
633e41f4b71Sopenharmony_ci
634e41f4b71Sopenharmony_ci```ts
635e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
636e41f4b71Sopenharmony_ci
637e41f4b71Sopenharmony_cilet path = new drawing.Path();
638e41f4b71Sopenharmony_ciconst rect: common2D.Rect = {left:100, top:100, right:500, bottom:500};
639e41f4b71Sopenharmony_cipath.addOval(rect, 5, drawing.PathDirection.CLOCKWISE);
640e41f4b71Sopenharmony_ci```
641e41f4b71Sopenharmony_ci
642e41f4b71Sopenharmony_ci### addRect<sup>12+</sup>
643e41f4b71Sopenharmony_ci
644e41f4b71Sopenharmony_ciaddRect(rect: common2D.Rect, pathDirection?: PathDirection): void
645e41f4b71Sopenharmony_ci
646e41f4b71Sopenharmony_ciAdds a rectangle to this path in the specified direction. The start point is the upper left corner of the rectangle.
647e41f4b71Sopenharmony_ci
648e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
649e41f4b71Sopenharmony_ci
650e41f4b71Sopenharmony_ci**Parameters**
651e41f4b71Sopenharmony_ci
652e41f4b71Sopenharmony_ci| Name        | Type                                      | Mandatory  | Description                 |
653e41f4b71Sopenharmony_ci| ----------- | ---------------------------------------- | ---- | ------------------- |
654e41f4b71Sopenharmony_ci| rect        | [common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes   | Rectangle.     |
655e41f4b71Sopenharmony_ci| pathDirection   | [PathDirection](#pathdirection12)  | No  | Direction of the path. The default direction is clockwise.|
656e41f4b71Sopenharmony_ci
657e41f4b71Sopenharmony_ci**Error codes**
658e41f4b71Sopenharmony_ci
659e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
660e41f4b71Sopenharmony_ci
661e41f4b71Sopenharmony_ci| ID| Error Message|
662e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
663e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.|
664e41f4b71Sopenharmony_ci
665e41f4b71Sopenharmony_ci**Example**
666e41f4b71Sopenharmony_ci
667e41f4b71Sopenharmony_ci```ts
668e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
669e41f4b71Sopenharmony_ci
670e41f4b71Sopenharmony_cilet path = new drawing.Path();
671e41f4b71Sopenharmony_ciconst rect: common2D.Rect = {left:100, top:100, right:500, bottom:500};
672e41f4b71Sopenharmony_cipath.addRect(rect, drawing.PathDirection.CLOCKWISE);
673e41f4b71Sopenharmony_ci```
674e41f4b71Sopenharmony_ci
675e41f4b71Sopenharmony_ci### addRoundRect<sup>12+</sup>
676e41f4b71Sopenharmony_ci
677e41f4b71Sopenharmony_ciaddRoundRect(roundRect: RoundRect, pathDirection?: PathDirection): void
678e41f4b71Sopenharmony_ci
679e41f4b71Sopenharmony_ciAdds a rounded rectangle to this path in the specified direction. When the path direction is clockwise, the start point is at the intersection of the rounded rectangle's left boundary and its lower left corner. When the path direction is counterclockwise, the start point is at the intersection point between the left boundary and the upper left corner.
680e41f4b71Sopenharmony_ci
681e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
682e41f4b71Sopenharmony_ci
683e41f4b71Sopenharmony_ci**Parameters**
684e41f4b71Sopenharmony_ci
685e41f4b71Sopenharmony_ci| Name        | Type                                      | Mandatory  | Description                 |
686e41f4b71Sopenharmony_ci| ----------- | ---------------------------------------- | ---- | ------------------- |
687e41f4b71Sopenharmony_ci| roundRect        | [RoundRect](#roundrect12) | Yes   | Rounded rectangle.     |
688e41f4b71Sopenharmony_ci| pathDirection   | [PathDirection](#pathdirection12)  | No  | Direction of the path. The default direction is clockwise.|
689e41f4b71Sopenharmony_ci
690e41f4b71Sopenharmony_ci**Error codes**
691e41f4b71Sopenharmony_ci
692e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
693e41f4b71Sopenharmony_ci
694e41f4b71Sopenharmony_ci| ID| Error Message|
695e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
696e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.|
697e41f4b71Sopenharmony_ci
698e41f4b71Sopenharmony_ci**Example**
699e41f4b71Sopenharmony_ci
700e41f4b71Sopenharmony_ci```ts
701e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
702e41f4b71Sopenharmony_ci
703e41f4b71Sopenharmony_cilet path = new drawing.Path();
704e41f4b71Sopenharmony_ciconst rect: common2D.Rect = {left:100, top:100, right:500, bottom:500};
705e41f4b71Sopenharmony_cilet roundRect = new drawing.RoundRect(rect, 50, 50);
706e41f4b71Sopenharmony_cipath.addRoundRect(roundRect, drawing.PathDirection.CLOCKWISE);
707e41f4b71Sopenharmony_ci```
708e41f4b71Sopenharmony_ci
709e41f4b71Sopenharmony_ci### addPath<sup>12+</sup>
710e41f4b71Sopenharmony_ci
711e41f4b71Sopenharmony_ciaddPath(path: Path, matrix?: Matrix | null): void
712e41f4b71Sopenharmony_ci
713e41f4b71Sopenharmony_ciTransforms the points in a path by a matrix and stores the resulting path in the current **Path** object.
714e41f4b71Sopenharmony_ci
715e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
716e41f4b71Sopenharmony_ci
717e41f4b71Sopenharmony_ci**Parameters**
718e41f4b71Sopenharmony_ci
719e41f4b71Sopenharmony_ci| Name        | Type                                      | Mandatory  | Description                 |
720e41f4b71Sopenharmony_ci| ----------- | ---------------------------------------- | ---- | ------------------- |
721e41f4b71Sopenharmony_ci| path        | [Path](#path) | Yes   | Source **Path** object.     |
722e41f4b71Sopenharmony_ci| matrix   | [Matrix](#matrix12)\|null  | No  | **Matrix** object. The default value is an identity matrix.|
723e41f4b71Sopenharmony_ci
724e41f4b71Sopenharmony_ci**Error codes**
725e41f4b71Sopenharmony_ci
726e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
727e41f4b71Sopenharmony_ci
728e41f4b71Sopenharmony_ci| ID| Error Message|
729e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
730e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
731e41f4b71Sopenharmony_ci
732e41f4b71Sopenharmony_ci**Example**
733e41f4b71Sopenharmony_ci
734e41f4b71Sopenharmony_ci```ts
735e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
736e41f4b71Sopenharmony_ci
737e41f4b71Sopenharmony_cilet path = new drawing.Path();
738e41f4b71Sopenharmony_cilet matrix = new drawing.Matrix();
739e41f4b71Sopenharmony_ciconst rect: common2D.Rect = {left:100, top:100, right:500, bottom:500};
740e41f4b71Sopenharmony_cilet roundRect = new drawing.RoundRect(rect, 50, 50);
741e41f4b71Sopenharmony_cipath.addRoundRect(roundRect, drawing.PathDirection.CLOCKWISE);
742e41f4b71Sopenharmony_cilet dstPath = new drawing.Path();
743e41f4b71Sopenharmony_cidstPath.addPath(path, matrix);
744e41f4b71Sopenharmony_ci```
745e41f4b71Sopenharmony_ci
746e41f4b71Sopenharmony_ci### transform<sup>12+</sup>
747e41f4b71Sopenharmony_ci
748e41f4b71Sopenharmony_citransform(matrix: Matrix): void
749e41f4b71Sopenharmony_ci
750e41f4b71Sopenharmony_ciTransforms the points in this path by a matrix.
751e41f4b71Sopenharmony_ci
752e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
753e41f4b71Sopenharmony_ci
754e41f4b71Sopenharmony_ci**Parameters**
755e41f4b71Sopenharmony_ci
756e41f4b71Sopenharmony_ci| Name        | Type                                      | Mandatory  | Description                 |
757e41f4b71Sopenharmony_ci| ----------- | ---------------------------------------- | ---- | ------------------- |
758e41f4b71Sopenharmony_ci| matrix   | [Matrix](#matrix12)  | Yes  | **Matrix** object.|
759e41f4b71Sopenharmony_ci
760e41f4b71Sopenharmony_ci**Error codes**
761e41f4b71Sopenharmony_ci
762e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
763e41f4b71Sopenharmony_ci
764e41f4b71Sopenharmony_ci| ID| Error Message|
765e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
766e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
767e41f4b71Sopenharmony_ci
768e41f4b71Sopenharmony_ci**Example**
769e41f4b71Sopenharmony_ci
770e41f4b71Sopenharmony_ci```ts
771e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
772e41f4b71Sopenharmony_ci
773e41f4b71Sopenharmony_cilet path = new drawing.Path();
774e41f4b71Sopenharmony_cilet matrix = new drawing.Matrix();
775e41f4b71Sopenharmony_cimatrix.setScale(1.5, 1.5, 10, 10);
776e41f4b71Sopenharmony_ciconst rect: common2D.Rect = {left:100, top:100, right:500, bottom:500};
777e41f4b71Sopenharmony_cilet roundRect = new drawing.RoundRect(rect, 50, 50);
778e41f4b71Sopenharmony_cipath.addRoundRect(roundRect, drawing.PathDirection.CLOCKWISE);
779e41f4b71Sopenharmony_cipath.transform(matrix);
780e41f4b71Sopenharmony_ci```
781e41f4b71Sopenharmony_ci
782e41f4b71Sopenharmony_ci### contains<sup>12+</sup>
783e41f4b71Sopenharmony_ci
784e41f4b71Sopenharmony_cicontains(x: number, y: number): boolean
785e41f4b71Sopenharmony_ci
786e41f4b71Sopenharmony_ciChecks whether a coordinate point is included in this path. For details, see [PathFillType](#pathfilltype12).
787e41f4b71Sopenharmony_ci
788e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
789e41f4b71Sopenharmony_ci
790e41f4b71Sopenharmony_ci**Parameters**
791e41f4b71Sopenharmony_ci
792e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                   |
793e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------- |
794e41f4b71Sopenharmony_ci| x      | number | Yes  | X coordinate. The value is a floating point number.|
795e41f4b71Sopenharmony_ci| y      | number | Yes  | Y coordinate. The value is a floating point number.|
796e41f4b71Sopenharmony_ci
797e41f4b71Sopenharmony_ci**Return value**
798e41f4b71Sopenharmony_ci
799e41f4b71Sopenharmony_ci| Type   | Description          |
800e41f4b71Sopenharmony_ci| ------- | -------------- |
801e41f4b71Sopenharmony_ci| boolean | Result indicating whether the coordinate point is included in the path. The value **true** means that the coordinate point is included in the path, and **false** means the opposite.|
802e41f4b71Sopenharmony_ci
803e41f4b71Sopenharmony_ci**Error codes**
804e41f4b71Sopenharmony_ci
805e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
806e41f4b71Sopenharmony_ci
807e41f4b71Sopenharmony_ci| ID| Error Message|
808e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
809e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
810e41f4b71Sopenharmony_ci
811e41f4b71Sopenharmony_ci**Example**
812e41f4b71Sopenharmony_ci
813e41f4b71Sopenharmony_ci```ts
814e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
815e41f4b71Sopenharmony_ci
816e41f4b71Sopenharmony_ciconst path = new drawing.Path();
817e41f4b71Sopenharmony_cilet rect : common2D.Rect = {left: 50, top: 50, right: 250, bottom: 250};
818e41f4b71Sopenharmony_cipath.addRect(rect, drawing.PathDirection.CLOCKWISE);
819e41f4b71Sopenharmony_ciconsole.info("test contains: " + path.contains(0, 0));
820e41f4b71Sopenharmony_ciconsole.info("test contains: " + path.contains(60, 60));
821e41f4b71Sopenharmony_ci```
822e41f4b71Sopenharmony_ci
823e41f4b71Sopenharmony_ci### setFillType<sup>12+</sup>
824e41f4b71Sopenharmony_ci
825e41f4b71Sopenharmony_cisetFillType(pathFillType: PathFillType): void
826e41f4b71Sopenharmony_ci
827e41f4b71Sopenharmony_ciSets the fill type of this path. The fill type determines how "inside" of the path is drawn. For example, when the fill type **Winding** is used, "inside" of the path is determined by a non-zero sum of signed edge crossings. When **EvenOdd** is used, "inside" of the path is determined by an odd number of edge crossings.
828e41f4b71Sopenharmony_ci
829e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
830e41f4b71Sopenharmony_ci
831e41f4b71Sopenharmony_ci**Parameters**
832e41f4b71Sopenharmony_ci
833e41f4b71Sopenharmony_ci| Name        | Type                                      | Mandatory  | Description                 |
834e41f4b71Sopenharmony_ci| ----------- | ---------------------------------------- | ---- | ------------------- |
835e41f4b71Sopenharmony_ci| pathFillType   | [PathFillType](#pathfilltype12)  | Yes  | Fill type of the path.|
836e41f4b71Sopenharmony_ci
837e41f4b71Sopenharmony_ci**Error codes**
838e41f4b71Sopenharmony_ci
839e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
840e41f4b71Sopenharmony_ci
841e41f4b71Sopenharmony_ci| ID| Error Message|
842e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
843e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.|
844e41f4b71Sopenharmony_ci
845e41f4b71Sopenharmony_ci**Example**
846e41f4b71Sopenharmony_ci
847e41f4b71Sopenharmony_ci```ts
848e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
849e41f4b71Sopenharmony_ci
850e41f4b71Sopenharmony_ciconst path = new drawing.Path();
851e41f4b71Sopenharmony_cipath.setFillType(drawing.PathFillType.WINDING);
852e41f4b71Sopenharmony_ci```
853e41f4b71Sopenharmony_ci
854e41f4b71Sopenharmony_ci### getBounds<sup>12+</sup>
855e41f4b71Sopenharmony_ci
856e41f4b71Sopenharmony_cigetBounds(): common2D.Rect
857e41f4b71Sopenharmony_ci
858e41f4b71Sopenharmony_ciObtains the minimum bounding rectangle that encloses this path.
859e41f4b71Sopenharmony_ci
860e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
861e41f4b71Sopenharmony_ci
862e41f4b71Sopenharmony_ci**Return value**
863e41f4b71Sopenharmony_ci
864e41f4b71Sopenharmony_ci| Type                                              | Description                  |
865e41f4b71Sopenharmony_ci| -------------------------------------------------- | ---------------------- |
866e41f4b71Sopenharmony_ci| [common2D.Rect](js-apis-graphics-common2D.md#rect) | Minimum bounding rectangle.|
867e41f4b71Sopenharmony_ci
868e41f4b71Sopenharmony_ci**Example**
869e41f4b71Sopenharmony_ci
870e41f4b71Sopenharmony_ci```ts
871e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
872e41f4b71Sopenharmony_ci
873e41f4b71Sopenharmony_ciconst path = new drawing.Path();
874e41f4b71Sopenharmony_cipath.lineTo(50, 40)
875e41f4b71Sopenharmony_cilet rect : common2D.Rect = {left: 0, top: 0, right: 0, bottom: 0};
876e41f4b71Sopenharmony_cirect = path.getBounds();
877e41f4b71Sopenharmony_ciconsole.info("test rect.left: " + rect.left);
878e41f4b71Sopenharmony_ciconsole.info("test rect.top: " + rect.top);
879e41f4b71Sopenharmony_ciconsole.info("test rect.right: " + rect.right);
880e41f4b71Sopenharmony_ciconsole.info("test rect.bottom: " + rect.bottom);
881e41f4b71Sopenharmony_ci```
882e41f4b71Sopenharmony_ci
883e41f4b71Sopenharmony_ci### addPolygon<sup>12+</sup>
884e41f4b71Sopenharmony_ci
885e41f4b71Sopenharmony_ciaddPolygon(points: Array\<common2D.Point>, close: boolean): void
886e41f4b71Sopenharmony_ci
887e41f4b71Sopenharmony_ciAdds a polygon to this path.
888e41f4b71Sopenharmony_ci
889e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
890e41f4b71Sopenharmony_ci
891e41f4b71Sopenharmony_ci**Parameters**
892e41f4b71Sopenharmony_ci
893e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                   |
894e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------- |
895e41f4b71Sopenharmony_ci| points | Array\<[common2D.Point](js-apis-graphics-common2D.md#point)>   | Yes  | Array that holds the vertex coordinates of the polygon.|
896e41f4b71Sopenharmony_ci| close  | boolean                                                        | Yes  | Whether to close the path, that is, whether to add a line segment from the start point to the end point of the path. The value **true** means to close the path, and **false** means the opposite.|
897e41f4b71Sopenharmony_ci
898e41f4b71Sopenharmony_ci**Error codes**
899e41f4b71Sopenharmony_ci
900e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
901e41f4b71Sopenharmony_ci
902e41f4b71Sopenharmony_ci| ID| Error Message|
903e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
904e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
905e41f4b71Sopenharmony_ci
906e41f4b71Sopenharmony_ci**Example**
907e41f4b71Sopenharmony_ci
908e41f4b71Sopenharmony_ci```ts
909e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
910e41f4b71Sopenharmony_ci
911e41f4b71Sopenharmony_cilet pointsArray = new Array<common2D.Point>();
912e41f4b71Sopenharmony_ciconst point1: common2D.Point = { x: 200, y: 200 };
913e41f4b71Sopenharmony_ciconst point2: common2D.Point = { x: 400, y: 200 };
914e41f4b71Sopenharmony_ciconst point3: common2D.Point = { x: 100, y: 400 };
915e41f4b71Sopenharmony_ciconst point4: common2D.Point = { x: 300, y: 400 };
916e41f4b71Sopenharmony_cipointsArray.push(point1);
917e41f4b71Sopenharmony_cipointsArray.push(point2);
918e41f4b71Sopenharmony_cipointsArray.push(point3);
919e41f4b71Sopenharmony_cipointsArray.push(point4);
920e41f4b71Sopenharmony_ciconst path = new drawing.Path();
921e41f4b71Sopenharmony_cipath.addPolygon(pointsArray, false);
922e41f4b71Sopenharmony_ci```
923e41f4b71Sopenharmony_ci
924e41f4b71Sopenharmony_ci### offset<sup>12+</sup>
925e41f4b71Sopenharmony_ci
926e41f4b71Sopenharmony_cioffset(dx: number, dy: number): Path
927e41f4b71Sopenharmony_ci
928e41f4b71Sopenharmony_ciOffsets this path by specified distances along the X axis and Y axis and stores the resulting path in the **Path** object returned.
929e41f4b71Sopenharmony_ci
930e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
931e41f4b71Sopenharmony_ci
932e41f4b71Sopenharmony_ci**Parameters**
933e41f4b71Sopenharmony_ci
934e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                   |
935e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------- |
936e41f4b71Sopenharmony_ci| dx     | number        | Yes  | X offset. A positive number indicates an offset towards the positive direction of the X axis, and a negative number indicates an offset towards the negative direction of the X axis. The value is a floating point number.|
937e41f4b71Sopenharmony_ci| dy     | number        | Yes  | Y offset. A positive number indicates an offset towards the positive direction of the Y axis, and a negative number indicates an offset towards the negative direction of the Y axis. The value is a floating point number.|
938e41f4b71Sopenharmony_ci
939e41f4b71Sopenharmony_ci**Return value**
940e41f4b71Sopenharmony_ci
941e41f4b71Sopenharmony_ci| Type  | Description               |
942e41f4b71Sopenharmony_ci| ------ | ------------------ |
943e41f4b71Sopenharmony_ci| [Path](#path) | New path generated.|
944e41f4b71Sopenharmony_ci
945e41f4b71Sopenharmony_ci**Error codes**
946e41f4b71Sopenharmony_ci
947e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
948e41f4b71Sopenharmony_ci
949e41f4b71Sopenharmony_ci| ID| Error Message|
950e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
951e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
952e41f4b71Sopenharmony_ci
953e41f4b71Sopenharmony_ci**Example**
954e41f4b71Sopenharmony_ci
955e41f4b71Sopenharmony_ci```ts
956e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
957e41f4b71Sopenharmony_ci
958e41f4b71Sopenharmony_ciconst path = new drawing.Path();
959e41f4b71Sopenharmony_cipath.moveTo(200, 200);
960e41f4b71Sopenharmony_cipath.lineTo(300, 300);
961e41f4b71Sopenharmony_ciconst dst = path.offset(200, 200);
962e41f4b71Sopenharmony_ci```
963e41f4b71Sopenharmony_ci
964e41f4b71Sopenharmony_ci### op<sup>12+</sup>
965e41f4b71Sopenharmony_ci
966e41f4b71Sopenharmony_ciop(path: Path, pathOp: PathOp): boolean
967e41f4b71Sopenharmony_ci
968e41f4b71Sopenharmony_ciCombines this path with the passed-in path based on the specified operation mode.
969e41f4b71Sopenharmony_ci
970e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
971e41f4b71Sopenharmony_ci
972e41f4b71Sopenharmony_ci**Parameters**
973e41f4b71Sopenharmony_ci
974e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                   |
975e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------- |
976e41f4b71Sopenharmony_ci| path    | [Path](#path) | Yes  | Path object, which will be combined with the current path.|
977e41f4b71Sopenharmony_ci| pathOp  | [PathOp](#pathop12)   | Yes   | Operation mode.   |
978e41f4b71Sopenharmony_ci
979e41f4b71Sopenharmony_ci**Return value**
980e41f4b71Sopenharmony_ci
981e41f4b71Sopenharmony_ci| Type  | Description               |
982e41f4b71Sopenharmony_ci| ------ | ------------------ |
983e41f4b71Sopenharmony_ci| boolean | Result of the path combination result. The value **true** means that the path combination is successful, and **false** means the opposite.|
984e41f4b71Sopenharmony_ci
985e41f4b71Sopenharmony_ci**Error codes**
986e41f4b71Sopenharmony_ci
987e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
988e41f4b71Sopenharmony_ci
989e41f4b71Sopenharmony_ci| ID| Error Message|
990e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
991e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
992e41f4b71Sopenharmony_ci
993e41f4b71Sopenharmony_ci**Example**
994e41f4b71Sopenharmony_ci
995e41f4b71Sopenharmony_ci```ts
996e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
997e41f4b71Sopenharmony_ci
998e41f4b71Sopenharmony_ciconst path = new drawing.Path();
999e41f4b71Sopenharmony_ciconst path2 = new drawing.Path();
1000e41f4b71Sopenharmony_cipath.addCircle(100, 200, 100, drawing.PathDirection.CLOCKWISE);
1001e41f4b71Sopenharmony_ciconsole.info("get pathOp: ", path2.op(path, drawing.PathOp.DIFFERENCE));
1002e41f4b71Sopenharmony_ci```
1003e41f4b71Sopenharmony_ci
1004e41f4b71Sopenharmony_ci### close
1005e41f4b71Sopenharmony_ci
1006e41f4b71Sopenharmony_ciclose(): void
1007e41f4b71Sopenharmony_ci
1008e41f4b71Sopenharmony_ciDraws a line segment from the current point to the start point of this path.
1009e41f4b71Sopenharmony_ci
1010e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1011e41f4b71Sopenharmony_ci
1012e41f4b71Sopenharmony_ci**Example**
1013e41f4b71Sopenharmony_ci
1014e41f4b71Sopenharmony_ci```ts
1015e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
1016e41f4b71Sopenharmony_cilet path = new drawing.Path();
1017e41f4b71Sopenharmony_cipath.moveTo(10,10);
1018e41f4b71Sopenharmony_cipath.cubicTo(10, 10, 10, 10, 15, 15);
1019e41f4b71Sopenharmony_cipath.close();
1020e41f4b71Sopenharmony_ci```
1021e41f4b71Sopenharmony_ci
1022e41f4b71Sopenharmony_ci### reset
1023e41f4b71Sopenharmony_ci
1024e41f4b71Sopenharmony_cireset(): void
1025e41f4b71Sopenharmony_ci
1026e41f4b71Sopenharmony_ciResets the path data.
1027e41f4b71Sopenharmony_ci
1028e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1029e41f4b71Sopenharmony_ci
1030e41f4b71Sopenharmony_ci**Example**
1031e41f4b71Sopenharmony_ci
1032e41f4b71Sopenharmony_ci```ts
1033e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
1034e41f4b71Sopenharmony_cilet path = new drawing.Path();
1035e41f4b71Sopenharmony_cipath.moveTo(10,10);
1036e41f4b71Sopenharmony_cipath.cubicTo(10, 10, 10, 10, 15, 15);
1037e41f4b71Sopenharmony_cipath.reset();
1038e41f4b71Sopenharmony_ci```
1039e41f4b71Sopenharmony_ci
1040e41f4b71Sopenharmony_ci### getLength<sup>12+</sup>
1041e41f4b71Sopenharmony_ci
1042e41f4b71Sopenharmony_cigetLength(forceClosed: boolean): number
1043e41f4b71Sopenharmony_ci
1044e41f4b71Sopenharmony_ciObtains the path length.
1045e41f4b71Sopenharmony_ci
1046e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1047e41f4b71Sopenharmony_ci
1048e41f4b71Sopenharmony_ci**Parameters**
1049e41f4b71Sopenharmony_ci
1050e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description    |
1051e41f4b71Sopenharmony_ci| ----- | ------ | ---- | --------- |
1052e41f4b71Sopenharmony_ci| forceClosed  | boolean | Yes | Whether the path is measured as a closed path. The value **true** means that the path is considered closed during measurement, and **false** means that the path is measured based on the actual closed status.|
1053e41f4b71Sopenharmony_ci
1054e41f4b71Sopenharmony_ci**Return value**
1055e41f4b71Sopenharmony_ci
1056e41f4b71Sopenharmony_ci| Type | Description|
1057e41f4b71Sopenharmony_ci| ------ | ---- |
1058e41f4b71Sopenharmony_ci| number | Path length.|
1059e41f4b71Sopenharmony_ci
1060e41f4b71Sopenharmony_ci**Example**
1061e41f4b71Sopenharmony_ci
1062e41f4b71Sopenharmony_ci```ts
1063e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D'
1064e41f4b71Sopenharmony_cilet path = new drawing.Path();
1065e41f4b71Sopenharmony_cipath.arcTo(20, 20, 180, 180, 180, 90);
1066e41f4b71Sopenharmony_cilet len = path.getLength(false);
1067e41f4b71Sopenharmony_ciconsole.info("path length = " + len);
1068e41f4b71Sopenharmony_ci```
1069e41f4b71Sopenharmony_ci
1070e41f4b71Sopenharmony_ci### getPositionAndTangent<sup>12+</sup>
1071e41f4b71Sopenharmony_ci
1072e41f4b71Sopenharmony_cigetPositionAndTangent(forceClosed: boolean, distance: number, position: common2D.Point, tangent: common2D.Point): boolean
1073e41f4b71Sopenharmony_ci
1074e41f4b71Sopenharmony_ciObtains the coordinates and tangent at a distance from the start point of this path.
1075e41f4b71Sopenharmony_ci
1076e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1077e41f4b71Sopenharmony_ci
1078e41f4b71Sopenharmony_ci**Parameters**
1079e41f4b71Sopenharmony_ci
1080e41f4b71Sopenharmony_ci| Name  | Type                                        | Mandatory| Description                           |
1081e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | ---- | ------------------------------- |
1082e41f4b71Sopenharmony_ci| forceClosed | boolean | Yes  | Whether the path is measured as a closed path. The value **true** means that the path is considered closed during measurement, and **false** means that the path is measured based on the actual closed status.                |
1083e41f4b71Sopenharmony_ci| distance | number | Yes  | Distance from the start point. If a negative number is passed in, the value **0** is used. If a value greater than the path length is passed in, the path length is used. The value is a floating point number.              |
1084e41f4b71Sopenharmony_ci| position | [common2D.Point](js-apis-graphics-common2D.md#point) | Yes  | Coordinates obtained.                 |
1085e41f4b71Sopenharmony_ci| tangent | [common2D.Point](js-apis-graphics-common2D.md#point) | Yes  | Tangent obtained, where **tangent.x** and **tangent.y** represent the cosine and sine of the tangent of the point, respectively.                |
1086e41f4b71Sopenharmony_ci
1087e41f4b71Sopenharmony_ci**Return value**
1088e41f4b71Sopenharmony_ci
1089e41f4b71Sopenharmony_ci| Type                 | Description          |
1090e41f4b71Sopenharmony_ci| --------------------- | -------------- |
1091e41f4b71Sopenharmony_ci| boolean |Result indicating whether the coordinates and tangent of the point are obtained. The value **true** means that they are obtained, and **false** means the opposite. The values of **position** and **tangent** are not changed.|
1092e41f4b71Sopenharmony_ci
1093e41f4b71Sopenharmony_ci**Error codes**
1094e41f4b71Sopenharmony_ci
1095e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1096e41f4b71Sopenharmony_ci
1097e41f4b71Sopenharmony_ci| ID| Error Message|
1098e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
1099e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
1100e41f4b71Sopenharmony_ci
1101e41f4b71Sopenharmony_ci**Example**
1102e41f4b71Sopenharmony_ci
1103e41f4b71Sopenharmony_ci```ts
1104e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
1105e41f4b71Sopenharmony_cilet path: drawing.Path = new drawing.Path();
1106e41f4b71Sopenharmony_cipath.moveTo(0, 0);
1107e41f4b71Sopenharmony_cipath.lineTo(0, 700);
1108e41f4b71Sopenharmony_cipath.lineTo(700, 0);
1109e41f4b71Sopenharmony_cilet position: common2D.Point = { x: 0.0, y: 0.0 };
1110e41f4b71Sopenharmony_cilet tangent: common2D.Point = { x: 0.0, y: 0.0 };
1111e41f4b71Sopenharmony_ciif (path.getPositionAndTangent(false, 0.1, position, tangent)) {
1112e41f4b71Sopenharmony_ci  console.info("getPositionAndTangent-----position:  "+ position.x);
1113e41f4b71Sopenharmony_ci  console.info("getPositionAndTangent-----position:  "+ position.y);
1114e41f4b71Sopenharmony_ci  console.info("getPositionAndTangent-----tangent:  "+ tangent.x);
1115e41f4b71Sopenharmony_ci  console.info("getPositionAndTangent-----tangent:  "+ tangent.y);
1116e41f4b71Sopenharmony_ci}
1117e41f4b71Sopenharmony_ci```
1118e41f4b71Sopenharmony_ci
1119e41f4b71Sopenharmony_ci### isClosed<sup>12+</sup>
1120e41f4b71Sopenharmony_ci
1121e41f4b71Sopenharmony_ciisClosed(): boolean
1122e41f4b71Sopenharmony_ci
1123e41f4b71Sopenharmony_ciChecks whether a path is closed.
1124e41f4b71Sopenharmony_ci
1125e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1126e41f4b71Sopenharmony_ci
1127e41f4b71Sopenharmony_ci**Return value**
1128e41f4b71Sopenharmony_ci
1129e41f4b71Sopenharmony_ci| Type                 | Description          |
1130e41f4b71Sopenharmony_ci| --------------------- | -------------- |
1131e41f4b71Sopenharmony_ci| boolean | Result indicating whether the path is closed. The value **true** means that the path is closed, and **false** means the opposite.|
1132e41f4b71Sopenharmony_ci
1133e41f4b71Sopenharmony_ci**Example**
1134e41f4b71Sopenharmony_ci
1135e41f4b71Sopenharmony_ci```ts
1136e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
1137e41f4b71Sopenharmony_cilet path: drawing.Path = new drawing.Path();
1138e41f4b71Sopenharmony_cipath.moveTo(0, 0);
1139e41f4b71Sopenharmony_cipath.lineTo(0, 700);
1140e41f4b71Sopenharmony_ciif (path.isClosed()) {
1141e41f4b71Sopenharmony_ci  console.info("path is closed.");
1142e41f4b71Sopenharmony_ci} else {
1143e41f4b71Sopenharmony_ci  console.info("path is not closed.");
1144e41f4b71Sopenharmony_ci}
1145e41f4b71Sopenharmony_ci```
1146e41f4b71Sopenharmony_ci
1147e41f4b71Sopenharmony_ci### getMatrix<sup>12+</sup>
1148e41f4b71Sopenharmony_ci
1149e41f4b71Sopenharmony_cigetMatrix(forceClosed: boolean, distance: number, matrix: Matrix, flags: PathMeasureMatrixFlags): boolean
1150e41f4b71Sopenharmony_ci
1151e41f4b71Sopenharmony_ciObtains a transformation matrix at a distance from the start point of this path.
1152e41f4b71Sopenharmony_ci
1153e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1154e41f4b71Sopenharmony_ci
1155e41f4b71Sopenharmony_ci**Parameters**
1156e41f4b71Sopenharmony_ci
1157e41f4b71Sopenharmony_ci| Name  | Type                                        | Mandatory| Description                           |
1158e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | ---- | ------------------------------- |
1159e41f4b71Sopenharmony_ci| forceClosed | boolean | Yes  | Whether the path is measured as a closed path. The value **true** means that the path is considered closed during measurement, and **false** means that the path is measured based on the actual closed status.                 |
1160e41f4b71Sopenharmony_ci| distance | number | Yes  | Distance from the start point. If a negative number is passed in, the value **0** is used. If a value greater than the path length is passed in, the path length is used. The value is a floating point number.                 |
1161e41f4b71Sopenharmony_ci| matrix | [Matrix](#matrix12) | Yes  | **Matrix** object used to store the matrix obtained.                 |
1162e41f4b71Sopenharmony_ci| flags | [PathMeasureMatrixFlags](#pathmeasurematrixflags12) | Yes  | Type of the matrix information obtained.                 |
1163e41f4b71Sopenharmony_ci
1164e41f4b71Sopenharmony_ci**Return value**
1165e41f4b71Sopenharmony_ci
1166e41f4b71Sopenharmony_ci| Type                 | Description          |
1167e41f4b71Sopenharmony_ci| --------------------- | -------------- |
1168e41f4b71Sopenharmony_ci| boolean | Result indicating whether a transformation matrix is obtained. The value **true** means that a transformation matrix is obtained, and **false** means the opposite.|
1169e41f4b71Sopenharmony_ci
1170e41f4b71Sopenharmony_ci**Error codes**
1171e41f4b71Sopenharmony_ci
1172e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1173e41f4b71Sopenharmony_ci
1174e41f4b71Sopenharmony_ci| ID| Error Message|
1175e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
1176e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. |
1177e41f4b71Sopenharmony_ci
1178e41f4b71Sopenharmony_ci**Example**
1179e41f4b71Sopenharmony_ci
1180e41f4b71Sopenharmony_ci```ts
1181e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
1182e41f4b71Sopenharmony_cilet path: drawing.Path = new drawing.Path();
1183e41f4b71Sopenharmony_cilet matrix = new drawing.Matrix();
1184e41f4b71Sopenharmony_ciif(path.getMatrix(false, 10, matrix, drawing.PathMeasureMatrixFlags.GET_TANGENT_MATRIX)) {
1185e41f4b71Sopenharmony_ci  console.info("path.getMatrix return true");
1186e41f4b71Sopenharmony_ci} else {
1187e41f4b71Sopenharmony_ci  console.info("path.getMatrix return false");
1188e41f4b71Sopenharmony_ci}
1189e41f4b71Sopenharmony_ci```
1190e41f4b71Sopenharmony_ci
1191e41f4b71Sopenharmony_ci### buildFromSvgString<sup>12+</sup>
1192e41f4b71Sopenharmony_ci
1193e41f4b71Sopenharmony_cibuildFromSvgString(str: string): boolean
1194e41f4b71Sopenharmony_ci
1195e41f4b71Sopenharmony_ciParses the path represented by an SVG string.
1196e41f4b71Sopenharmony_ci
1197e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1198e41f4b71Sopenharmony_ci
1199e41f4b71Sopenharmony_ci**Parameters**
1200e41f4b71Sopenharmony_ci
1201e41f4b71Sopenharmony_ci| Name  | Type                                        | Mandatory| Description                           |
1202e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | ---- | ------------------------------- |
1203e41f4b71Sopenharmony_ci| str | string | Yes  | String in SVG format, which is used to describe the path.                |
1204e41f4b71Sopenharmony_ci
1205e41f4b71Sopenharmony_ci**Return value**
1206e41f4b71Sopenharmony_ci
1207e41f4b71Sopenharmony_ci| Type                 | Description          |
1208e41f4b71Sopenharmony_ci| --------------------- | -------------- |
1209e41f4b71Sopenharmony_ci| boolean | Result indicating whether the SVG string is parsed. The value **true** means that the parsing is successful, and **false** means the opposite.|
1210e41f4b71Sopenharmony_ci
1211e41f4b71Sopenharmony_ci**Error codes**
1212e41f4b71Sopenharmony_ci
1213e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1214e41f4b71Sopenharmony_ci
1215e41f4b71Sopenharmony_ci| ID| Error Message|
1216e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
1217e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. |
1218e41f4b71Sopenharmony_ci
1219e41f4b71Sopenharmony_ci**Example**
1220e41f4b71Sopenharmony_ci
1221e41f4b71Sopenharmony_ci```ts
1222e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
1223e41f4b71Sopenharmony_cilet path: drawing.Path = new drawing.Path();
1224e41f4b71Sopenharmony_cilet svgStr: string =  "M150 100 L75 300 L225 300 Z";
1225e41f4b71Sopenharmony_ciif(path.buildFromSvgString(svgStr)) {
1226e41f4b71Sopenharmony_ci  console.info("buildFromSvgString return true");
1227e41f4b71Sopenharmony_ci} else {
1228e41f4b71Sopenharmony_ci  console.info("buildFromSvgString return false");
1229e41f4b71Sopenharmony_ci}
1230e41f4b71Sopenharmony_ci```
1231e41f4b71Sopenharmony_ci
1232e41f4b71Sopenharmony_ci## Canvas
1233e41f4b71Sopenharmony_ci
1234e41f4b71Sopenharmony_ciA carrier that carries the drawn content and drawing status.
1235e41f4b71Sopenharmony_ci
1236e41f4b71Sopenharmony_ci> **NOTE**
1237e41f4b71Sopenharmony_ci>
1238e41f4b71Sopenharmony_ci> By default, the canvas has a black brush with anti-aliasing enabled but no any other style. This default brush takes effect only when no brush or pen is proactively set in the canvas.
1239e41f4b71Sopenharmony_ci
1240e41f4b71Sopenharmony_ci### constructor
1241e41f4b71Sopenharmony_ci
1242e41f4b71Sopenharmony_ciconstructor(pixelmap: image.PixelMap)
1243e41f4b71Sopenharmony_ci
1244e41f4b71Sopenharmony_ciA constructor used to create a **Canvas** object.
1245e41f4b71Sopenharmony_ci
1246e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1247e41f4b71Sopenharmony_ci
1248e41f4b71Sopenharmony_ci**Parameters**
1249e41f4b71Sopenharmony_ci
1250e41f4b71Sopenharmony_ci| Name  | Type                                        | Mandatory| Description          |
1251e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | ---- | -------------- |
1252e41f4b71Sopenharmony_ci| pixelmap | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | Yes  | Pixel map used to create the object.|
1253e41f4b71Sopenharmony_ci
1254e41f4b71Sopenharmony_ci**Error codes**
1255e41f4b71Sopenharmony_ci
1256e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1257e41f4b71Sopenharmony_ci
1258e41f4b71Sopenharmony_ci| ID| Error Message|
1259e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
1260e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
1261e41f4b71Sopenharmony_ci
1262e41f4b71Sopenharmony_ci**Example**
1263e41f4b71Sopenharmony_ci
1264e41f4b71Sopenharmony_ci```ts
1265e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
1266e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
1267e41f4b71Sopenharmony_ciconst color = new ArrayBuffer(96);
1268e41f4b71Sopenharmony_cilet opts : image.InitializationOptions = {
1269e41f4b71Sopenharmony_ci  editable: true,
1270e41f4b71Sopenharmony_ci  pixelFormat: 3,
1271e41f4b71Sopenharmony_ci  size: {
1272e41f4b71Sopenharmony_ci    height: 4,
1273e41f4b71Sopenharmony_ci    width: 6
1274e41f4b71Sopenharmony_ci  }
1275e41f4b71Sopenharmony_ci}
1276e41f4b71Sopenharmony_ciimage.createPixelMap(color, opts).then((pixelMap) => {
1277e41f4b71Sopenharmony_ci  const canvas = new drawing.Canvas(pixelMap);
1278e41f4b71Sopenharmony_ci})
1279e41f4b71Sopenharmony_ci```
1280e41f4b71Sopenharmony_ci
1281e41f4b71Sopenharmony_ci### drawRect
1282e41f4b71Sopenharmony_ci
1283e41f4b71Sopenharmony_cidrawRect(rect: common2D.Rect): void
1284e41f4b71Sopenharmony_ci
1285e41f4b71Sopenharmony_ciDraws a rectangle. By default, black is used for filling.
1286e41f4b71Sopenharmony_ci
1287e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1288e41f4b71Sopenharmony_ci
1289e41f4b71Sopenharmony_ci**Parameters**
1290e41f4b71Sopenharmony_ci
1291e41f4b71Sopenharmony_ci| Name| Type                                              | Mandatory| Description          |
1292e41f4b71Sopenharmony_ci| ------ | -------------------------------------------------- | ---- | -------------- |
1293e41f4b71Sopenharmony_ci| rect   | [common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes  | Rectangle to draw.|
1294e41f4b71Sopenharmony_ci
1295e41f4b71Sopenharmony_ci**Error codes**
1296e41f4b71Sopenharmony_ci
1297e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1298e41f4b71Sopenharmony_ci
1299e41f4b71Sopenharmony_ci| ID| Error Message|
1300e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
1301e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
1302e41f4b71Sopenharmony_ci
1303e41f4b71Sopenharmony_ci**Example**
1304e41f4b71Sopenharmony_ci
1305e41f4b71Sopenharmony_ci```ts
1306e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
1307e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
1308e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
1309e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
1310e41f4b71Sopenharmony_ci    const canvas = context.canvas;
1311e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
1312e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
1313e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
1314e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
1315e41f4b71Sopenharmony_ci    canvas.drawRect({ left : 0, right : 10, top : 0, bottom : 10 });
1316e41f4b71Sopenharmony_ci    canvas.detachPen();
1317e41f4b71Sopenharmony_ci  }
1318e41f4b71Sopenharmony_ci}
1319e41f4b71Sopenharmony_ci```
1320e41f4b71Sopenharmony_ci
1321e41f4b71Sopenharmony_ci### drawRect<sup>12+</sup>
1322e41f4b71Sopenharmony_ci
1323e41f4b71Sopenharmony_cidrawRect(left: number, top: number, right: number, bottom: number): void
1324e41f4b71Sopenharmony_ci
1325e41f4b71Sopenharmony_ciDraws a rectangle. By default, black is used for filling. This API provides better performance than [drawRect](#drawrect) and is recommended.
1326e41f4b71Sopenharmony_ci
1327e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1328e41f4b71Sopenharmony_ci
1329e41f4b71Sopenharmony_ci**Parameters**
1330e41f4b71Sopenharmony_ci
1331e41f4b71Sopenharmony_ci| Name| Type   | Mandatory| Description          |
1332e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------- |
1333e41f4b71Sopenharmony_ci| left   | number | Yes  | X coordinate of the upper left corner of the rectangle. The value is a floating point number.|
1334e41f4b71Sopenharmony_ci| top    | number | Yes  | Y coordinate of the upper left corner of the rectangle. The value is a floating point number.|
1335e41f4b71Sopenharmony_ci| right  | number | Yes  | X coordinate of the lower right corner of the rectangle. The value is a floating point number.|
1336e41f4b71Sopenharmony_ci| bottom | number | Yes  | Y coordinate of the lower right corner of the rectangle. The value is a floating point number.|
1337e41f4b71Sopenharmony_ci
1338e41f4b71Sopenharmony_ci**Error codes**
1339e41f4b71Sopenharmony_ci
1340e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1341e41f4b71Sopenharmony_ci
1342e41f4b71Sopenharmony_ci| ID| Error Message|
1343e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
1344e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
1345e41f4b71Sopenharmony_ci
1346e41f4b71Sopenharmony_ci**Example**
1347e41f4b71Sopenharmony_ci
1348e41f4b71Sopenharmony_ci```ts
1349e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
1350e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
1351e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
1352e41f4b71Sopenharmony_ci
1353e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
1354e41f4b71Sopenharmony_ci    const canvas = context.canvas;
1355e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
1356e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
1357e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
1358e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
1359e41f4b71Sopenharmony_ci    canvas.drawRect(0, 0, 10, 10);
1360e41f4b71Sopenharmony_ci    canvas.detachPen();
1361e41f4b71Sopenharmony_ci  }
1362e41f4b71Sopenharmony_ci}
1363e41f4b71Sopenharmony_ci```
1364e41f4b71Sopenharmony_ci
1365e41f4b71Sopenharmony_ci### drawRoundRect<sup>12+</sup>
1366e41f4b71Sopenharmony_ci
1367e41f4b71Sopenharmony_cidrawRoundRect(roundRect: RoundRect): void
1368e41f4b71Sopenharmony_ci
1369e41f4b71Sopenharmony_ciDraws a rounded rectangle.
1370e41f4b71Sopenharmony_ci
1371e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1372e41f4b71Sopenharmony_ci
1373e41f4b71Sopenharmony_ci**Parameters**
1374e41f4b71Sopenharmony_ci
1375e41f4b71Sopenharmony_ci| Name    | Type                   | Mandatory| Description      |
1376e41f4b71Sopenharmony_ci| ---------- | ----------------------- | ---- | ------------ |
1377e41f4b71Sopenharmony_ci| roundRect  | [RoundRect](#roundrect12) | Yes  | Rounded rectangle.|
1378e41f4b71Sopenharmony_ci
1379e41f4b71Sopenharmony_ci**Error codes**
1380e41f4b71Sopenharmony_ci
1381e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1382e41f4b71Sopenharmony_ci
1383e41f4b71Sopenharmony_ci| ID| Error Message|
1384e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
1385e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
1386e41f4b71Sopenharmony_ci
1387e41f4b71Sopenharmony_ci**Example**
1388e41f4b71Sopenharmony_ci
1389e41f4b71Sopenharmony_ci```ts
1390e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
1391e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
1392e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
1393e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
1394e41f4b71Sopenharmony_ci    const canvas = context.canvas;
1395e41f4b71Sopenharmony_ci    let rect: common2D.Rect = { left : 100, top : 100, right : 400, bottom : 500 };
1396e41f4b71Sopenharmony_ci    let roundRect = new drawing.RoundRect(rect, 10, 10);
1397e41f4b71Sopenharmony_ci    canvas.drawRoundRect(roundRect);
1398e41f4b71Sopenharmony_ci  }
1399e41f4b71Sopenharmony_ci}
1400e41f4b71Sopenharmony_ci```
1401e41f4b71Sopenharmony_ci
1402e41f4b71Sopenharmony_ci### drawNestedRoundRect<sup>12+</sup>
1403e41f4b71Sopenharmony_ci
1404e41f4b71Sopenharmony_cidrawNestedRoundRect(outer: RoundRect, inner: RoundRect): void
1405e41f4b71Sopenharmony_ci
1406e41f4b71Sopenharmony_ciDraws two nested rounded rectangles. The outer rectangle boundary must contain the inner rectangle boundary. Otherwise, there is no drawing effect.
1407e41f4b71Sopenharmony_ci
1408e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1409e41f4b71Sopenharmony_ci
1410e41f4b71Sopenharmony_ci**Parameters**
1411e41f4b71Sopenharmony_ci
1412e41f4b71Sopenharmony_ci| Name | Type                   | Mandatory| Description      |
1413e41f4b71Sopenharmony_ci| ------ | ----------------------- | ---- | ------------ |
1414e41f4b71Sopenharmony_ci| outer  | [RoundRect](#roundrect12) | Yes  | Outer rounded rectangle.|
1415e41f4b71Sopenharmony_ci| inner  | [RoundRect](#roundrect12) | Yes  | Inner rounded rectangle.|
1416e41f4b71Sopenharmony_ci
1417e41f4b71Sopenharmony_ci**Error codes**
1418e41f4b71Sopenharmony_ci
1419e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1420e41f4b71Sopenharmony_ci
1421e41f4b71Sopenharmony_ci| ID| Error Message|
1422e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
1423e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
1424e41f4b71Sopenharmony_ci
1425e41f4b71Sopenharmony_ci**Example**
1426e41f4b71Sopenharmony_ci
1427e41f4b71Sopenharmony_ci```ts
1428e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
1429e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
1430e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
1431e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
1432e41f4b71Sopenharmony_ci    const canvas = context.canvas;
1433e41f4b71Sopenharmony_ci    let inRect: common2D.Rect = { left : 200, top : 200, right : 400, bottom : 500 };
1434e41f4b71Sopenharmony_ci    let outRect: common2D.Rect = { left : 100, top : 100, right : 400, bottom : 500 };
1435e41f4b71Sopenharmony_ci    let outRoundRect = new drawing.RoundRect(outRect, 10, 10);
1436e41f4b71Sopenharmony_ci    let inRoundRect = new drawing.RoundRect(inRect, 10, 10);
1437e41f4b71Sopenharmony_ci    canvas.drawNestedRoundRect(outRoundRect, inRoundRect);
1438e41f4b71Sopenharmony_ci    canvas.drawRoundRect(outRoundRect);
1439e41f4b71Sopenharmony_ci  }
1440e41f4b71Sopenharmony_ci}
1441e41f4b71Sopenharmony_ci```
1442e41f4b71Sopenharmony_ci
1443e41f4b71Sopenharmony_ci### drawBackground<sup>12+</sup>
1444e41f4b71Sopenharmony_ci
1445e41f4b71Sopenharmony_cidrawBackground(brush: Brush): void
1446e41f4b71Sopenharmony_ci
1447e41f4b71Sopenharmony_ciUses a brush to fill the drawable area of the canvas.
1448e41f4b71Sopenharmony_ci
1449e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1450e41f4b71Sopenharmony_ci
1451e41f4b71Sopenharmony_ci**Parameters**
1452e41f4b71Sopenharmony_ci
1453e41f4b71Sopenharmony_ci| Name| Type           | Mandatory| Description      |
1454e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ---------- |
1455e41f4b71Sopenharmony_ci| brush  | [Brush](#brush) | Yes  | **Brush** object.|
1456e41f4b71Sopenharmony_ci
1457e41f4b71Sopenharmony_ci**Error codes**
1458e41f4b71Sopenharmony_ci
1459e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1460e41f4b71Sopenharmony_ci
1461e41f4b71Sopenharmony_ci| ID| Error Message|
1462e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
1463e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
1464e41f4b71Sopenharmony_ci
1465e41f4b71Sopenharmony_ci**Example**
1466e41f4b71Sopenharmony_ci
1467e41f4b71Sopenharmony_ci```ts
1468e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
1469e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
1470e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
1471e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
1472e41f4b71Sopenharmony_ci    const canvas = context.canvas;
1473e41f4b71Sopenharmony_ci    const brush = new drawing.Brush();
1474e41f4b71Sopenharmony_ci    const color : common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
1475e41f4b71Sopenharmony_ci    brush.setColor(color);
1476e41f4b71Sopenharmony_ci    canvas.drawBackground(brush);
1477e41f4b71Sopenharmony_ci  }
1478e41f4b71Sopenharmony_ci}
1479e41f4b71Sopenharmony_ci```
1480e41f4b71Sopenharmony_ci
1481e41f4b71Sopenharmony_ci### drawShadow<sup>12+</sup>
1482e41f4b71Sopenharmony_ci
1483e41f4b71Sopenharmony_cidrawShadow(path: Path, planeParams: common2D.Point3d, devLightPos: common2D.Point3d, lightRadius: number, ambientColor: common2D.Color, spotColor: common2D.Color, flag: ShadowFlag) : void
1484e41f4b71Sopenharmony_ci
1485e41f4b71Sopenharmony_ciDraws a spot shadow and uses a given path to outline the ambient shadow.
1486e41f4b71Sopenharmony_ci
1487e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1488e41f4b71Sopenharmony_ci
1489e41f4b71Sopenharmony_ci**Parameters**
1490e41f4b71Sopenharmony_ci
1491e41f4b71Sopenharmony_ci| Name         | Type                                      | Mandatory  | Description        |
1492e41f4b71Sopenharmony_ci| ------------ | ---------------------------------------- | ---- | ---------- |
1493e41f4b71Sopenharmony_ci| path | [Path](#path)                | Yes   | **Path** object, which is used to outline the shadow.|
1494e41f4b71Sopenharmony_ci| planeParams  | [common2D.Point3d](js-apis-graphics-common2D.md#point3d12) | Yes   | 3D vector, which is used to calculate the offset in the Z axis.|
1495e41f4b71Sopenharmony_ci| devLightPos  | [common2D.Point3d](js-apis-graphics-common2D.md#point3d12) | Yes   | Position of the light relative to the canvas.|
1496e41f4b71Sopenharmony_ci| lightRadius   | number           | Yes   | Radius of the light. The value is a floating point number.     |
1497e41f4b71Sopenharmony_ci| ambientColor  | [common2D.Color](js-apis-graphics-common2D.md#color) | Yes   | Color of the ambient shadow.|
1498e41f4b71Sopenharmony_ci| spotColor  | [common2D.Color](js-apis-graphics-common2D.md#color) | Yes   | Color of the spot shadow.|
1499e41f4b71Sopenharmony_ci| flag         | [ShadowFlag](#shadowflag12)                  | Yes   | Shadow flag.   |
1500e41f4b71Sopenharmony_ci
1501e41f4b71Sopenharmony_ci**Error codes**
1502e41f4b71Sopenharmony_ci
1503e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1504e41f4b71Sopenharmony_ci
1505e41f4b71Sopenharmony_ci| ID| Error Message|
1506e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
1507e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
1508e41f4b71Sopenharmony_ci
1509e41f4b71Sopenharmony_ci**Example**
1510e41f4b71Sopenharmony_ci
1511e41f4b71Sopenharmony_ci```ts
1512e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
1513e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
1514e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
1515e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
1516e41f4b71Sopenharmony_ci    const canvas = context.canvas;
1517e41f4b71Sopenharmony_ci    const path = new drawing.Path();
1518e41f4b71Sopenharmony_ci    path.addCircle(100, 200, 100, drawing.PathDirection.CLOCKWISE);
1519e41f4b71Sopenharmony_ci    let pen = new drawing.Pen();
1520e41f4b71Sopenharmony_ci    pen.setAntiAlias(true);
1521e41f4b71Sopenharmony_ci    let pen_color : common2D.Color = { alpha: 0xFF, red: 0xFF, green: 0x00, blue: 0x00 };
1522e41f4b71Sopenharmony_ci    pen.setColor(pen_color);
1523e41f4b71Sopenharmony_ci    pen.setStrokeWidth(10.0);
1524e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
1525e41f4b71Sopenharmony_ci    let brush = new drawing.Brush();
1526e41f4b71Sopenharmony_ci    let brush_color : common2D.Color = { alpha: 0xFF, red: 0x00, green: 0xFF, blue: 0x00 };
1527e41f4b71Sopenharmony_ci    brush.setColor(brush_color);
1528e41f4b71Sopenharmony_ci    canvas.attachBrush(brush);
1529e41f4b71Sopenharmony_ci    let point1 : common2D.Point3d = {x: 100, y: 80, z:80};
1530e41f4b71Sopenharmony_ci    let point2 : common2D.Point3d = {x: 200, y: 10, z:40};
1531e41f4b71Sopenharmony_ci    let color1 : common2D.Color = {alpha: 0xFF, red:0, green:0, blue:0xFF};
1532e41f4b71Sopenharmony_ci    let color2 : common2D.Color = {alpha: 0xFF, red:0xFF, green:0, blue:0};
1533e41f4b71Sopenharmony_ci    let shadowFlag : drawing.ShadowFlag = drawing.ShadowFlag.ALL;
1534e41f4b71Sopenharmony_ci    canvas.drawShadow(path, point1, point2, 30, color1, color2, shadowFlag);
1535e41f4b71Sopenharmony_ci  }
1536e41f4b71Sopenharmony_ci}
1537e41f4b71Sopenharmony_ci```
1538e41f4b71Sopenharmony_ci
1539e41f4b71Sopenharmony_ci### drawShadow<sup>13+</sup>
1540e41f4b71Sopenharmony_ci
1541e41f4b71Sopenharmony_cidrawShadow(path: Path, planeParams: common2D.Point3d, devLightPos: common2D.Point3d, lightRadius: number, ambientColor: number, spotColor: number, flag: ShadowFlag) : void
1542e41f4b71Sopenharmony_ci
1543e41f4b71Sopenharmony_ciDraws a spot shadow and uses a given path to outline the ambient shadow.
1544e41f4b71Sopenharmony_ci
1545e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1546e41f4b71Sopenharmony_ci
1547e41f4b71Sopenharmony_ci**Parameters**
1548e41f4b71Sopenharmony_ci
1549e41f4b71Sopenharmony_ci| Name         | Type                                      | Mandatory  | Description        |
1550e41f4b71Sopenharmony_ci| ------------ | ---------------------------------------- | ---- | ---------- |
1551e41f4b71Sopenharmony_ci| path | [Path](#path)                | Yes   | **Path** object, which is used to outline the shadow.|
1552e41f4b71Sopenharmony_ci| planeParams  | [common2D.Point3d](js-apis-graphics-common2D.md#point3d12) | Yes   | 3D vector, which is used to calculate the offset in the Z axis.|
1553e41f4b71Sopenharmony_ci| devLightPos  | [common2D.Point3d](js-apis-graphics-common2D.md#point3d12) | Yes   | Position of the light relative to the canvas.|
1554e41f4b71Sopenharmony_ci| lightRadius   | number           | Yes   | Radius of the light. The value is a floating point number.     |
1555e41f4b71Sopenharmony_ci| ambientColor  |number | Yes   | Ambient shadow color, represented by a 32-bit unsigned integer in hexadecimal ARGB format.|
1556e41f4b71Sopenharmony_ci| spotColor  |number | Yes   | Spot shadow color, represented by a 32-bit unsigned integer in hexadecimal ARGB format.|
1557e41f4b71Sopenharmony_ci| flag         | [ShadowFlag](#shadowflag12)                  | Yes   | Shadow flag.   |
1558e41f4b71Sopenharmony_ci
1559e41f4b71Sopenharmony_ci**Error codes**
1560e41f4b71Sopenharmony_ci
1561e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1562e41f4b71Sopenharmony_ci
1563e41f4b71Sopenharmony_ci| ID| Error Message|
1564e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
1565e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
1566e41f4b71Sopenharmony_ci
1567e41f4b71Sopenharmony_ci**Example**
1568e41f4b71Sopenharmony_ci
1569e41f4b71Sopenharmony_ci```ts
1570e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
1571e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
1572e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
1573e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
1574e41f4b71Sopenharmony_ci    const canvas = context.canvas;
1575e41f4b71Sopenharmony_ci    const path = new drawing.Path();
1576e41f4b71Sopenharmony_ci    path.addCircle(300, 600, 100, drawing.PathDirection.CLOCKWISE);
1577e41f4b71Sopenharmony_ci    let point1 : common2D.Point3d = {x: 100, y: 80, z:80};
1578e41f4b71Sopenharmony_ci    let point2 : common2D.Point3d = {x: 200, y: 10, z:40};
1579e41f4b71Sopenharmony_ci    let shadowFlag : drawing.ShadowFlag = drawing.ShadowFlag.ALL;
1580e41f4b71Sopenharmony_ci    canvas.drawShadow(path, point1, point2, 30, 0xFF0000FF, 0xFFFF0000, shadowFlag);
1581e41f4b71Sopenharmony_ci  }
1582e41f4b71Sopenharmony_ci}
1583e41f4b71Sopenharmony_ci```
1584e41f4b71Sopenharmony_ci
1585e41f4b71Sopenharmony_ci### getLocalClipBounds<sup>12+</sup>
1586e41f4b71Sopenharmony_ci
1587e41f4b71Sopenharmony_cigetLocalClipBounds(): common2D.Rect
1588e41f4b71Sopenharmony_ci
1589e41f4b71Sopenharmony_ciObtains the bounds of the cropping region of the canvas.
1590e41f4b71Sopenharmony_ci
1591e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1592e41f4b71Sopenharmony_ci
1593e41f4b71Sopenharmony_ci**Return value**
1594e41f4b71Sopenharmony_ci
1595e41f4b71Sopenharmony_ci| Type                                      | Description      |
1596e41f4b71Sopenharmony_ci| ---------------------------------------- | -------- |
1597e41f4b71Sopenharmony_ci| [common2D.Rect](js-apis-graphics-common2D.md#rect) | Bounds of the cropping region.|
1598e41f4b71Sopenharmony_ci
1599e41f4b71Sopenharmony_ci**Example**
1600e41f4b71Sopenharmony_ci
1601e41f4b71Sopenharmony_ci```ts
1602e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
1603e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
1604e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
1605e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
1606e41f4b71Sopenharmony_ci    const canvas = context.canvas;
1607e41f4b71Sopenharmony_ci    let clipRect: common2D.Rect = {
1608e41f4b71Sopenharmony_ci      left : 150, top : 150, right : 300, bottom : 400
1609e41f4b71Sopenharmony_ci    };
1610e41f4b71Sopenharmony_ci    canvas.clipRect(clipRect,drawing.ClipOp.DIFFERENCE, true);
1611e41f4b71Sopenharmony_ci    console.info("test rect.left: " + clipRect.left);
1612e41f4b71Sopenharmony_ci    console.info("test rect.top: " + clipRect.top);
1613e41f4b71Sopenharmony_ci    console.info("test rect.right: " + clipRect.right);
1614e41f4b71Sopenharmony_ci    console.info("test rect.bottom: " + clipRect.bottom);
1615e41f4b71Sopenharmony_ci    canvas.getLocalClipBounds();
1616e41f4b71Sopenharmony_ci  }
1617e41f4b71Sopenharmony_ci}
1618e41f4b71Sopenharmony_ci```
1619e41f4b71Sopenharmony_ci
1620e41f4b71Sopenharmony_ci### getTotalMatrix<sup>12+</sup>
1621e41f4b71Sopenharmony_ci
1622e41f4b71Sopenharmony_cigetTotalMatrix(): Matrix
1623e41f4b71Sopenharmony_ci
1624e41f4b71Sopenharmony_ciObtains the canvas matrix.
1625e41f4b71Sopenharmony_ci
1626e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1627e41f4b71Sopenharmony_ci
1628e41f4b71Sopenharmony_ci**Return value**
1629e41f4b71Sopenharmony_ci
1630e41f4b71Sopenharmony_ci| Type               | Description      |
1631e41f4b71Sopenharmony_ci| ----------------- | -------- |
1632e41f4b71Sopenharmony_ci| [Matrix](#matrix12) |Canvas matrix.|
1633e41f4b71Sopenharmony_ci
1634e41f4b71Sopenharmony_ci**Example**
1635e41f4b71Sopenharmony_ci
1636e41f4b71Sopenharmony_ci```ts
1637e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
1638e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
1639e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
1640e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
1641e41f4b71Sopenharmony_ci    const canvas = context.canvas;
1642e41f4b71Sopenharmony_ci    let matrix = new drawing.Matrix();
1643e41f4b71Sopenharmony_ci    matrix.setMatrix([5, 0, 0, 0, 1, 1, 0, 0, 1]);
1644e41f4b71Sopenharmony_ci    canvas.setMatrix(matrix);
1645e41f4b71Sopenharmony_ci    let matrixResult =canvas.getTotalMatrix();
1646e41f4b71Sopenharmony_ci  }
1647e41f4b71Sopenharmony_ci}
1648e41f4b71Sopenharmony_ci```
1649e41f4b71Sopenharmony_ci
1650e41f4b71Sopenharmony_ci### drawCircle
1651e41f4b71Sopenharmony_ci
1652e41f4b71Sopenharmony_cidrawCircle(x: number, y: number, radius: number): void
1653e41f4b71Sopenharmony_ci
1654e41f4b71Sopenharmony_ciDraws a circle. If the radius is less than or equal to zero, nothing is drawn. By default, black is used for filling.
1655e41f4b71Sopenharmony_ci
1656e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1657e41f4b71Sopenharmony_ci
1658e41f4b71Sopenharmony_ci**Parameters**
1659e41f4b71Sopenharmony_ci
1660e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description               |
1661e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------- |
1662e41f4b71Sopenharmony_ci| x      | number | Yes  | X coordinate of the center of the circle. The value is a floating point number.|
1663e41f4b71Sopenharmony_ci| y      | number | Yes  | Y coordinate of the center of the circle. The value is a floating point number.|
1664e41f4b71Sopenharmony_ci| radius | number | Yes  | Radius of the circle. The value is a floating point number greater than 0.|
1665e41f4b71Sopenharmony_ci
1666e41f4b71Sopenharmony_ci**Error codes**
1667e41f4b71Sopenharmony_ci
1668e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1669e41f4b71Sopenharmony_ci
1670e41f4b71Sopenharmony_ci| ID| Error Message|
1671e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
1672e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
1673e41f4b71Sopenharmony_ci
1674e41f4b71Sopenharmony_ci**Example**
1675e41f4b71Sopenharmony_ci
1676e41f4b71Sopenharmony_ci```ts
1677e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
1678e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
1679e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
1680e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
1681e41f4b71Sopenharmony_ci    const canvas = context.canvas;
1682e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
1683e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
1684e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
1685e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
1686e41f4b71Sopenharmony_ci    canvas.drawCircle(10, 10, 2);
1687e41f4b71Sopenharmony_ci    canvas.detachPen();
1688e41f4b71Sopenharmony_ci  }
1689e41f4b71Sopenharmony_ci}
1690e41f4b71Sopenharmony_ci```
1691e41f4b71Sopenharmony_ci
1692e41f4b71Sopenharmony_ci### drawImage
1693e41f4b71Sopenharmony_ci
1694e41f4b71Sopenharmony_cidrawImage(pixelmap: image.PixelMap, left: number, top: number, samplingOptions?: SamplingOptions): void
1695e41f4b71Sopenharmony_ci
1696e41f4b71Sopenharmony_ciDraws an image. The coordinates of the upper left corner of the image are (left, top).
1697e41f4b71Sopenharmony_ci
1698e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1699e41f4b71Sopenharmony_ci
1700e41f4b71Sopenharmony_ci**Parameters**
1701e41f4b71Sopenharmony_ci
1702e41f4b71Sopenharmony_ci| Name  | Type                                        | Mandatory| Description                           |
1703e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | ---- | ------------------------------- |
1704e41f4b71Sopenharmony_ci| pixelmap | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | Yes  | Pixel map of the image.                 |
1705e41f4b71Sopenharmony_ci| left     | number                                       | Yes  | X coordinate of the upper left corner of the image. The value is a floating point number.|
1706e41f4b71Sopenharmony_ci| top      | number                                       | Yes  | Y coordinate of the upper left corner of the image. The value is a floating point number.|
1707e41f4b71Sopenharmony_ci| samplingOptions<sup>12+</sup>  | [SamplingOptions](#samplingoptions12)  | No | Sampling options. By default, the **SamplingOptions** object created using the no-argument constructor is used.|
1708e41f4b71Sopenharmony_ci
1709e41f4b71Sopenharmony_ci**Error codes**
1710e41f4b71Sopenharmony_ci
1711e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1712e41f4b71Sopenharmony_ci
1713e41f4b71Sopenharmony_ci| ID| Error Message|
1714e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
1715e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
1716e41f4b71Sopenharmony_ci
1717e41f4b71Sopenharmony_ci**Example**
1718e41f4b71Sopenharmony_ci
1719e41f4b71Sopenharmony_ci```ts
1720e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
1721e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
1722e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
1723e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
1724e41f4b71Sopenharmony_ci  pixelMap: image.PixelMap | null = null;
1725e41f4b71Sopenharmony_ci
1726e41f4b71Sopenharmony_ci  async draw(context : DrawContext) {
1727e41f4b71Sopenharmony_ci    const canvas = context.canvas;
1728e41f4b71Sopenharmony_ci    let options = new drawing.SamplingOptions(drawing.FilterMode.FILTER_MODE_NEAREST);
1729e41f4b71Sopenharmony_ci    if (this.pixelMap != null) {
1730e41f4b71Sopenharmony_ci      canvas.drawImage(this.pixelMap, 0, 0, options);
1731e41f4b71Sopenharmony_ci    }
1732e41f4b71Sopenharmony_ci  }
1733e41f4b71Sopenharmony_ci}
1734e41f4b71Sopenharmony_ci```
1735e41f4b71Sopenharmony_ci
1736e41f4b71Sopenharmony_ci### drawImageRect<sup>12+</sup>
1737e41f4b71Sopenharmony_ci
1738e41f4b71Sopenharmony_cidrawImageRect(pixelmap: image.PixelMap, dstRect: common2D.Rect, samplingOptions?: SamplingOptions): void
1739e41f4b71Sopenharmony_ci
1740e41f4b71Sopenharmony_ciDraws an image onto a specified area of the canvas.
1741e41f4b71Sopenharmony_ci
1742e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1743e41f4b71Sopenharmony_ci
1744e41f4b71Sopenharmony_ci**Parameters**
1745e41f4b71Sopenharmony_ci
1746e41f4b71Sopenharmony_ci| Name  | Type                                        | Mandatory| Description                           |
1747e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | ---- | ------------------------------- |
1748e41f4b71Sopenharmony_ci| pixelmap | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | Yes  | Pixel map of the image.                |
1749e41f4b71Sopenharmony_ci| dstRect     | [common2D.Rect](js-apis-graphics-common2D.md#rect)                               | Yes  | **Rectangle** object, which specifies the area of the canvas onto which the image will be drawn.|
1750e41f4b71Sopenharmony_ci| samplingOptions     | [SamplingOptions](#samplingoptions12)                           | No  | Sampling options. By default, the **SamplingOptions** object created using the no-argument constructor is used.|
1751e41f4b71Sopenharmony_ci
1752e41f4b71Sopenharmony_ci**Error codes**
1753e41f4b71Sopenharmony_ci
1754e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1755e41f4b71Sopenharmony_ci
1756e41f4b71Sopenharmony_ci| ID| Error Message|
1757e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
1758e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
1759e41f4b71Sopenharmony_ci
1760e41f4b71Sopenharmony_ci**Example**
1761e41f4b71Sopenharmony_ci
1762e41f4b71Sopenharmony_ci```ts
1763e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
1764e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
1765e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
1766e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
1767e41f4b71Sopenharmony_cipixelMap: image.PixelMap | null = null;
1768e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
1769e41f4b71Sopenharmony_ci    const canvas = context.canvas;
1770e41f4b71Sopenharmony_ci    let pen = new drawing.Pen();
1771e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
1772e41f4b71Sopenharmony_ci    let rect: common2D.Rect = { left: 0, top: 0, right: 200, bottom: 200 };
1773e41f4b71Sopenharmony_ci    canvas.drawImageRect(this.pixelMap, rect);
1774e41f4b71Sopenharmony_ci    canvas.detachPen();
1775e41f4b71Sopenharmony_ci  }
1776e41f4b71Sopenharmony_ci}
1777e41f4b71Sopenharmony_ci```
1778e41f4b71Sopenharmony_ci
1779e41f4b71Sopenharmony_ci### drawImageRectWithSrc<sup>12+</sup>
1780e41f4b71Sopenharmony_ci
1781e41f4b71Sopenharmony_cidrawImageRectWithSrc(pixelmap: image.PixelMap, srcRect: common2D.Rect, dstRect: common2D.Rect, samplingOptions?: SamplingOptions, constraint?: SrcRectConstraint): void
1782e41f4b71Sopenharmony_ci
1783e41f4b71Sopenharmony_ciDraws a portion of an image onto a specified area of the canvas.
1784e41f4b71Sopenharmony_ci
1785e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1786e41f4b71Sopenharmony_ci
1787e41f4b71Sopenharmony_ci**Parameters**
1788e41f4b71Sopenharmony_ci
1789e41f4b71Sopenharmony_ci| Name  | Type                                        | Mandatory| Description                           |
1790e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | ---- | ------------------------------- |
1791e41f4b71Sopenharmony_ci| pixelmap | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | Yes  | Pixel map of the image.                |
1792e41f4b71Sopenharmony_ci| srcRect     | [common2D.Rect](js-apis-graphics-common2D.md#rect)                               | Yes  | **Rectangle** object, which specifies the portion of the image to draw.|
1793e41f4b71Sopenharmony_ci| dstRect     | [common2D.Rect](js-apis-graphics-common2D.md#rect)                               | Yes  | **Rectangle** object, which specifies the area of the canvas onto which the image will be drawn.|
1794e41f4b71Sopenharmony_ci| samplingOptions     | [SamplingOptions](#samplingoptions12)                           | No  | Sampling options. By default, the **SamplingOptions** object created using the no-argument constructor is used.|
1795e41f4b71Sopenharmony_ci| constraint     | [SrcRectConstraint](#srcrectconstraint12)                        | No  | Constraint type of the source rectangle. The default value is **STRICT**.|
1796e41f4b71Sopenharmony_ci
1797e41f4b71Sopenharmony_ci**Error codes**
1798e41f4b71Sopenharmony_ci
1799e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1800e41f4b71Sopenharmony_ci
1801e41f4b71Sopenharmony_ci| ID| Error Message|
1802e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
1803e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
1804e41f4b71Sopenharmony_ci
1805e41f4b71Sopenharmony_ci**Example**
1806e41f4b71Sopenharmony_ci
1807e41f4b71Sopenharmony_ci```ts
1808e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
1809e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
1810e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
1811e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
1812e41f4b71Sopenharmony_cipixelMap: image.PixelMap | null = null;
1813e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
1814e41f4b71Sopenharmony_ci    const canvas = context.canvas;
1815e41f4b71Sopenharmony_ci    let pen = new drawing.Pen();
1816e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
1817e41f4b71Sopenharmony_ci    let srcRect: common2D.Rect = { left: 0, top: 0, right: 100, bottom: 100 };
1818e41f4b71Sopenharmony_ci    let dstRect: common2D.Rect = { left: 100, top: 100, right: 200, bottom: 200 };
1819e41f4b71Sopenharmony_ci    canvas.drawImageRectWithSrc(this.pixelMap, srcRect, dstRect);
1820e41f4b71Sopenharmony_ci    canvas.detachPen();
1821e41f4b71Sopenharmony_ci  }
1822e41f4b71Sopenharmony_ci}
1823e41f4b71Sopenharmony_ci```
1824e41f4b71Sopenharmony_ci
1825e41f4b71Sopenharmony_ci### drawColor
1826e41f4b71Sopenharmony_ci
1827e41f4b71Sopenharmony_cidrawColor(color: common2D.Color, blendMode?: BlendMode): void
1828e41f4b71Sopenharmony_ci
1829e41f4b71Sopenharmony_ciDraws the background color.
1830e41f4b71Sopenharmony_ci
1831e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1832e41f4b71Sopenharmony_ci
1833e41f4b71Sopenharmony_ci**Parameters**
1834e41f4b71Sopenharmony_ci
1835e41f4b71Sopenharmony_ci| Name   | Type                                                | Mandatory| Description                            |
1836e41f4b71Sopenharmony_ci| --------- | ---------------------------------------------------- | ---- | -------------------------------- |
1837e41f4b71Sopenharmony_ci| color     | [common2D.Color](js-apis-graphics-common2D.md#color) | Yes  | Color in ARGB format. Each color channel is an integer ranging from 0 to 255.                  |
1838e41f4b71Sopenharmony_ci| blendMode | [BlendMode](#blendmode)                              | No  | Blend mode. The default mode is **SRC_OVER**.|
1839e41f4b71Sopenharmony_ci
1840e41f4b71Sopenharmony_ci**Error codes**
1841e41f4b71Sopenharmony_ci
1842e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1843e41f4b71Sopenharmony_ci
1844e41f4b71Sopenharmony_ci| ID| Error Message|
1845e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
1846e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
1847e41f4b71Sopenharmony_ci
1848e41f4b71Sopenharmony_ci**Example**
1849e41f4b71Sopenharmony_ci
1850e41f4b71Sopenharmony_ci```ts
1851e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
1852e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
1853e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
1854e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
1855e41f4b71Sopenharmony_ci    const canvas = context.canvas;
1856e41f4b71Sopenharmony_ci    let color: common2D.Color = {
1857e41f4b71Sopenharmony_ci      alpha : 255,
1858e41f4b71Sopenharmony_ci      red: 0,
1859e41f4b71Sopenharmony_ci      green: 10,
1860e41f4b71Sopenharmony_ci      blue: 10
1861e41f4b71Sopenharmony_ci    }
1862e41f4b71Sopenharmony_ci    canvas.drawColor(color, drawing.BlendMode.CLEAR);
1863e41f4b71Sopenharmony_ci  }
1864e41f4b71Sopenharmony_ci}
1865e41f4b71Sopenharmony_ci```
1866e41f4b71Sopenharmony_ci
1867e41f4b71Sopenharmony_ci### drawColor<sup>12+</sup>
1868e41f4b71Sopenharmony_ci
1869e41f4b71Sopenharmony_cidrawColor(alpha: number, red: number, green: number, blue: number, blendMode?: BlendMode): void
1870e41f4b71Sopenharmony_ci
1871e41f4b71Sopenharmony_ciDraws the background color. This API provides better performance than [drawColor](#drawcolor) and is recommended.
1872e41f4b71Sopenharmony_ci
1873e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1874e41f4b71Sopenharmony_ci
1875e41f4b71Sopenharmony_ci**Parameters**
1876e41f4b71Sopenharmony_ci
1877e41f4b71Sopenharmony_ci| Name    | Type                   | Mandatory| Description                                              |
1878e41f4b71Sopenharmony_ci| --------- | ----------------------- | ---- | ------------------------------------------------- |
1879e41f4b71Sopenharmony_ci| alpha     | number                  | Yes  | Alpha channel value of the color in ARGB format. The value is an integer ranging from 0 to 255. Any passed-in floating point number is rounded down.|
1880e41f4b71Sopenharmony_ci| red       | number                  | Yes  | Red channel value of the color in ARGB format. The value is an integer ranging from 0 to 255. Any passed-in floating point number is rounded down.  |
1881e41f4b71Sopenharmony_ci| green     | number                  | Yes  | Green channel value of the color in ARGB format. The value is an integer ranging from 0 to 255. Any passed-in floating point number is rounded down.  |
1882e41f4b71Sopenharmony_ci| blue      | number                  | Yes  | Blue channel value of the color in ARGB format. The value is an integer ranging from 0 to 255. Any passed-in floating point number is rounded down.  |
1883e41f4b71Sopenharmony_ci| blendMode | [BlendMode](#blendmode) | No  | Blend mode. The default mode is **SRC_OVER**.                  |
1884e41f4b71Sopenharmony_ci
1885e41f4b71Sopenharmony_ci**Error codes**
1886e41f4b71Sopenharmony_ci
1887e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1888e41f4b71Sopenharmony_ci
1889e41f4b71Sopenharmony_ci| ID| Error Message|
1890e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
1891e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
1892e41f4b71Sopenharmony_ci
1893e41f4b71Sopenharmony_ci**Example**
1894e41f4b71Sopenharmony_ci
1895e41f4b71Sopenharmony_ci```ts
1896e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
1897e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
1898e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
1899e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
1900e41f4b71Sopenharmony_ci    const canvas = context.canvas;
1901e41f4b71Sopenharmony_ci    canvas.drawColor(255, 0, 10, 10, drawing.BlendMode.CLEAR);
1902e41f4b71Sopenharmony_ci  }
1903e41f4b71Sopenharmony_ci}
1904e41f4b71Sopenharmony_ci```
1905e41f4b71Sopenharmony_ci
1906e41f4b71Sopenharmony_ci### drawPixelMapMesh<sup>12+</sup>
1907e41f4b71Sopenharmony_ci
1908e41f4b71Sopenharmony_cidrawPixelMapMesh(pixelmap: image.PixelMap, meshWidth: number, meshHeight: number, vertices: Array\<number>, vertOffset: number, colors: Array\<number>, colorOffset: number): void
1909e41f4b71Sopenharmony_ci
1910e41f4b71Sopenharmony_ciDraws a pixel map based on a mesh, where mesh vertices are evenly distributed across the pixel map.
1911e41f4b71Sopenharmony_ci
1912e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1913e41f4b71Sopenharmony_ci
1914e41f4b71Sopenharmony_ci**Parameters**
1915e41f4b71Sopenharmony_ci
1916e41f4b71Sopenharmony_ci| Name     | Type           | Mandatory| Description                           |
1917e41f4b71Sopenharmony_ci| ----------- | -------------  | ---- | ------------------------------- |
1918e41f4b71Sopenharmony_ci| pixelmap    | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | Yes  | Pixel map to draw.|
1919e41f4b71Sopenharmony_ci| meshWidth   | number         | Yes  | Number of columns in the mesh. The value is an integer greater than 0.|
1920e41f4b71Sopenharmony_ci| meshHeight  | number         | Yes  | Number of rows in the mesh. The value is an integer greater than 0.|
1921e41f4b71Sopenharmony_ci| vertices    | Array\<number> | Yes  | Array of vertices, which specify the position to draw. The value is a floating-point array and the size must be ((meshWidth+1) * (meshHeight+1) + vertOffset) * 2.|
1922e41f4b71Sopenharmony_ci| vertOffset  | number         | Yes  | Number of vert elements to skip before drawing. The value is an integer greater than or equal to 0.|
1923e41f4b71Sopenharmony_ci| colors      | Array\<number> | Yes  | Array of colors, which specify the color at each vertex. The value is an integer array and can be null. The size must be (meshWidth+1) * (meshHeight+1) + colorOffset.|
1924e41f4b71Sopenharmony_ci| colorOffset | number         | Yes  | Number of color elements to skip before drawing. The value is an integer greater than or equal to 0.|
1925e41f4b71Sopenharmony_ci
1926e41f4b71Sopenharmony_ci**Error codes**
1927e41f4b71Sopenharmony_ci
1928e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1929e41f4b71Sopenharmony_ci
1930e41f4b71Sopenharmony_ci| ID| Error Message|
1931e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
1932e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
1933e41f4b71Sopenharmony_ci
1934e41f4b71Sopenharmony_ci**Example**
1935e41f4b71Sopenharmony_ci
1936e41f4b71Sopenharmony_ci```ts
1937e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
1938e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
1939e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
1940e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
1941e41f4b71Sopenharmony_ci  pixelMap: image.PixelMap | null = null;
1942e41f4b71Sopenharmony_ci
1943e41f4b71Sopenharmony_ci  async draw(context : DrawContext) {
1944e41f4b71Sopenharmony_ci    const canvas = context.canvas;
1945e41f4b71Sopenharmony_ci    if (this.pixelMap != null) {
1946e41f4b71Sopenharmony_ci      const brush = new drawing.Brush(); // Only brush is supported. There is no drawing effect when pen is used.
1947e41f4b71Sopenharmony_ci      canvas.attachBrush(brush);
1948e41f4b71Sopenharmony_ci      let verts : Array<number> = [0, 0, 50, 0, 410, 0, 0, 180, 50, 180, 410, 180, 0, 360, 50, 360, 410, 360]; // 18
1949e41f4b71Sopenharmony_ci      canvas.drawPixelMapMesh(this.pixelMap, 2, 2, verts, 0, null, 0);
1950e41f4b71Sopenharmony_ci      canvas.detachBrush();
1951e41f4b71Sopenharmony_ci    }
1952e41f4b71Sopenharmony_ci  }
1953e41f4b71Sopenharmony_ci}
1954e41f4b71Sopenharmony_ci```
1955e41f4b71Sopenharmony_ci
1956e41f4b71Sopenharmony_ci### clear<sup>12+</sup>
1957e41f4b71Sopenharmony_ci
1958e41f4b71Sopenharmony_ciclear(color: common2D.Color): void
1959e41f4b71Sopenharmony_ci
1960e41f4b71Sopenharmony_ciClears the canvas with a given color.
1961e41f4b71Sopenharmony_ci
1962e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1963e41f4b71Sopenharmony_ci
1964e41f4b71Sopenharmony_ci**Parameters**
1965e41f4b71Sopenharmony_ci
1966e41f4b71Sopenharmony_ci| Name   | Type                                                | Mandatory| Description                            |
1967e41f4b71Sopenharmony_ci| --------- | ---------------------------------------------------- | ---- | -------------------------------- |
1968e41f4b71Sopenharmony_ci| color     | [common2D.Color](js-apis-graphics-common2D.md#color) | Yes  | Color in ARGB format. Each color channel is an integer ranging from 0 to 255.     |
1969e41f4b71Sopenharmony_ci
1970e41f4b71Sopenharmony_ci**Error codes**
1971e41f4b71Sopenharmony_ci
1972e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1973e41f4b71Sopenharmony_ci
1974e41f4b71Sopenharmony_ci| ID| Error Message|
1975e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
1976e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
1977e41f4b71Sopenharmony_ci
1978e41f4b71Sopenharmony_ci**Example**
1979e41f4b71Sopenharmony_ci
1980e41f4b71Sopenharmony_ci```ts
1981e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
1982e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
1983e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
1984e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
1985e41f4b71Sopenharmony_ci    const canvas = context.canvas;
1986e41f4b71Sopenharmony_ci    let color: common2D.Color = {alpha: 255, red: 255, green: 0, blue: 0};
1987e41f4b71Sopenharmony_ci    canvas.clear(color);
1988e41f4b71Sopenharmony_ci  }
1989e41f4b71Sopenharmony_ci}
1990e41f4b71Sopenharmony_ci```
1991e41f4b71Sopenharmony_ci
1992e41f4b71Sopenharmony_ci### clear<sup>13+</sup>
1993e41f4b71Sopenharmony_ci
1994e41f4b71Sopenharmony_ciclear(number): void
1995e41f4b71Sopenharmony_ci
1996e41f4b71Sopenharmony_ciClears the canvas with a given color.
1997e41f4b71Sopenharmony_ci
1998e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
1999e41f4b71Sopenharmony_ci
2000e41f4b71Sopenharmony_ci**Parameters**
2001e41f4b71Sopenharmony_ci
2002e41f4b71Sopenharmony_ci| Name   | Type                                                | Mandatory| Description                            |
2003e41f4b71Sopenharmony_ci| --------- | ---------------------------------------------------- | ---- | -------------------------------- |
2004e41f4b71Sopenharmony_ci| color     | number| Yes  | Color, represented by a 32-bit unsigned integer in hexadecimal ARGB format. |
2005e41f4b71Sopenharmony_ci
2006e41f4b71Sopenharmony_ci**Error codes**
2007e41f4b71Sopenharmony_ci
2008e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2009e41f4b71Sopenharmony_ci
2010e41f4b71Sopenharmony_ci| ID| Error Message|
2011e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
2012e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2013e41f4b71Sopenharmony_ci
2014e41f4b71Sopenharmony_ci**Example**
2015e41f4b71Sopenharmony_ci
2016e41f4b71Sopenharmony_ci```ts
2017e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2018e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
2019e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2020e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2021e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2022e41f4b71Sopenharmony_ci    let color: number = 0xffff0000;
2023e41f4b71Sopenharmony_ci    canvas.clear(color);
2024e41f4b71Sopenharmony_ci  }
2025e41f4b71Sopenharmony_ci}
2026e41f4b71Sopenharmony_ci```
2027e41f4b71Sopenharmony_ci
2028e41f4b71Sopenharmony_ci### getWidth<sup>12+</sup>
2029e41f4b71Sopenharmony_ci
2030e41f4b71Sopenharmony_cigetWidth(): number
2031e41f4b71Sopenharmony_ci
2032e41f4b71Sopenharmony_ciObtains the canvas width.
2033e41f4b71Sopenharmony_ci
2034e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
2035e41f4b71Sopenharmony_ci
2036e41f4b71Sopenharmony_ci**Return value**
2037e41f4b71Sopenharmony_ci
2038e41f4b71Sopenharmony_ci| Type  | Mandatory| Description          |
2039e41f4b71Sopenharmony_ci| ------ | ---- | -------------- |
2040e41f4b71Sopenharmony_ci| number | Yes  | Canvas width. The value is a floating point number.|
2041e41f4b71Sopenharmony_ci
2042e41f4b71Sopenharmony_ci**Example**
2043e41f4b71Sopenharmony_ci
2044e41f4b71Sopenharmony_ci```ts
2045e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2046e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
2047e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2048e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2049e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2050e41f4b71Sopenharmony_ci    let width = canvas.getWidth();
2051e41f4b71Sopenharmony_ci    console.info('get canvas width:' + width);
2052e41f4b71Sopenharmony_ci  }
2053e41f4b71Sopenharmony_ci}
2054e41f4b71Sopenharmony_ci```
2055e41f4b71Sopenharmony_ci
2056e41f4b71Sopenharmony_ci### getHeight<sup>12+</sup>
2057e41f4b71Sopenharmony_ci
2058e41f4b71Sopenharmony_cigetHeight(): number
2059e41f4b71Sopenharmony_ci
2060e41f4b71Sopenharmony_ciObtains the canvas height.
2061e41f4b71Sopenharmony_ci
2062e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
2063e41f4b71Sopenharmony_ci
2064e41f4b71Sopenharmony_ci**Return value**
2065e41f4b71Sopenharmony_ci
2066e41f4b71Sopenharmony_ci| Type  | Mandatory| Description          |
2067e41f4b71Sopenharmony_ci| ------ | ---- | -------------- |
2068e41f4b71Sopenharmony_ci| number | Yes  | Canvas height. The value is a floating point number.|
2069e41f4b71Sopenharmony_ci
2070e41f4b71Sopenharmony_ci**Example**
2071e41f4b71Sopenharmony_ci
2072e41f4b71Sopenharmony_ci```ts
2073e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2074e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
2075e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2076e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2077e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2078e41f4b71Sopenharmony_ci    let height = canvas.getHeight();
2079e41f4b71Sopenharmony_ci    console.log('get canvas height:' + height);
2080e41f4b71Sopenharmony_ci  }
2081e41f4b71Sopenharmony_ci}
2082e41f4b71Sopenharmony_ci```
2083e41f4b71Sopenharmony_ci
2084e41f4b71Sopenharmony_ci### drawOval<sup>12+</sup>
2085e41f4b71Sopenharmony_ci
2086e41f4b71Sopenharmony_cidrawOval(oval: common2D.Rect): void
2087e41f4b71Sopenharmony_ci
2088e41f4b71Sopenharmony_ciDraws an oval on the canvas. The shape and position of the oval are defined by the rectangle parameters that specify the oval boundary.
2089e41f4b71Sopenharmony_ci
2090e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
2091e41f4b71Sopenharmony_ci
2092e41f4b71Sopenharmony_ci**Parameters**
2093e41f4b71Sopenharmony_ci
2094e41f4b71Sopenharmony_ci| Name| Type                                              | Mandatory| Description          |
2095e41f4b71Sopenharmony_ci| ------ | -------------------------------------------------- | ---- | -------------- |
2096e41f4b71Sopenharmony_ci| oval   | [common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes  | Rectangle. The oval inscribed within the rectangle is the oval to draw.|
2097e41f4b71Sopenharmony_ci
2098e41f4b71Sopenharmony_ci**Error codes**
2099e41f4b71Sopenharmony_ci
2100e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2101e41f4b71Sopenharmony_ci
2102e41f4b71Sopenharmony_ci| ID| Error Message|
2103e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
2104e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2105e41f4b71Sopenharmony_ci
2106e41f4b71Sopenharmony_ci**Example**
2107e41f4b71Sopenharmony_ci
2108e41f4b71Sopenharmony_ci```ts
2109e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2110e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
2111e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2112e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2113e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2114e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
2115e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
2116e41f4b71Sopenharmony_ci    const color : common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
2117e41f4b71Sopenharmony_ci    pen.setColor(color);
2118e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
2119e41f4b71Sopenharmony_ci    const rect: common2D.Rect = {left:100, top:50, right:400, bottom:500};
2120e41f4b71Sopenharmony_ci    canvas.drawOval(rect);
2121e41f4b71Sopenharmony_ci    canvas.detachPen();
2122e41f4b71Sopenharmony_ci  }
2123e41f4b71Sopenharmony_ci}
2124e41f4b71Sopenharmony_ci```
2125e41f4b71Sopenharmony_ci
2126e41f4b71Sopenharmony_ci### drawArc<sup>12+</sup>
2127e41f4b71Sopenharmony_ci
2128e41f4b71Sopenharmony_cidrawArc(arc: common2D.Rect, startAngle: number, sweepAngle: number): void
2129e41f4b71Sopenharmony_ci
2130e41f4b71Sopenharmony_ciDraws an arc on the canvas, with the start angle and sweep angle specified.
2131e41f4b71Sopenharmony_ci
2132e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
2133e41f4b71Sopenharmony_ci
2134e41f4b71Sopenharmony_ci**Parameters**
2135e41f4b71Sopenharmony_ci
2136e41f4b71Sopenharmony_ci| Name| Type                                              | Mandatory| Description          |
2137e41f4b71Sopenharmony_ci| ------ | -------------------------------------------------- | ---- | -------------- |
2138e41f4b71Sopenharmony_ci| arc   | [common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes  | Rectangular boundary that encapsulates the oval including the arc.|
2139e41f4b71Sopenharmony_ci| startAngle      | number | Yes  | Start angle, in degrees. The value is a floating point number. When the degree is 0, the start point is located at the right end of the oval. A positive number indicates that the start point is placed clockwise, and a negative number indicates that the start point is placed counterclockwise.|
2140e41f4b71Sopenharmony_ci| sweepAngle      | number | Yes  | Angle to sweep, in degrees. The value is a floating point number. A positive number indicates a clockwise sweep, and a negative value indicates a counterclockwise swipe.|
2141e41f4b71Sopenharmony_ci
2142e41f4b71Sopenharmony_ci**Error codes**
2143e41f4b71Sopenharmony_ci
2144e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2145e41f4b71Sopenharmony_ci
2146e41f4b71Sopenharmony_ci| ID| Error Message|
2147e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
2148e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2149e41f4b71Sopenharmony_ci
2150e41f4b71Sopenharmony_ci**Example**
2151e41f4b71Sopenharmony_ci
2152e41f4b71Sopenharmony_ci```ts
2153e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2154e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
2155e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2156e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2157e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2158e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
2159e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
2160e41f4b71Sopenharmony_ci    const color : common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
2161e41f4b71Sopenharmony_ci    pen.setColor(color);
2162e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
2163e41f4b71Sopenharmony_ci    const rect: common2D.Rect = {left:100, top:50, right:400, bottom:200};
2164e41f4b71Sopenharmony_ci    canvas.drawArc(rect, 90, 180);
2165e41f4b71Sopenharmony_ci    canvas.detachPen();
2166e41f4b71Sopenharmony_ci  }
2167e41f4b71Sopenharmony_ci}
2168e41f4b71Sopenharmony_ci```
2169e41f4b71Sopenharmony_ci
2170e41f4b71Sopenharmony_ci### drawPoint
2171e41f4b71Sopenharmony_ci
2172e41f4b71Sopenharmony_cidrawPoint(x: number, y: number): void
2173e41f4b71Sopenharmony_ci
2174e41f4b71Sopenharmony_ciDraws a point.
2175e41f4b71Sopenharmony_ci
2176e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
2177e41f4b71Sopenharmony_ci
2178e41f4b71Sopenharmony_ci**Parameters**
2179e41f4b71Sopenharmony_ci
2180e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description               |
2181e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------- |
2182e41f4b71Sopenharmony_ci| x      | number | Yes  | X coordinate of the point. The value is a floating point number.|
2183e41f4b71Sopenharmony_ci| y      | number | Yes  | Y coordinate of the point. The value is a floating point number.|
2184e41f4b71Sopenharmony_ci
2185e41f4b71Sopenharmony_ci**Error codes**
2186e41f4b71Sopenharmony_ci
2187e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2188e41f4b71Sopenharmony_ci
2189e41f4b71Sopenharmony_ci| ID| Error Message|
2190e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
2191e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2192e41f4b71Sopenharmony_ci
2193e41f4b71Sopenharmony_ci**Example**
2194e41f4b71Sopenharmony_ci
2195e41f4b71Sopenharmony_ci```ts
2196e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2197e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
2198e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2199e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2200e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2201e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
2202e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
2203e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2204e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
2205e41f4b71Sopenharmony_ci    canvas.drawPoint(10, 10);
2206e41f4b71Sopenharmony_ci    canvas.detachPen();
2207e41f4b71Sopenharmony_ci  }
2208e41f4b71Sopenharmony_ci}
2209e41f4b71Sopenharmony_ci```
2210e41f4b71Sopenharmony_ci
2211e41f4b71Sopenharmony_ci### drawPoints<sup>12+</sup>
2212e41f4b71Sopenharmony_ci
2213e41f4b71Sopenharmony_cidrawPoints(points: Array\<common2D.Point>, mode?: PointMode): void
2214e41f4b71Sopenharmony_ci
2215e41f4b71Sopenharmony_ciDraws a group of points, line segments, or polygons on the canvas, with the specified drawing mode. An array is used to hold these points.
2216e41f4b71Sopenharmony_ci
2217e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
2218e41f4b71Sopenharmony_ci
2219e41f4b71Sopenharmony_ci**Parameters**
2220e41f4b71Sopenharmony_ci
2221e41f4b71Sopenharmony_ci| Name | Type                                      | Mandatory  | Description       |
2222e41f4b71Sopenharmony_ci| ---- | ---------------------------------------- | ---- | --------- |
2223e41f4b71Sopenharmony_ci| points  | Array\<[common2D.Point](js-apis-graphics-common2D.md#point)> | Yes   | Array that holds the points to draw. The length cannot be 0.  |
2224e41f4b71Sopenharmony_ci| mode | [PointMode](#pointmode12)                  | No   | Mode in which the points are drawn. The default value is **drawing.PointMode.POINTS**.|
2225e41f4b71Sopenharmony_ci
2226e41f4b71Sopenharmony_ci**Error codes**
2227e41f4b71Sopenharmony_ci
2228e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2229e41f4b71Sopenharmony_ci
2230e41f4b71Sopenharmony_ci| ID| Error Message|
2231e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
2232e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.|
2233e41f4b71Sopenharmony_ci
2234e41f4b71Sopenharmony_ci**Example**
2235e41f4b71Sopenharmony_ci
2236e41f4b71Sopenharmony_ci```ts
2237e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2238e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
2239e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2240e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2241e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2242e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
2243e41f4b71Sopenharmony_ci    pen.setStrokeWidth(30);
2244e41f4b71Sopenharmony_ci    const color : common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
2245e41f4b71Sopenharmony_ci    pen.setColor(color);
2246e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
2247e41f4b71Sopenharmony_ci    canvas.drawPoints([{x: 100, y: 200}, {x: 150, y: 230}, {x: 200, y: 300}], drawing.PointMode.POINTS);
2248e41f4b71Sopenharmony_ci    canvas.detachPen();
2249e41f4b71Sopenharmony_ci  }
2250e41f4b71Sopenharmony_ci}
2251e41f4b71Sopenharmony_ci```
2252e41f4b71Sopenharmony_ci
2253e41f4b71Sopenharmony_ci### drawPath
2254e41f4b71Sopenharmony_ci
2255e41f4b71Sopenharmony_cidrawPath(path: Path): void
2256e41f4b71Sopenharmony_ci
2257e41f4b71Sopenharmony_ciDraws a custom path, which contains a set of path outlines. Each path outline can be open or closed.
2258e41f4b71Sopenharmony_ci
2259e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
2260e41f4b71Sopenharmony_ci
2261e41f4b71Sopenharmony_ci**Parameters**
2262e41f4b71Sopenharmony_ci
2263e41f4b71Sopenharmony_ci| Name| Type         | Mandatory| Description              |
2264e41f4b71Sopenharmony_ci| ------ | ------------- | ---- | ------------------ |
2265e41f4b71Sopenharmony_ci| path   | [Path](#path) | Yes  | **Path** object to draw.|
2266e41f4b71Sopenharmony_ci
2267e41f4b71Sopenharmony_ci**Error codes**
2268e41f4b71Sopenharmony_ci
2269e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2270e41f4b71Sopenharmony_ci
2271e41f4b71Sopenharmony_ci| ID| Error Message|
2272e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
2273e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2274e41f4b71Sopenharmony_ci
2275e41f4b71Sopenharmony_ci**Example**
2276e41f4b71Sopenharmony_ci
2277e41f4b71Sopenharmony_ci```ts
2278e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2279e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
2280e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2281e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2282e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2283e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
2284e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
2285e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2286e41f4b71Sopenharmony_ci    let path = new drawing.Path();
2287e41f4b71Sopenharmony_ci    path.moveTo(10,10);
2288e41f4b71Sopenharmony_ci    path.cubicTo(10, 10, 10, 10, 15, 15);
2289e41f4b71Sopenharmony_ci    path.close();
2290e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
2291e41f4b71Sopenharmony_ci    canvas.drawPath(path);
2292e41f4b71Sopenharmony_ci    canvas.detachPen();
2293e41f4b71Sopenharmony_ci  }
2294e41f4b71Sopenharmony_ci}
2295e41f4b71Sopenharmony_ci```
2296e41f4b71Sopenharmony_ci
2297e41f4b71Sopenharmony_ci### drawLine
2298e41f4b71Sopenharmony_ci
2299e41f4b71Sopenharmony_cidrawLine(x0: number, y0: number, x1: number, y1: number): void
2300e41f4b71Sopenharmony_ci
2301e41f4b71Sopenharmony_ciDraws a line segment from the start point to the end point. If the coordinates of the start point are the same as those of the end point, nothing is drawn.
2302e41f4b71Sopenharmony_ci
2303e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
2304e41f4b71Sopenharmony_ci
2305e41f4b71Sopenharmony_ci**Parameters**
2306e41f4b71Sopenharmony_ci
2307e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                   |
2308e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------- |
2309e41f4b71Sopenharmony_ci| x0     | number | Yes  | X coordinate of the start point of the line segment. The value is a floating point number.|
2310e41f4b71Sopenharmony_ci| y0     | number | Yes  | Y coordinate of the start point of the line segment. The value is a floating point number.|
2311e41f4b71Sopenharmony_ci| x1     | number | Yes  | X coordinate of the end point of the line segment. The value is a floating point number.|
2312e41f4b71Sopenharmony_ci| y1     | number | Yes  | Y coordinate of the end point of the line segment. The value is a floating point number.|
2313e41f4b71Sopenharmony_ci
2314e41f4b71Sopenharmony_ci**Error codes**
2315e41f4b71Sopenharmony_ci
2316e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2317e41f4b71Sopenharmony_ci
2318e41f4b71Sopenharmony_ci| ID| Error Message|
2319e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
2320e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2321e41f4b71Sopenharmony_ci
2322e41f4b71Sopenharmony_ci**Example**
2323e41f4b71Sopenharmony_ci
2324e41f4b71Sopenharmony_ci```ts
2325e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2326e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
2327e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2328e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2329e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2330e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
2331e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
2332e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2333e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
2334e41f4b71Sopenharmony_ci    canvas.drawLine(0, 0, 20, 20);
2335e41f4b71Sopenharmony_ci    canvas.detachPen();
2336e41f4b71Sopenharmony_ci  }
2337e41f4b71Sopenharmony_ci}
2338e41f4b71Sopenharmony_ci```
2339e41f4b71Sopenharmony_ci
2340e41f4b71Sopenharmony_ci### drawTextBlob
2341e41f4b71Sopenharmony_ci
2342e41f4b71Sopenharmony_cidrawTextBlob(blob: TextBlob, x: number, y: number): void
2343e41f4b71Sopenharmony_ci
2344e41f4b71Sopenharmony_ciDraws a text blob. If the typeface used to construct **blob** does not support a character, that character will not be drawn.
2345e41f4b71Sopenharmony_ci
2346e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
2347e41f4b71Sopenharmony_ci
2348e41f4b71Sopenharmony_ci**Parameters**
2349e41f4b71Sopenharmony_ci
2350e41f4b71Sopenharmony_ci| Name| Type                 | Mandatory| Description                                      |
2351e41f4b71Sopenharmony_ci| ------ | --------------------- | ---- | ------------------------------------------ |
2352e41f4b71Sopenharmony_ci| blob   | [TextBlob](#textblob) | Yes  | **TextBlob** object.                            |
2353e41f4b71Sopenharmony_ci| x      | number                | Yes  | X coordinate of the left point (red point in the figure below) of the text baseline (blue line in the figure below). The value is a floating point number.|
2354e41f4b71Sopenharmony_ci| y      | number                | Yes  | Y coordinate of the left point (red point in the figure below) of the text baseline (blue line in the figure below). The value is a floating point number.|
2355e41f4b71Sopenharmony_ci
2356e41f4b71Sopenharmony_ci![image_Text_Blob.png](figures/image_Text_Blob.png)
2357e41f4b71Sopenharmony_ci
2358e41f4b71Sopenharmony_ci**Error codes**
2359e41f4b71Sopenharmony_ci
2360e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2361e41f4b71Sopenharmony_ci
2362e41f4b71Sopenharmony_ci| ID| Error Message|
2363e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
2364e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2365e41f4b71Sopenharmony_ci
2366e41f4b71Sopenharmony_ci**Example**
2367e41f4b71Sopenharmony_ci
2368e41f4b71Sopenharmony_ci```ts
2369e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2370e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
2371e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2372e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2373e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2374e41f4b71Sopenharmony_ci    const brush = new drawing.Brush();
2375e41f4b71Sopenharmony_ci    brush.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2376e41f4b71Sopenharmony_ci    const font = new drawing.Font();
2377e41f4b71Sopenharmony_ci    font.setSize(20);
2378e41f4b71Sopenharmony_ci    const textBlob = drawing.TextBlob.makeFromString("Hello, drawing", font, drawing.TextEncoding.TEXT_ENCODING_UTF8);
2379e41f4b71Sopenharmony_ci    canvas.attachBrush(brush);
2380e41f4b71Sopenharmony_ci    canvas.drawTextBlob(textBlob, 20, 20);
2381e41f4b71Sopenharmony_ci    canvas.detachBrush();
2382e41f4b71Sopenharmony_ci  }
2383e41f4b71Sopenharmony_ci}
2384e41f4b71Sopenharmony_ci```
2385e41f4b71Sopenharmony_ci
2386e41f4b71Sopenharmony_ci### drawSingleCharacter<sup>12+</sup>
2387e41f4b71Sopenharmony_ci
2388e41f4b71Sopenharmony_cidrawSingleCharacter(text: string, font: Font, x: number, y: number): void
2389e41f4b71Sopenharmony_ci
2390e41f4b71Sopenharmony_ciDraws a single character. If the typeface of the current font does not support the character to draw, the system typeface is used to draw the character.
2391e41f4b71Sopenharmony_ci
2392e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
2393e41f4b71Sopenharmony_ci
2394e41f4b71Sopenharmony_ci**Parameters**
2395e41f4b71Sopenharmony_ci
2396e41f4b71Sopenharmony_ci| Name| Type               | Mandatory| Description       |
2397e41f4b71Sopenharmony_ci| ------ | ------------------- | ---- | ----------- |
2398e41f4b71Sopenharmony_ci| text   | string | Yes  | Single character to draw. The length of the string must be 1. |
2399e41f4b71Sopenharmony_ci| font   | [Font](#font) | Yes  | **Font** object. |
2400e41f4b71Sopenharmony_ci| x      | number | Yes  | X coordinate of the left point (red point in the figure below) of the character baseline (blue line in the figure below). The value is a floating point number.|
2401e41f4b71Sopenharmony_ci| y      | number | Yes  | Y coordinate of the left point (red point in the figure below) of the character baseline (blue line in the figure below). The value is a floating point number.|
2402e41f4b71Sopenharmony_ci
2403e41f4b71Sopenharmony_ci![image_Text_Blob.png](figures/image_Text_Blob.png)
2404e41f4b71Sopenharmony_ci
2405e41f4b71Sopenharmony_ci**Error codes**
2406e41f4b71Sopenharmony_ci
2407e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2408e41f4b71Sopenharmony_ci
2409e41f4b71Sopenharmony_ci| ID| Error Message|
2410e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
2411e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
2412e41f4b71Sopenharmony_ci
2413e41f4b71Sopenharmony_ci**Example**
2414e41f4b71Sopenharmony_ci
2415e41f4b71Sopenharmony_ci```ts
2416e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2417e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
2418e41f4b71Sopenharmony_ci
2419e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2420e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2421e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2422e41f4b71Sopenharmony_ci    const brush = new drawing.Brush();
2423e41f4b71Sopenharmony_ci    brush.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2424e41f4b71Sopenharmony_ci    const font = new drawing.Font();
2425e41f4b71Sopenharmony_ci    font.setSize(20);
2426e41f4b71Sopenharmony_ci    canvas.attachBrush(brush);
2427e41f4b71Sopenharmony_ci    canvas.drawSingleCharacter ("Hello", font, 100, 100);
2428e41f4b71Sopenharmony_ci    canvas.drawSingleCharacter ("drawing", font, 120, 100);
2429e41f4b71Sopenharmony_ci    canvas.detachBrush();
2430e41f4b71Sopenharmony_ci  }
2431e41f4b71Sopenharmony_ci}
2432e41f4b71Sopenharmony_ci```
2433e41f4b71Sopenharmony_ci
2434e41f4b71Sopenharmony_ci### drawRegion<sup>12+</sup>
2435e41f4b71Sopenharmony_ci
2436e41f4b71Sopenharmony_cidrawRegion(region: Region): void
2437e41f4b71Sopenharmony_ci
2438e41f4b71Sopenharmony_ciDraws a region.
2439e41f4b71Sopenharmony_ci
2440e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
2441e41f4b71Sopenharmony_ci
2442e41f4b71Sopenharmony_ci**Parameters**
2443e41f4b71Sopenharmony_ci
2444e41f4b71Sopenharmony_ci| Name| Type               | Mandatory| Description       |
2445e41f4b71Sopenharmony_ci| ------ | ------------------- | ---- | ----------- |
2446e41f4b71Sopenharmony_ci| region   | [Region](#region12) | Yes  | Region to draw. |
2447e41f4b71Sopenharmony_ci
2448e41f4b71Sopenharmony_ci**Error codes**
2449e41f4b71Sopenharmony_ci
2450e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2451e41f4b71Sopenharmony_ci
2452e41f4b71Sopenharmony_ci| ID| Error Message|
2453e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
2454e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2455e41f4b71Sopenharmony_ci
2456e41f4b71Sopenharmony_ci**Example**
2457e41f4b71Sopenharmony_ci
2458e41f4b71Sopenharmony_ci```ts
2459e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2460e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2461e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2462e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2463e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
2464e41f4b71Sopenharmony_ci    let region = new drawing.Region();
2465e41f4b71Sopenharmony_ci    pen.setStrokeWidth(10);
2466e41f4b71Sopenharmony_ci    pen.setColor({ alpha: 255, red: 255, green: 0, blue: 0 });
2467e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
2468e41f4b71Sopenharmony_ci    region.setRect(100, 100, 400, 400);
2469e41f4b71Sopenharmony_ci    canvas.drawRegion(region);
2470e41f4b71Sopenharmony_ci    canvas.detachPen();
2471e41f4b71Sopenharmony_ci  }
2472e41f4b71Sopenharmony_ci}
2473e41f4b71Sopenharmony_ci```
2474e41f4b71Sopenharmony_ci
2475e41f4b71Sopenharmony_ci### attachPen
2476e41f4b71Sopenharmony_ci
2477e41f4b71Sopenharmony_ciattachPen(pen: Pen): void
2478e41f4b71Sopenharmony_ci
2479e41f4b71Sopenharmony_ciAttaches a pen to a canvas so that the canvas can use the style and color of the pen to outline a shape.
2480e41f4b71Sopenharmony_ci
2481e41f4b71Sopenharmony_ci> **NOTE**
2482e41f4b71Sopenharmony_ci>
2483e41f4b71Sopenharmony_ci> If the pen effect changes after this API is called, you must call the API again if you want to use the new effect in the subsequent drawing.
2484e41f4b71Sopenharmony_ci
2485e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
2486e41f4b71Sopenharmony_ci
2487e41f4b71Sopenharmony_ci**Parameters**
2488e41f4b71Sopenharmony_ci
2489e41f4b71Sopenharmony_ci| Name| Type       | Mandatory| Description      |
2490e41f4b71Sopenharmony_ci| ------ | ----------- | ---- | ---------- |
2491e41f4b71Sopenharmony_ci| pen    | [Pen](#pen) | Yes  | **Pen** object.|
2492e41f4b71Sopenharmony_ci
2493e41f4b71Sopenharmony_ci**Error codes**
2494e41f4b71Sopenharmony_ci
2495e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2496e41f4b71Sopenharmony_ci
2497e41f4b71Sopenharmony_ci| ID| Error Message|
2498e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
2499e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2500e41f4b71Sopenharmony_ci
2501e41f4b71Sopenharmony_ci**Example**
2502e41f4b71Sopenharmony_ci
2503e41f4b71Sopenharmony_ci```ts
2504e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2505e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
2506e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2507e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2508e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2509e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
2510e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
2511e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2512e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
2513e41f4b71Sopenharmony_ci    canvas.drawRect({ left : 0, right : 10, top : 0, bottom : 10 });
2514e41f4b71Sopenharmony_ci    canvas.detachPen();
2515e41f4b71Sopenharmony_ci  }
2516e41f4b71Sopenharmony_ci}
2517e41f4b71Sopenharmony_ci```
2518e41f4b71Sopenharmony_ci
2519e41f4b71Sopenharmony_ci### attachBrush
2520e41f4b71Sopenharmony_ci
2521e41f4b71Sopenharmony_ciattachBrush(brush: Brush): void
2522e41f4b71Sopenharmony_ci
2523e41f4b71Sopenharmony_ciAttaches a brush to a canvas so that the canvas can use the style and color of the brush to fill in a shape.
2524e41f4b71Sopenharmony_ci
2525e41f4b71Sopenharmony_ci> **NOTE**
2526e41f4b71Sopenharmony_ci>
2527e41f4b71Sopenharmony_ci> If the brush effect changes after this API is called, you must call the API again if you want to use the new effect in the subsequent drawing.
2528e41f4b71Sopenharmony_ci
2529e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
2530e41f4b71Sopenharmony_ci
2531e41f4b71Sopenharmony_ci**Parameters**
2532e41f4b71Sopenharmony_ci
2533e41f4b71Sopenharmony_ci| Name| Type           | Mandatory| Description      |
2534e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ---------- |
2535e41f4b71Sopenharmony_ci| brush  | [Brush](#brush) | Yes  | **Brush** object.|
2536e41f4b71Sopenharmony_ci
2537e41f4b71Sopenharmony_ci**Error codes**
2538e41f4b71Sopenharmony_ci
2539e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2540e41f4b71Sopenharmony_ci
2541e41f4b71Sopenharmony_ci| ID| Error Message|
2542e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
2543e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2544e41f4b71Sopenharmony_ci
2545e41f4b71Sopenharmony_ci**Example**
2546e41f4b71Sopenharmony_ci
2547e41f4b71Sopenharmony_ci```ts
2548e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2549e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
2550e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2551e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2552e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2553e41f4b71Sopenharmony_ci    const brush = new drawing.Brush();
2554e41f4b71Sopenharmony_ci    brush.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2555e41f4b71Sopenharmony_ci    canvas.attachBrush(brush);
2556e41f4b71Sopenharmony_ci    canvas.drawRect({ left : 0, right : 10, top : 0, bottom : 10 });
2557e41f4b71Sopenharmony_ci    canvas.detachBrush();
2558e41f4b71Sopenharmony_ci  }
2559e41f4b71Sopenharmony_ci}
2560e41f4b71Sopenharmony_ci```
2561e41f4b71Sopenharmony_ci
2562e41f4b71Sopenharmony_ci### detachPen
2563e41f4b71Sopenharmony_ci
2564e41f4b71Sopenharmony_cidetachPen(): void
2565e41f4b71Sopenharmony_ci
2566e41f4b71Sopenharmony_ciDetaches the pen from a canvas so that the canvas can no longer use the style and color of the pen to outline a shape.
2567e41f4b71Sopenharmony_ci
2568e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
2569e41f4b71Sopenharmony_ci
2570e41f4b71Sopenharmony_ci**Example**
2571e41f4b71Sopenharmony_ci
2572e41f4b71Sopenharmony_ci```ts
2573e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2574e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
2575e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2576e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2577e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2578e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
2579e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
2580e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2581e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
2582e41f4b71Sopenharmony_ci    canvas.drawRect({ left : 0, right : 10, top : 0, bottom : 10 });
2583e41f4b71Sopenharmony_ci    canvas.detachPen();
2584e41f4b71Sopenharmony_ci  }
2585e41f4b71Sopenharmony_ci}
2586e41f4b71Sopenharmony_ci```
2587e41f4b71Sopenharmony_ci
2588e41f4b71Sopenharmony_ci### detachBrush
2589e41f4b71Sopenharmony_ci
2590e41f4b71Sopenharmony_cidetachBrush(): void
2591e41f4b71Sopenharmony_ci
2592e41f4b71Sopenharmony_ciDetaches the brush from a canvas so that the canvas can no longer use the style and color of the brush to fill in a shape.
2593e41f4b71Sopenharmony_ci
2594e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
2595e41f4b71Sopenharmony_ci
2596e41f4b71Sopenharmony_ci**Example**
2597e41f4b71Sopenharmony_ci
2598e41f4b71Sopenharmony_ci```ts
2599e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2600e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
2601e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2602e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2603e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2604e41f4b71Sopenharmony_ci    const brush = new drawing.Brush();
2605e41f4b71Sopenharmony_ci    brush.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2606e41f4b71Sopenharmony_ci    canvas.attachBrush(brush);
2607e41f4b71Sopenharmony_ci    canvas.drawRect({ left : 0, right : 10, top : 0, bottom : 10 });
2608e41f4b71Sopenharmony_ci    canvas.detachBrush();
2609e41f4b71Sopenharmony_ci  }
2610e41f4b71Sopenharmony_ci}
2611e41f4b71Sopenharmony_ci```
2612e41f4b71Sopenharmony_ci
2613e41f4b71Sopenharmony_ci### clipPath<sup>12+</sup>
2614e41f4b71Sopenharmony_ci
2615e41f4b71Sopenharmony_ciclipPath(path: Path, clipOp?: ClipOp, doAntiAlias?: boolean): void
2616e41f4b71Sopenharmony_ci
2617e41f4b71Sopenharmony_ciClips a path.
2618e41f4b71Sopenharmony_ci
2619e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
2620e41f4b71Sopenharmony_ci
2621e41f4b71Sopenharmony_ci**Parameters**
2622e41f4b71Sopenharmony_ci
2623e41f4b71Sopenharmony_ci| Name      | Type              | Mandatory| Description                               |
2624e41f4b71Sopenharmony_ci| ------------ | ----------------- | ---- | ------------------------------------|
2625e41f4b71Sopenharmony_ci| path         | [Path](#path)     | Yes  | **Path** object.                                                |
2626e41f4b71Sopenharmony_ci| clipOp       | [ClipOp](#clipop12) | No  | Clip mode. The default value is **INTERSECT**.                                    |
2627e41f4b71Sopenharmony_ci| doAntiAlias  | boolean           | No  | Whether to enable anti-aliasing. The value **true** means to enable anti-aliasing, and **false** means the opposite. The default value is **false**.|
2628e41f4b71Sopenharmony_ci
2629e41f4b71Sopenharmony_ci**Error codes**
2630e41f4b71Sopenharmony_ci
2631e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2632e41f4b71Sopenharmony_ci
2633e41f4b71Sopenharmony_ci| ID| Error Message|
2634e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
2635e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2636e41f4b71Sopenharmony_ci
2637e41f4b71Sopenharmony_ci**Example**
2638e41f4b71Sopenharmony_ci
2639e41f4b71Sopenharmony_ci```ts
2640e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2641e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
2642e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2643e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2644e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2645e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
2646e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
2647e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2648e41f4b71Sopenharmony_ci    let path = new drawing.Path();
2649e41f4b71Sopenharmony_ci    path.moveTo(10, 10);
2650e41f4b71Sopenharmony_ci    path.cubicTo(10, 10, 10, 10, 15, 15);
2651e41f4b71Sopenharmony_ci    path.close();
2652e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
2653e41f4b71Sopenharmony_ci    canvas.clipPath(path, drawing.ClipOp.DIFFERENCE, true);
2654e41f4b71Sopenharmony_ci    canvas.detachPen();
2655e41f4b71Sopenharmony_ci  }
2656e41f4b71Sopenharmony_ci}
2657e41f4b71Sopenharmony_ci```
2658e41f4b71Sopenharmony_ci
2659e41f4b71Sopenharmony_ci### clipRect<sup>12+</sup>
2660e41f4b71Sopenharmony_ci
2661e41f4b71Sopenharmony_ciclipRect(rect: common2D.Rect, clipOp?: ClipOp, doAntiAlias?: boolean): void
2662e41f4b71Sopenharmony_ci
2663e41f4b71Sopenharmony_ciClips a rectangle.
2664e41f4b71Sopenharmony_ci
2665e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
2666e41f4b71Sopenharmony_ci
2667e41f4b71Sopenharmony_ci**Parameters**
2668e41f4b71Sopenharmony_ci
2669e41f4b71Sopenharmony_ci| Name        | Type                                      | Mandatory  | Description                 |
2670e41f4b71Sopenharmony_ci| ----------- | ---------------------------------------- | ---- | ------------------- |
2671e41f4b71Sopenharmony_ci| rect        | [common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes   | Rectangle.     |
2672e41f4b71Sopenharmony_ci| clipOp      | [ClipOp](#clipop12)                  | No   | Clip mode. The default value is **INTERSECT**.    |
2673e41f4b71Sopenharmony_ci| doAntiAlias | boolean           | No  | Whether to enable anti-aliasing. The value **true** means to enable anti-aliasing, and **false** means the opposite. The default value is **false**.|
2674e41f4b71Sopenharmony_ci
2675e41f4b71Sopenharmony_ci**Error codes**
2676e41f4b71Sopenharmony_ci
2677e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2678e41f4b71Sopenharmony_ci
2679e41f4b71Sopenharmony_ci| ID| Error Message|
2680e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
2681e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2682e41f4b71Sopenharmony_ci
2683e41f4b71Sopenharmony_ci**Example**
2684e41f4b71Sopenharmony_ci
2685e41f4b71Sopenharmony_ci```ts
2686e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2687e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
2688e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2689e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2690e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2691e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
2692e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
2693e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2694e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
2695e41f4b71Sopenharmony_ci    canvas.clipRect({left : 10, right : 500, top : 300, bottom : 900}, drawing.ClipOp.DIFFERENCE, true);
2696e41f4b71Sopenharmony_ci    canvas.detachPen();
2697e41f4b71Sopenharmony_ci  }
2698e41f4b71Sopenharmony_ci}
2699e41f4b71Sopenharmony_ci```
2700e41f4b71Sopenharmony_ci
2701e41f4b71Sopenharmony_ci### save<sup>12+</sup>
2702e41f4b71Sopenharmony_ci
2703e41f4b71Sopenharmony_cisave(): number
2704e41f4b71Sopenharmony_ci
2705e41f4b71Sopenharmony_ciSaves the current canvas status (canvas matrix) to the top of the stack.
2706e41f4b71Sopenharmony_ci
2707e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
2708e41f4b71Sopenharmony_ci
2709e41f4b71Sopenharmony_ci**Return value**
2710e41f4b71Sopenharmony_ci
2711e41f4b71Sopenharmony_ci| Type  | Description               |
2712e41f4b71Sopenharmony_ci| ------ | ------------------ |
2713e41f4b71Sopenharmony_ci| number | Number of canvas statuses. The value is a positive integer.|
2714e41f4b71Sopenharmony_ci
2715e41f4b71Sopenharmony_ci**Example**
2716e41f4b71Sopenharmony_ci
2717e41f4b71Sopenharmony_ci```ts
2718e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2719e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
2720e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2721e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2722e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2723e41f4b71Sopenharmony_ci    let rect: common2D.Rect = {left: 10, right: 200, top: 100, bottom: 300};
2724e41f4b71Sopenharmony_ci    canvas.drawRect(rect);
2725e41f4b71Sopenharmony_ci    let saveCount = canvas.save();
2726e41f4b71Sopenharmony_ci  }
2727e41f4b71Sopenharmony_ci}
2728e41f4b71Sopenharmony_ci```
2729e41f4b71Sopenharmony_ci
2730e41f4b71Sopenharmony_ci### saveLayer<sup>12+</sup>
2731e41f4b71Sopenharmony_ci
2732e41f4b71Sopenharmony_cisaveLayer(rect?: common2D.Rect | null, brush?: Brush | null): number
2733e41f4b71Sopenharmony_ci
2734e41f4b71Sopenharmony_ciSaves the matrix and cropping region of the canvas, and allocates a bitmap for subsequent drawing. If you call [restore](#restore12), the changes made to the matrix and clipping region are discarded, and the bitmap is drawn.
2735e41f4b71Sopenharmony_ci
2736e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
2737e41f4b71Sopenharmony_ci
2738e41f4b71Sopenharmony_ci**Parameters**
2739e41f4b71Sopenharmony_ci
2740e41f4b71Sopenharmony_ci| Name | Type    | Mandatory  | Description        |
2741e41f4b71Sopenharmony_ci| ---- | ------ | ---- | ----------------- |
2742e41f4b71Sopenharmony_ci| rect   | [common2D.Rect](js-apis-graphics-common2D.md#rect)\|null | No  | **Rect** object, which is used to limit the size of the graphics layer. The default value is the current canvas size.|
2743e41f4b71Sopenharmony_ci| brush  | [Brush](#brush)\|null | No  | **Brush** object. The alpha value, filter effect, and blend mode of the brush are applied when the bitmap is drawn. If null is passed in, no effect is applied.|
2744e41f4b71Sopenharmony_ci
2745e41f4b71Sopenharmony_ci**Return value**
2746e41f4b71Sopenharmony_ci
2747e41f4b71Sopenharmony_ci| Type  | Description               |
2748e41f4b71Sopenharmony_ci| ------ | ------------------ |
2749e41f4b71Sopenharmony_ci| number | Number of canvas statuses that have been saved. The value is a positive integer.|
2750e41f4b71Sopenharmony_ci
2751e41f4b71Sopenharmony_ci**Error codes**
2752e41f4b71Sopenharmony_ci
2753e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2754e41f4b71Sopenharmony_ci
2755e41f4b71Sopenharmony_ci| ID| Error Message|
2756e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
2757e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. |
2758e41f4b71Sopenharmony_ci
2759e41f4b71Sopenharmony_ci**Example**
2760e41f4b71Sopenharmony_ci
2761e41f4b71Sopenharmony_ci```ts
2762e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2763e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
2764e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2765e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2766e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2767e41f4b71Sopenharmony_ci    canvas.saveLayer(null, null);
2768e41f4b71Sopenharmony_ci    const brushRect = new drawing.Brush();
2769e41f4b71Sopenharmony_ci    const colorRect: common2D.Color = {alpha: 255, red: 255, green: 255, blue: 0};
2770e41f4b71Sopenharmony_ci    brushRect.setColor(colorRect);
2771e41f4b71Sopenharmony_ci    canvas.attachBrush(brushRect);
2772e41f4b71Sopenharmony_ci    const rect: common2D.Rect = {left:100, top:100, right:500, bottom:500};
2773e41f4b71Sopenharmony_ci    canvas.drawRect(rect);
2774e41f4b71Sopenharmony_ci
2775e41f4b71Sopenharmony_ci    const brush = new drawing.Brush();
2776e41f4b71Sopenharmony_ci    brush.setBlendMode(drawing.BlendMode.DST_OUT);
2777e41f4b71Sopenharmony_ci    canvas.saveLayer(rect, brush);
2778e41f4b71Sopenharmony_ci
2779e41f4b71Sopenharmony_ci    const brushCircle = new drawing.Brush();
2780e41f4b71Sopenharmony_ci    const colorCircle: common2D.Color = {alpha: 255, red: 0, green: 0, blue: 255};
2781e41f4b71Sopenharmony_ci    brushCircle.setColor(colorCircle);
2782e41f4b71Sopenharmony_ci    canvas.attachBrush(brushCircle);
2783e41f4b71Sopenharmony_ci    canvas.drawCircle(500, 500, 200);
2784e41f4b71Sopenharmony_ci    canvas.restore();
2785e41f4b71Sopenharmony_ci    canvas.restore();
2786e41f4b71Sopenharmony_ci    canvas.detachBrush();
2787e41f4b71Sopenharmony_ci  }
2788e41f4b71Sopenharmony_ci}
2789e41f4b71Sopenharmony_ci```
2790e41f4b71Sopenharmony_ci
2791e41f4b71Sopenharmony_ci### scale<sup>12+</sup>
2792e41f4b71Sopenharmony_ci
2793e41f4b71Sopenharmony_ciscale(sx: number, sy: number): void
2794e41f4b71Sopenharmony_ci
2795e41f4b71Sopenharmony_ciScales the canvas.
2796e41f4b71Sopenharmony_ci
2797e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
2798e41f4b71Sopenharmony_ci
2799e41f4b71Sopenharmony_ci**Parameters**
2800e41f4b71Sopenharmony_ci
2801e41f4b71Sopenharmony_ci| Name | Type    | Mandatory  | Description        |
2802e41f4b71Sopenharmony_ci| ---- | ------ | ---- | ----------------- |
2803e41f4b71Sopenharmony_ci| sx   | number | Yes  | Scale ratio on the X axis. The value is a floating point number.|
2804e41f4b71Sopenharmony_ci| sy   | number | Yes  | Scale ratio on the Y axis. The value is a floating point number.|
2805e41f4b71Sopenharmony_ci
2806e41f4b71Sopenharmony_ci**Error codes**
2807e41f4b71Sopenharmony_ci
2808e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2809e41f4b71Sopenharmony_ci
2810e41f4b71Sopenharmony_ci| ID| Error Message|
2811e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
2812e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2813e41f4b71Sopenharmony_ci
2814e41f4b71Sopenharmony_ci**Example**
2815e41f4b71Sopenharmony_ci
2816e41f4b71Sopenharmony_ci```ts
2817e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2818e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
2819e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2820e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2821e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2822e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
2823e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
2824e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2825e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
2826e41f4b71Sopenharmony_ci    canvas.scale(2, 0.5);
2827e41f4b71Sopenharmony_ci    canvas.drawRect({left : 10, right : 500, top : 300, bottom : 900});
2828e41f4b71Sopenharmony_ci    canvas.detachPen();
2829e41f4b71Sopenharmony_ci  }
2830e41f4b71Sopenharmony_ci}
2831e41f4b71Sopenharmony_ci```
2832e41f4b71Sopenharmony_ci
2833e41f4b71Sopenharmony_ci### skew<sup>12+</sup>
2834e41f4b71Sopenharmony_ci
2835e41f4b71Sopenharmony_ciskew(sx: number, sy: number) : void
2836e41f4b71Sopenharmony_ci
2837e41f4b71Sopenharmony_ciSkews the canvas in both the horizontal and vertical directions.
2838e41f4b71Sopenharmony_ci
2839e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
2840e41f4b71Sopenharmony_ci
2841e41f4b71Sopenharmony_ci**Parameters**
2842e41f4b71Sopenharmony_ci
2843e41f4b71Sopenharmony_ci| Name | Type    | Mandatory  | Description        |
2844e41f4b71Sopenharmony_ci| ---- | ------ | ---- | ----------------- |
2845e41f4b71Sopenharmony_ci| sx   | number | Yes  | Amount of tilt on the X axis. The value is a floating point number.   |
2846e41f4b71Sopenharmony_ci| sy   | number | Yes  | Amount of tilt on the Y axis. The value is a floating point number.   |
2847e41f4b71Sopenharmony_ci
2848e41f4b71Sopenharmony_ci**Error codes**
2849e41f4b71Sopenharmony_ci
2850e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2851e41f4b71Sopenharmony_ci
2852e41f4b71Sopenharmony_ci| ID| Error Message|
2853e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
2854e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2855e41f4b71Sopenharmony_ci
2856e41f4b71Sopenharmony_ci**Example**
2857e41f4b71Sopenharmony_ci
2858e41f4b71Sopenharmony_ci```ts
2859e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2860e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
2861e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2862e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2863e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2864e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
2865e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
2866e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2867e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
2868e41f4b71Sopenharmony_ci    canvas.skew(0.1, 0.1);
2869e41f4b71Sopenharmony_ci    canvas.drawRect({left : 10, right : 500, top : 300, bottom : 900});
2870e41f4b71Sopenharmony_ci    canvas.detachPen();
2871e41f4b71Sopenharmony_ci  }
2872e41f4b71Sopenharmony_ci}
2873e41f4b71Sopenharmony_ci```
2874e41f4b71Sopenharmony_ci
2875e41f4b71Sopenharmony_ci### rotate<sup>12+</sup>
2876e41f4b71Sopenharmony_ci
2877e41f4b71Sopenharmony_cirotate(degrees: number, sx: number, sy: number) : void
2878e41f4b71Sopenharmony_ci
2879e41f4b71Sopenharmony_ciRotates the canvas by a certain angle.
2880e41f4b71Sopenharmony_ci
2881e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
2882e41f4b71Sopenharmony_ci
2883e41f4b71Sopenharmony_ci**Parameters**
2884e41f4b71Sopenharmony_ci
2885e41f4b71Sopenharmony_ci| Name | Type    | Mandatory  | Description        |
2886e41f4b71Sopenharmony_ci| ---- | ------ | ------ | ------------------------ |
2887e41f4b71Sopenharmony_ci| degrees       | number | Yes   | Angle to rotate, in degrees. The value is a floating point number. A positive value indicates a clockwise rotation, and a negative value indicates a counterclockwise rotation. |
2888e41f4b71Sopenharmony_ci| sx            | number | Yes   | X coordinate of the rotation center. The value is a floating point number.|
2889e41f4b71Sopenharmony_ci| sy            | number | Yes   | Y coordinate of the rotation center. The value is a floating point number.|
2890e41f4b71Sopenharmony_ci
2891e41f4b71Sopenharmony_ci**Error codes**
2892e41f4b71Sopenharmony_ci
2893e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2894e41f4b71Sopenharmony_ci
2895e41f4b71Sopenharmony_ci| ID| Error Message|
2896e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
2897e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2898e41f4b71Sopenharmony_ci
2899e41f4b71Sopenharmony_ci**Example**
2900e41f4b71Sopenharmony_ci
2901e41f4b71Sopenharmony_ci```ts
2902e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2903e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
2904e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2905e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2906e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2907e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
2908e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
2909e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2910e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
2911e41f4b71Sopenharmony_ci    canvas.rotate(30, 100, 100);
2912e41f4b71Sopenharmony_ci    canvas.drawRect({left : 10, right : 500, top : 300, bottom : 900});
2913e41f4b71Sopenharmony_ci    canvas.detachPen();
2914e41f4b71Sopenharmony_ci  }
2915e41f4b71Sopenharmony_ci}
2916e41f4b71Sopenharmony_ci```
2917e41f4b71Sopenharmony_ci
2918e41f4b71Sopenharmony_ci### translate<sup>12+</sup>
2919e41f4b71Sopenharmony_ci
2920e41f4b71Sopenharmony_citranslate(dx: number, dy: number): void
2921e41f4b71Sopenharmony_ci
2922e41f4b71Sopenharmony_ciTranslates the canvas by a given distance.
2923e41f4b71Sopenharmony_ci
2924e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
2925e41f4b71Sopenharmony_ci
2926e41f4b71Sopenharmony_ci**Parameters**
2927e41f4b71Sopenharmony_ci
2928e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description               |
2929e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ------------------- |
2930e41f4b71Sopenharmony_ci| dx    | number | Yes  | Distance to translate on the X axis. The value is a floating point number.  |
2931e41f4b71Sopenharmony_ci| dy    | number | Yes  | Distance to translate on the Y axis. The value is a floating point number.  |
2932e41f4b71Sopenharmony_ci
2933e41f4b71Sopenharmony_ci**Error codes**
2934e41f4b71Sopenharmony_ci
2935e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2936e41f4b71Sopenharmony_ci
2937e41f4b71Sopenharmony_ci| ID| Error Message|
2938e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
2939e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2940e41f4b71Sopenharmony_ci
2941e41f4b71Sopenharmony_ci**Example**
2942e41f4b71Sopenharmony_ci
2943e41f4b71Sopenharmony_ci```ts
2944e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2945e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
2946e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2947e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2948e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2949e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
2950e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
2951e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2952e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
2953e41f4b71Sopenharmony_ci    canvas.translate(10, 10);
2954e41f4b71Sopenharmony_ci    canvas.drawRect({left : 10, right : 500, top : 300, bottom : 900});
2955e41f4b71Sopenharmony_ci    canvas.detachPen();
2956e41f4b71Sopenharmony_ci  }
2957e41f4b71Sopenharmony_ci}
2958e41f4b71Sopenharmony_ci```
2959e41f4b71Sopenharmony_ci
2960e41f4b71Sopenharmony_ci### getSaveCount<sup>12+</sup>
2961e41f4b71Sopenharmony_ci
2962e41f4b71Sopenharmony_cigetSaveCount(): number
2963e41f4b71Sopenharmony_ci
2964e41f4b71Sopenharmony_ciObtains the number of canvas statuses (canvas matrices) saved in the stack.
2965e41f4b71Sopenharmony_ci
2966e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
2967e41f4b71Sopenharmony_ci
2968e41f4b71Sopenharmony_ci**Return value**
2969e41f4b71Sopenharmony_ci
2970e41f4b71Sopenharmony_ci| Type   | Description                                |
2971e41f4b71Sopenharmony_ci| ------ | ------------------------------------ |
2972e41f4b71Sopenharmony_ci| number | Number of canvas statuses that have been saved. The value is a positive integer.|
2973e41f4b71Sopenharmony_ci
2974e41f4b71Sopenharmony_ci**Example**
2975e41f4b71Sopenharmony_ci
2976e41f4b71Sopenharmony_ci```ts
2977e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
2978e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
2979e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
2980e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
2981e41f4b71Sopenharmony_ci    const canvas = context.canvas;
2982e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
2983e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
2984e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2985e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
2986e41f4b71Sopenharmony_ci    canvas.drawRect({left: 10, right: 200, top: 100, bottom: 300});
2987e41f4b71Sopenharmony_ci    canvas.save();
2988e41f4b71Sopenharmony_ci    canvas.drawRect({left : 10, right : 500, top : 300, bottom : 900});
2989e41f4b71Sopenharmony_ci    canvas.getSaveCount();
2990e41f4b71Sopenharmony_ci    canvas.detachPen();
2991e41f4b71Sopenharmony_ci  }
2992e41f4b71Sopenharmony_ci}
2993e41f4b71Sopenharmony_ci```
2994e41f4b71Sopenharmony_ci
2995e41f4b71Sopenharmony_ci### restoreToCount<sup>12+</sup>
2996e41f4b71Sopenharmony_ci
2997e41f4b71Sopenharmony_cirestoreToCount(count: number): void
2998e41f4b71Sopenharmony_ci
2999e41f4b71Sopenharmony_ciRestores to a given number of canvas statuses (canvas matrices).
3000e41f4b71Sopenharmony_ci
3001e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3002e41f4b71Sopenharmony_ci
3003e41f4b71Sopenharmony_ci**Parameters**
3004e41f4b71Sopenharmony_ci
3005e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory  | Description                   |
3006e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ----------------------------- |
3007e41f4b71Sopenharmony_ci| count | number | Yes  | Depth of the canvas statuses to restore. The value is an integer. If the value is less than or equal to 1, the canvas is restored to the initial state. If the value is greater than the number of canvas statuses that have been saved, no operation is performed.|
3008e41f4b71Sopenharmony_ci
3009e41f4b71Sopenharmony_ci**Error codes**
3010e41f4b71Sopenharmony_ci
3011e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3012e41f4b71Sopenharmony_ci
3013e41f4b71Sopenharmony_ci| ID| Error Message|
3014e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
3015e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
3016e41f4b71Sopenharmony_ci
3017e41f4b71Sopenharmony_ci**Example**
3018e41f4b71Sopenharmony_ci
3019e41f4b71Sopenharmony_ci```ts
3020e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
3021e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
3022e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
3023e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
3024e41f4b71Sopenharmony_ci    const canvas = context.canvas;
3025e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
3026e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
3027e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
3028e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
3029e41f4b71Sopenharmony_ci    canvas.drawRect({left: 10, right: 200, top: 100, bottom: 300});
3030e41f4b71Sopenharmony_ci    canvas.save();
3031e41f4b71Sopenharmony_ci    canvas.drawRect({left: 10, right: 200, top: 100, bottom: 500});
3032e41f4b71Sopenharmony_ci    canvas.save();
3033e41f4b71Sopenharmony_ci    canvas.drawRect({left: 100, right: 300, top: 100, bottom: 500});
3034e41f4b71Sopenharmony_ci    canvas.save();
3035e41f4b71Sopenharmony_ci    canvas.restoreToCount(2);
3036e41f4b71Sopenharmony_ci    canvas.drawRect({left : 10, right : 500, top : 300, bottom : 900});
3037e41f4b71Sopenharmony_ci    canvas.detachPen();
3038e41f4b71Sopenharmony_ci  }
3039e41f4b71Sopenharmony_ci}
3040e41f4b71Sopenharmony_ci```
3041e41f4b71Sopenharmony_ci
3042e41f4b71Sopenharmony_ci### restore<sup>12+</sup>
3043e41f4b71Sopenharmony_ci
3044e41f4b71Sopenharmony_cirestore(): void
3045e41f4b71Sopenharmony_ci
3046e41f4b71Sopenharmony_ciRestores the canvas status (canvas matrix) saved on the top of the stack.
3047e41f4b71Sopenharmony_ci
3048e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3049e41f4b71Sopenharmony_ci
3050e41f4b71Sopenharmony_ci**Example**
3051e41f4b71Sopenharmony_ci
3052e41f4b71Sopenharmony_ci```ts
3053e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
3054e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
3055e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
3056e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
3057e41f4b71Sopenharmony_ci    const canvas = context.canvas;
3058e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
3059e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
3060e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
3061e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
3062e41f4b71Sopenharmony_ci    canvas.restore();
3063e41f4b71Sopenharmony_ci    canvas.detachPen();
3064e41f4b71Sopenharmony_ci  }
3065e41f4b71Sopenharmony_ci}
3066e41f4b71Sopenharmony_ci```
3067e41f4b71Sopenharmony_ci
3068e41f4b71Sopenharmony_ci### concatMatrix<sup>12+</sup>
3069e41f4b71Sopenharmony_ci
3070e41f4b71Sopenharmony_ciconcatMatrix(matrix: Matrix): void
3071e41f4b71Sopenharmony_ci
3072e41f4b71Sopenharmony_ciPreconcats the existing matrix of the canvas with the passed-in matrix. The drawing operation triggered before this API is called is not affected.
3073e41f4b71Sopenharmony_ci
3074e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3075e41f4b71Sopenharmony_ci
3076e41f4b71Sopenharmony_ci**Parameters**
3077e41f4b71Sopenharmony_ci
3078e41f4b71Sopenharmony_ci| Name   | Type               | Mandatory  | Description   |
3079e41f4b71Sopenharmony_ci| ------ | ----------------- | ---- | ----- |
3080e41f4b71Sopenharmony_ci| matrix | [Matrix](#matrix12) | Yes   | **Matrix** object.|
3081e41f4b71Sopenharmony_ci
3082e41f4b71Sopenharmony_ci**Error codes**
3083e41f4b71Sopenharmony_ci
3084e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3085e41f4b71Sopenharmony_ci
3086e41f4b71Sopenharmony_ci| ID| Error Message|
3087e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
3088e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
3089e41f4b71Sopenharmony_ci
3090e41f4b71Sopenharmony_ci**Example**
3091e41f4b71Sopenharmony_ci
3092e41f4b71Sopenharmony_ci```ts
3093e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
3094e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
3095e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
3096e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
3097e41f4b71Sopenharmony_ci    const canvas = context.canvas;
3098e41f4b71Sopenharmony_ci    let matrix = new drawing.Matrix();
3099e41f4b71Sopenharmony_ci    matrix.setMatrix([5, 0, 0, 0, 1, 2, 0, 0, 1]);
3100e41f4b71Sopenharmony_ci    canvas.concatMatrix(matrix);
3101e41f4b71Sopenharmony_ci  }
3102e41f4b71Sopenharmony_ci}
3103e41f4b71Sopenharmony_ci```
3104e41f4b71Sopenharmony_ci
3105e41f4b71Sopenharmony_ci### setMatrix<sup>12+</sup>
3106e41f4b71Sopenharmony_ci
3107e41f4b71Sopenharmony_cisetMatrix(matrix: Matrix): void
3108e41f4b71Sopenharmony_ci
3109e41f4b71Sopenharmony_ciSets a matrix for the canvas.
3110e41f4b71Sopenharmony_ci
3111e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3112e41f4b71Sopenharmony_ci
3113e41f4b71Sopenharmony_ci**Parameters**
3114e41f4b71Sopenharmony_ci
3115e41f4b71Sopenharmony_ci| Name   | Type               | Mandatory  | Description   |
3116e41f4b71Sopenharmony_ci| ------ | ----------------- | ---- | ----- |
3117e41f4b71Sopenharmony_ci| matrix | [Matrix](#matrix12) | Yes   | **Matrix** object.|
3118e41f4b71Sopenharmony_ci
3119e41f4b71Sopenharmony_ci**Error codes**
3120e41f4b71Sopenharmony_ci
3121e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3122e41f4b71Sopenharmony_ci
3123e41f4b71Sopenharmony_ci| ID| Error Message|
3124e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
3125e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
3126e41f4b71Sopenharmony_ci
3127e41f4b71Sopenharmony_ci**Example**
3128e41f4b71Sopenharmony_ci
3129e41f4b71Sopenharmony_ci```ts
3130e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
3131e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
3132e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
3133e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
3134e41f4b71Sopenharmony_ci    const canvas = context.canvas;
3135e41f4b71Sopenharmony_ci    let matrix = new drawing.Matrix()
3136e41f4b71Sopenharmony_ci    matrix.setMatrix([5, 0, 0, 0, 1, 1, 0, 0, 1]);
3137e41f4b71Sopenharmony_ci    canvas.setMatrix(matrix);
3138e41f4b71Sopenharmony_ci  }
3139e41f4b71Sopenharmony_ci}
3140e41f4b71Sopenharmony_ci```
3141e41f4b71Sopenharmony_ci
3142e41f4b71Sopenharmony_ci### isClipEmpty<sup>12+</sup>
3143e41f4b71Sopenharmony_ci
3144e41f4b71Sopenharmony_ciisClipEmpty(): boolean
3145e41f4b71Sopenharmony_ci
3146e41f4b71Sopenharmony_ciChecks whether the region that can be drawn is empty after clipping.
3147e41f4b71Sopenharmony_ci
3148e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3149e41f4b71Sopenharmony_ci
3150e41f4b71Sopenharmony_ci**Return value**
3151e41f4b71Sopenharmony_ci
3152e41f4b71Sopenharmony_ci| Type                 | Description          |
3153e41f4b71Sopenharmony_ci| --------------------- | -------------- |
3154e41f4b71Sopenharmony_ci| boolean | Chek result. The value **true** means that the region is empty, and **false** means the opposite.|
3155e41f4b71Sopenharmony_ci
3156e41f4b71Sopenharmony_ci**Example**
3157e41f4b71Sopenharmony_ci
3158e41f4b71Sopenharmony_ci```ts
3159e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
3160e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
3161e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
3162e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
3163e41f4b71Sopenharmony_ci    const canvas = context.canvas;
3164e41f4b71Sopenharmony_ci    if (canvas.isClipEmpty()) {
3165e41f4b71Sopenharmony_ci      console.info("canvas.isClipEmpty() returned true");
3166e41f4b71Sopenharmony_ci    } else {
3167e41f4b71Sopenharmony_ci      console.info("canvas.isClipEmpty() returned false");
3168e41f4b71Sopenharmony_ci    }
3169e41f4b71Sopenharmony_ci  }
3170e41f4b71Sopenharmony_ci}
3171e41f4b71Sopenharmony_ci```
3172e41f4b71Sopenharmony_ci
3173e41f4b71Sopenharmony_ci### clipRegion<sup>12+</sup>
3174e41f4b71Sopenharmony_ci
3175e41f4b71Sopenharmony_ciclipRegion(region: Region, clipOp?: ClipOp): void
3176e41f4b71Sopenharmony_ci
3177e41f4b71Sopenharmony_ciClips a region on the canvas.
3178e41f4b71Sopenharmony_ci
3179e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3180e41f4b71Sopenharmony_ci
3181e41f4b71Sopenharmony_ci**Parameters**
3182e41f4b71Sopenharmony_ci
3183e41f4b71Sopenharmony_ci| Name         | Type   | Mandatory| Description                                                       |
3184e41f4b71Sopenharmony_ci| --------------- | ------- | ---- | ----------------------------------------------------------- |
3185e41f4b71Sopenharmony_ci| region | [Region](#region12) | Yes  | **Region** object, which indicates the range to clip.|
3186e41f4b71Sopenharmony_ci| clipOp | [ClipOp](#clipop12)   | No  | Clipping mode. The default value is **INTERSECT**.|
3187e41f4b71Sopenharmony_ci
3188e41f4b71Sopenharmony_ci**Error codes**
3189e41f4b71Sopenharmony_ci
3190e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3191e41f4b71Sopenharmony_ci
3192e41f4b71Sopenharmony_ci| ID| Error Message|
3193e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
3194e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
3195e41f4b71Sopenharmony_ci
3196e41f4b71Sopenharmony_ci**Example**
3197e41f4b71Sopenharmony_ci
3198e41f4b71Sopenharmony_ci```ts
3199e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
3200e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
3201e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
3202e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
3203e41f4b71Sopenharmony_ci    const canvas = context.canvas;
3204e41f4b71Sopenharmony_ci    let region : drawing.Region = new drawing.Region();
3205e41f4b71Sopenharmony_ci    region.setRect(0, 0, 500, 500);
3206e41f4b71Sopenharmony_ci    canvas.clipRegion(region);
3207e41f4b71Sopenharmony_ci  }
3208e41f4b71Sopenharmony_ci}
3209e41f4b71Sopenharmony_ci```
3210e41f4b71Sopenharmony_ci
3211e41f4b71Sopenharmony_ci### clipRoundRect<sup>12+</sup>
3212e41f4b71Sopenharmony_ci
3213e41f4b71Sopenharmony_ciclipRoundRect(roundRect: RoundRect, clipOp?: ClipOp, doAntiAlias?: boolean): void
3214e41f4b71Sopenharmony_ci
3215e41f4b71Sopenharmony_ciClips a rounded rectangle on the canvas.
3216e41f4b71Sopenharmony_ci
3217e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3218e41f4b71Sopenharmony_ci
3219e41f4b71Sopenharmony_ci**Parameters**
3220e41f4b71Sopenharmony_ci
3221e41f4b71Sopenharmony_ci| Name         | Type   | Mandatory| Description                                                       |
3222e41f4b71Sopenharmony_ci| --------------- | ------- | ---- | ----------------------------------------------------------- |
3223e41f4b71Sopenharmony_ci| roundRect | [RoundRect](#roundrect12) | Yes  | **RoundRect** object, which indicates the range to clip.|
3224e41f4b71Sopenharmony_ci| clipOp | [ClipOp](#clipop12)   | No  | Clipping mode. The default value is **INTERSECT**.|
3225e41f4b71Sopenharmony_ci| doAntiAlias | boolean | No  | Whether to enable anti-aliasing. The value **true** means to enable anti-aliasing, and **false** means the opposite. The default value is **false**.|
3226e41f4b71Sopenharmony_ci
3227e41f4b71Sopenharmony_ci**Error codes**
3228e41f4b71Sopenharmony_ci
3229e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3230e41f4b71Sopenharmony_ci
3231e41f4b71Sopenharmony_ci| ID| Error Message|
3232e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
3233e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
3234e41f4b71Sopenharmony_ci
3235e41f4b71Sopenharmony_ci**Example**
3236e41f4b71Sopenharmony_ci
3237e41f4b71Sopenharmony_ci```ts
3238e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
3239e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
3240e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
3241e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
3242e41f4b71Sopenharmony_ci    const canvas = context.canvas;
3243e41f4b71Sopenharmony_ci    let rect: common2D.Rect = { left: 10, top: 100, right: 200, bottom: 300 };
3244e41f4b71Sopenharmony_ci    let roundRect = new drawing.RoundRect(rect, 10, 10);
3245e41f4b71Sopenharmony_ci    canvas.clipRoundRect(roundRect);
3246e41f4b71Sopenharmony_ci  }
3247e41f4b71Sopenharmony_ci}
3248e41f4b71Sopenharmony_ci```
3249e41f4b71Sopenharmony_ci
3250e41f4b71Sopenharmony_ci### resetMatrix<sup>12+</sup>
3251e41f4b71Sopenharmony_ci
3252e41f4b71Sopenharmony_ciresetMatrix(): void
3253e41f4b71Sopenharmony_ci
3254e41f4b71Sopenharmony_ciResets the matrix of this canvas to an identity matrix.
3255e41f4b71Sopenharmony_ci
3256e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3257e41f4b71Sopenharmony_ci
3258e41f4b71Sopenharmony_ci**Example**
3259e41f4b71Sopenharmony_ci
3260e41f4b71Sopenharmony_ci```ts
3261e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
3262e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
3263e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
3264e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
3265e41f4b71Sopenharmony_ci    const canvas = context.canvas;
3266e41f4b71Sopenharmony_ci    canvas.scale(4, 6);
3267e41f4b71Sopenharmony_ci    canvas.resetMatrix();
3268e41f4b71Sopenharmony_ci  }
3269e41f4b71Sopenharmony_ci}
3270e41f4b71Sopenharmony_ci```
3271e41f4b71Sopenharmony_ci
3272e41f4b71Sopenharmony_ci## ImageFilter<sup>12+</sup>
3273e41f4b71Sopenharmony_ci
3274e41f4b71Sopenharmony_ciImplements an image filter.
3275e41f4b71Sopenharmony_ci
3276e41f4b71Sopenharmony_ci### createBlurImageFilter<sup>12+</sup>
3277e41f4b71Sopenharmony_ci
3278e41f4b71Sopenharmony_cistatic createBlurImageFilter(sigmaX: number, sigmaY: number, tileMode: TileMode, imageFilter?: ImageFilter | null ): ImageFilter
3279e41f4b71Sopenharmony_ci
3280e41f4b71Sopenharmony_ciCreates an image filter with a given blur effect.
3281e41f4b71Sopenharmony_ci
3282e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3283e41f4b71Sopenharmony_ci
3284e41f4b71Sopenharmony_ci**Parameters**
3285e41f4b71Sopenharmony_ci
3286e41f4b71Sopenharmony_ci| Name         | Type   | Mandatory| Description                                                       |
3287e41f4b71Sopenharmony_ci| --------------- | ------- | ---- | ----------------------------------------------------------- |
3288e41f4b71Sopenharmony_ci| sigmaX | number | Yes  | Standard deviation of the Gaussian blur along the X axis. The value must be a floating point number greater than 0.|
3289e41f4b71Sopenharmony_ci| sigmaY | number | Yes  | Standard deviation of the Gaussian blur along the Y axis. The value must be a floating point number greater than 0.|
3290e41f4b71Sopenharmony_ci| tileMode | [TileMode](#tilemode12)| Yes  | Tile mode to apply to the edges.|
3291e41f4b71Sopenharmony_ci| imageFilter | [ImageFilter](#imagefilter12) \| null | No  | Filter to which the image filter will be applied. The default value is null, indicating that the image filter is directly applied to the original image.|
3292e41f4b71Sopenharmony_ci
3293e41f4b71Sopenharmony_ci**Return value**
3294e41f4b71Sopenharmony_ci
3295e41f4b71Sopenharmony_ci| Type                 | Description          |
3296e41f4b71Sopenharmony_ci| --------------------- | -------------- |
3297e41f4b71Sopenharmony_ci| [ImageFilter](#imagefilter12) | Image filter created.|
3298e41f4b71Sopenharmony_ci
3299e41f4b71Sopenharmony_ci**Error codes**
3300e41f4b71Sopenharmony_ci
3301e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3302e41f4b71Sopenharmony_ci
3303e41f4b71Sopenharmony_ci| ID| Error Message|
3304e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
3305e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
3306e41f4b71Sopenharmony_ci
3307e41f4b71Sopenharmony_ci**Example**
3308e41f4b71Sopenharmony_ci
3309e41f4b71Sopenharmony_ci```ts
3310e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
3311e41f4b71Sopenharmony_cilet imgFilter = drawing.ImageFilter.createBlurImageFilter(5, 10, drawing.TileMode.CLAMP);
3312e41f4b71Sopenharmony_ci```
3313e41f4b71Sopenharmony_ci
3314e41f4b71Sopenharmony_ci### createFromColorFilter<sup>12+</sup>
3315e41f4b71Sopenharmony_ci
3316e41f4b71Sopenharmony_cistatic createFromColorFilter(colorFilter: ColorFilter, imageFilter?: ImageFilter | null): ImageFilter
3317e41f4b71Sopenharmony_ci
3318e41f4b71Sopenharmony_ciCreates an image filter object with a given color filter effect.
3319e41f4b71Sopenharmony_ci
3320e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3321e41f4b71Sopenharmony_ci
3322e41f4b71Sopenharmony_ci**Parameters**
3323e41f4b71Sopenharmony_ci
3324e41f4b71Sopenharmony_ci| Name         | Type   | Mandatory| Description                                                       |
3325e41f4b71Sopenharmony_ci| --------------- | ------- | ---- | ----------------------------------------------------------- |
3326e41f4b71Sopenharmony_ci| colorFilter | [ColorFilter](#colorfilter) | Yes  | Color filter.|
3327e41f4b71Sopenharmony_ci| imageFilter | [ImageFilter](#imagefilter12) \| null | No  | Filter to which the image filter will be applied. The default value is null, indicating that the image filter is directly applied to the original image.|
3328e41f4b71Sopenharmony_ci
3329e41f4b71Sopenharmony_ci**Return value**
3330e41f4b71Sopenharmony_ci
3331e41f4b71Sopenharmony_ci| Type                 | Description          |
3332e41f4b71Sopenharmony_ci| --------------------- | -------------- |
3333e41f4b71Sopenharmony_ci| [ImageFilter](#imagefilter12) | Image filter created.|
3334e41f4b71Sopenharmony_ci
3335e41f4b71Sopenharmony_ci**Error codes**
3336e41f4b71Sopenharmony_ci
3337e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3338e41f4b71Sopenharmony_ci
3339e41f4b71Sopenharmony_ci| ID| Error Message|
3340e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
3341e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
3342e41f4b71Sopenharmony_ci
3343e41f4b71Sopenharmony_ci**Example**
3344e41f4b71Sopenharmony_ci
3345e41f4b71Sopenharmony_ci```ts
3346e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
3347e41f4b71Sopenharmony_cilet imgFilter = drawing.ImageFilter.createBlurImageFilter(5, 10, drawing.TileMode.CLAMP);
3348e41f4b71Sopenharmony_cilet clolorfilter = drawing.ColorFilter.createSRGBGammaToLinear();
3349e41f4b71Sopenharmony_cilet imgFilter1 = drawing.ImageFilter.createFromColorFilter(clolorfilter, imgFilter);
3350e41f4b71Sopenharmony_ci```
3351e41f4b71Sopenharmony_ci
3352e41f4b71Sopenharmony_ci## TextBlobRunBuffer
3353e41f4b71Sopenharmony_ci
3354e41f4b71Sopenharmony_ciDescribes a series of consecutive glyphs with the same attributes in a text blob.
3355e41f4b71Sopenharmony_ci
3356e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3357e41f4b71Sopenharmony_ci
3358e41f4b71Sopenharmony_ci| Name     | Type  | Readable| Writable| Description                     |
3359e41f4b71Sopenharmony_ci| --------- | ------ | ---- | ---- | ------------------------- |
3360e41f4b71Sopenharmony_ci| glyph     | number | Yes  | Yes  | Index of the glyph. The value is an integer. If a floating point number is passed in, the value is rounded down.|
3361e41f4b71Sopenharmony_ci| positionX | number | Yes  | Yes  | X coordinate of the start point of the text blob. The value is a floating point number.|
3362e41f4b71Sopenharmony_ci| positionY | number | Yes  | Yes  | Y coordinate of the start point of the text blob. The value is a floating point number.|
3363e41f4b71Sopenharmony_ci
3364e41f4b71Sopenharmony_ci## TextEncoding
3365e41f4b71Sopenharmony_ci
3366e41f4b71Sopenharmony_ciEnumerates the text encoding types.
3367e41f4b71Sopenharmony_ci
3368e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3369e41f4b71Sopenharmony_ci
3370e41f4b71Sopenharmony_ci| Name                  | Value  | Description                          |
3371e41f4b71Sopenharmony_ci| ---------------------- | ---- | ------------------------------ |
3372e41f4b71Sopenharmony_ci| TEXT_ENCODING_UTF8     | 0    | One byte is used to indicate UTF-8 or ASCII characters. |
3373e41f4b71Sopenharmony_ci| TEXT_ENCODING_UTF16    | 1    | Two bytes are used to indicate most Unicode characters.|
3374e41f4b71Sopenharmony_ci| TEXT_ENCODING_UTF32    | 2    | Four bytes are used to indicate all Unicode characters.  |
3375e41f4b71Sopenharmony_ci| TEXT_ENCODING_GLYPH_ID | 3    | Two bytes are used to indicate the glyph index.  |
3376e41f4b71Sopenharmony_ci
3377e41f4b71Sopenharmony_ci## ClipOp<sup>12+</sup>
3378e41f4b71Sopenharmony_ciEnumerates the canvas clipping modes.
3379e41f4b71Sopenharmony_ci
3380e41f4b71Sopenharmony_ci
3381e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3382e41f4b71Sopenharmony_ci
3383e41f4b71Sopenharmony_ci| Name                | Value   | Description          | Diagram  |
3384e41f4b71Sopenharmony_ci| ------------------ | ---- | ---------------- | -------- |
3385e41f4b71Sopenharmony_ci| DIFFERENCE | 0    | Clips a specified area. That is, the difference set is obtained.| ![DIFFERENCE](./figures/image_ClipOp_Difference.png) |
3386e41f4b71Sopenharmony_ci| INTERSECT  | 1    | Retains a specified area. That is, the intersection is obtained.| ![INTERSECT](./figures/image_ClipOp_Intersect.png) |
3387e41f4b71Sopenharmony_ci
3388e41f4b71Sopenharmony_ci> **NOTE**
3389e41f4b71Sopenharmony_ci>
3390e41f4b71Sopenharmony_ci> The diagrams show the result of cropping a circle based on different enumerated values after a rectangle is cropped in INTERSECT mode. The green area is the final area obtained.
3391e41f4b71Sopenharmony_ci
3392e41f4b71Sopenharmony_ci## FilterMode<sup>12+</sup>
3393e41f4b71Sopenharmony_ci
3394e41f4b71Sopenharmony_ciEnumerates the filter modes.
3395e41f4b71Sopenharmony_ci
3396e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3397e41f4b71Sopenharmony_ci
3398e41f4b71Sopenharmony_ci| Name                 | Value   | Description     |
3399e41f4b71Sopenharmony_ci| ------------------- | ---- | ------- |
3400e41f4b71Sopenharmony_ci| FILTER_MODE_NEAREST | 0    | Nearest filter mode.|
3401e41f4b71Sopenharmony_ci| FILTER_MODE_LINEAR  | 1    | Linear filter mode.|
3402e41f4b71Sopenharmony_ci
3403e41f4b71Sopenharmony_ci## PathDirection<sup>12+</sup>
3404e41f4b71Sopenharmony_ci
3405e41f4b71Sopenharmony_ciEnumerates the directions of a closed contour.
3406e41f4b71Sopenharmony_ci
3407e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3408e41f4b71Sopenharmony_ci
3409e41f4b71Sopenharmony_ci| Name                 | Value   | Description     |
3410e41f4b71Sopenharmony_ci| ------------------- | ---- | ------- |
3411e41f4b71Sopenharmony_ci| CLOCKWISE   | 0    | Adds a closed contour clockwise.|
3412e41f4b71Sopenharmony_ci| COUNTER_CLOCKWISE  | 1    | Adds a closed contour counterclockwise.|
3413e41f4b71Sopenharmony_ci
3414e41f4b71Sopenharmony_ci## PathFillType<sup>12+</sup>
3415e41f4b71Sopenharmony_ci
3416e41f4b71Sopenharmony_ciEnumerates the fill types of a path.
3417e41f4b71Sopenharmony_ci
3418e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3419e41f4b71Sopenharmony_ci
3420e41f4b71Sopenharmony_ci| Name                 | Value   | Description     |
3421e41f4b71Sopenharmony_ci| ------------------- | ---- | ------- |
3422e41f4b71Sopenharmony_ci| WINDING   | 0    | Specifies that "inside" is computed by a non-zero sum of signed edge crossings. Specifically, draws a point and emits a ray in any direction. A count is used to record the number of intersection points of the ray and path, and the initial count is 0. When encountering a clockwise intersection point (the path passes from the left to the right of the ray), the count increases by 1. When encountering a counterclockwise intersection point (the path passes from the right to the left of the ray), the count decreases by 1. If the final count is not 0, the point is inside the path and needs to be colored. If the final count is 0, the point is not colored.|
3423e41f4b71Sopenharmony_ci| EVEN_ODD  | 1    | Specifies that "inside" is computed by an odd number of edge crossings. Specifically, draws a point and emits a ray in any direction. If the number of intersection points of the ray and path is an odd number, the point is considered to be inside the path and needs to be colored. If the number is an even number, the point is not colored.|
3424e41f4b71Sopenharmony_ci| INVERSE_WINDING  | 2    | Same as **WINDING**, but draws outside of the path, rather than inside.|
3425e41f4b71Sopenharmony_ci| INVERSE_EVEN_ODD  | 3    | Same as **EVEN_ODD**, but draws outside of the path, rather than inside.|
3426e41f4b71Sopenharmony_ci
3427e41f4b71Sopenharmony_ci> **NOTE**
3428e41f4b71Sopenharmony_ci> ![WINDING&EVEN_ODD](./figures/image_PathFillType_Winding_Even_Odd.png)
3429e41f4b71Sopenharmony_ci> As shown in the above figure, the path is a circle, the arrow indicates the path direction, **p** is any point "inside" the path, the blue line is the ray emitted from **p**, and the black arrow indicates the fill result using blue under the corresponding fill type. Under the **WINDING** fill rule, the number of intersection points of the ray and path is 2 (not 0), and therefore **p** is colored. Under the **EVEN_ODD** filling rule, the number of intersection points of the ray and path is 2 (an even number), and therefore **p** is not colored.
3430e41f4b71Sopenharmony_ci
3431e41f4b71Sopenharmony_ci## PointMode<sup>12+</sup>
3432e41f4b71Sopenharmony_ci
3433e41f4b71Sopenharmony_ciEnumerates the modes for drawing multiple points in an array.
3434e41f4b71Sopenharmony_ci
3435e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3436e41f4b71Sopenharmony_ci
3437e41f4b71Sopenharmony_ci| Name                | Value   | Description           |
3438e41f4b71Sopenharmony_ci| ------------------ | ---- | ------------- |
3439e41f4b71Sopenharmony_ci| POINTS  | 0    | Draws each point separately.     |
3440e41f4b71Sopenharmony_ci| LINES   | 1    | Draws every two points as a line segment.   |
3441e41f4b71Sopenharmony_ci| POLYGON | 2    | Draws an array of points as an open polygon.|
3442e41f4b71Sopenharmony_ci
3443e41f4b71Sopenharmony_ci## FontEdging<sup>12+</sup>
3444e41f4b71Sopenharmony_ci
3445e41f4b71Sopenharmony_ciEnumerates the font edging types.
3446e41f4b71Sopenharmony_ci
3447e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3448e41f4b71Sopenharmony_ci
3449e41f4b71Sopenharmony_ci| Name                 | Value   | Description     |
3450e41f4b71Sopenharmony_ci| ------------------- | ---- | ------- |
3451e41f4b71Sopenharmony_ci| ALIAS | 0    | No anti-aliasing processing is used.|
3452e41f4b71Sopenharmony_ci| ANTI_ALIAS  | 1    | Uses anti-aliasing to smooth the jagged edges.|
3453e41f4b71Sopenharmony_ci| SUBPIXEL_ANTI_ALIAS  | 2    | Uses sub-pixel anti-aliasing to provide a smoother effect for jagged edges.|
3454e41f4b71Sopenharmony_ci
3455e41f4b71Sopenharmony_ci## FontHinting<sup>12+</sup>
3456e41f4b71Sopenharmony_ci
3457e41f4b71Sopenharmony_ciEnumerates the font hinting types.
3458e41f4b71Sopenharmony_ci
3459e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3460e41f4b71Sopenharmony_ci
3461e41f4b71Sopenharmony_ci| Name                 | Value   | Description     |
3462e41f4b71Sopenharmony_ci| ------------------- | ---- | ------- |
3463e41f4b71Sopenharmony_ci| NONE    | 0    | No font hinting is used.|
3464e41f4b71Sopenharmony_ci| SLIGHT  | 1    | Slight font hinting is used to improve contrast.|
3465e41f4b71Sopenharmony_ci| NORMAL  | 2    | Normal font hinting is used to improve contrast.|
3466e41f4b71Sopenharmony_ci| FULL    | 3    | Full font hinting is used to improve contrast.|
3467e41f4b71Sopenharmony_ci
3468e41f4b71Sopenharmony_ci## TextBlob
3469e41f4b71Sopenharmony_ci
3470e41f4b71Sopenharmony_ciDefines a block consisting of one or more characters with the same font.
3471e41f4b71Sopenharmony_ci
3472e41f4b71Sopenharmony_ci### makeFromPosText<sup>12+</sup>
3473e41f4b71Sopenharmony_ci
3474e41f4b71Sopenharmony_cistatic makeFromPosText(text: string, len: number, points: common2D.Point[], font: Font): TextBlob
3475e41f4b71Sopenharmony_ci
3476e41f4b71Sopenharmony_ciCreates a **TextBlob** object from the text. The coordinates of each font in the **TextBlob** object are determined by the coordinate information in the **points** array.
3477e41f4b71Sopenharmony_ci
3478e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3479e41f4b71Sopenharmony_ci
3480e41f4b71Sopenharmony_ci**Parameters**
3481e41f4b71Sopenharmony_ci
3482e41f4b71Sopenharmony_ci| Name  | Type                         | Mandatory| Description                                  |
3483e41f4b71Sopenharmony_ci| -------- | ----------------------------- | ---- | -------------------------------------- |
3484e41f4b71Sopenharmony_ci| text     | string             | Yes  | Content to be used for drawing the text blob.                  |
3485e41f4b71Sopenharmony_ci| len      | number             | Yes  | Number of fonts. The value is an integer and is obtained from [countText](#counttext12).|
3486e41f4b71Sopenharmony_ci| points   |[common2D.Point](js-apis-graphics-common2D.md#point)[]     | Yes  |Array of points, which are used to specify the coordinates of each font. The array length must be the same as the value of **len**.|
3487e41f4b71Sopenharmony_ci| font     | [Font](#font)      | Yes  | **Font** object.|
3488e41f4b71Sopenharmony_ci
3489e41f4b71Sopenharmony_ci**Return value**
3490e41f4b71Sopenharmony_ci
3491e41f4b71Sopenharmony_ci| Type                 | Description          |
3492e41f4b71Sopenharmony_ci| --------------------- | -------------- |
3493e41f4b71Sopenharmony_ci| [TextBlob](#textblob) | **TextBlob** object.|
3494e41f4b71Sopenharmony_ci
3495e41f4b71Sopenharmony_ci
3496e41f4b71Sopenharmony_ci**Error codes**
3497e41f4b71Sopenharmony_ci
3498e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3499e41f4b71Sopenharmony_ci
3500e41f4b71Sopenharmony_ci| ID| Error Message|
3501e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
3502e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types. |
3503e41f4b71Sopenharmony_ci
3504e41f4b71Sopenharmony_ci**Example**
3505e41f4b71Sopenharmony_ci
3506e41f4b71Sopenharmony_ci```ts
3507e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
3508e41f4b71Sopenharmony_ciimport { drawing,common2D} from '@kit.ArkGraphics2D';
3509e41f4b71Sopenharmony_ci
3510e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
3511e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
3512e41f4b71Sopenharmony_ci    const canvas = context.canvas;
3513e41f4b71Sopenharmony_ci    let text : string = 'makeFromPosText';
3514e41f4b71Sopenharmony_ci    let font : drawing.Font = new drawing.Font();
3515e41f4b71Sopenharmony_ci    font.setSize(100);
3516e41f4b71Sopenharmony_ci    let length = font.countText(text);
3517e41f4b71Sopenharmony_ci    let points : common2D.Point[] = [];
3518e41f4b71Sopenharmony_ci    for (let i = 0; i !== length; ++i) {
3519e41f4b71Sopenharmony_ci      points.push({ x: i * 35, y: i * 35 });
3520e41f4b71Sopenharmony_ci    }
3521e41f4b71Sopenharmony_ci    let textblob : drawing.TextBlob =drawing.TextBlob.makeFromPosText(text, points.length, points, font);
3522e41f4b71Sopenharmony_ci    canvas.drawTextBlob(textblob, 100, 100);
3523e41f4b71Sopenharmony_ci  }
3524e41f4b71Sopenharmony_ci}
3525e41f4b71Sopenharmony_ci```
3526e41f4b71Sopenharmony_ci
3527e41f4b71Sopenharmony_ci### uniqueID<sup>12+</sup>
3528e41f4b71Sopenharmony_ci
3529e41f4b71Sopenharmony_ciuniqueID(): number
3530e41f4b71Sopenharmony_ci
3531e41f4b71Sopenharmony_ciObtains the unique identifier of a text blob. The identifier is a non-zero value.
3532e41f4b71Sopenharmony_ci
3533e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3534e41f4b71Sopenharmony_ci
3535e41f4b71Sopenharmony_ci**Return value**
3536e41f4b71Sopenharmony_ci
3537e41f4b71Sopenharmony_ci| Type                 | Description          |
3538e41f4b71Sopenharmony_ci| --------------------- | -------------- |
3539e41f4b71Sopenharmony_ci| number | Unique identifier of the text blob.|
3540e41f4b71Sopenharmony_ci
3541e41f4b71Sopenharmony_ci**Example**
3542e41f4b71Sopenharmony_ci
3543e41f4b71Sopenharmony_ci```ts
3544e41f4b71Sopenharmony_ciimport {drawing} from "@kit.ArkGraphics2D"
3545e41f4b71Sopenharmony_cilet text : string = 'TextBlobUniqueId';
3546e41f4b71Sopenharmony_cilet font : drawing.Font = new drawing.Font();
3547e41f4b71Sopenharmony_cifont.setSize(100);
3548e41f4b71Sopenharmony_cilet textBlob = drawing.TextBlob.makeFromString(text, font, 0);
3549e41f4b71Sopenharmony_cilet id = textBlob.uniqueID();
3550e41f4b71Sopenharmony_ciconsole.info("uniqueID---------------" +id);
3551e41f4b71Sopenharmony_ci```
3552e41f4b71Sopenharmony_ci
3553e41f4b71Sopenharmony_ci### makeFromString
3554e41f4b71Sopenharmony_ci
3555e41f4b71Sopenharmony_cistatic makeFromString(text: string, font: Font, encoding?: TextEncoding): TextBlob
3556e41f4b71Sopenharmony_ci
3557e41f4b71Sopenharmony_ciConverts a value of the string type into a **TextBlob** object.
3558e41f4b71Sopenharmony_ci
3559e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3560e41f4b71Sopenharmony_ci
3561e41f4b71Sopenharmony_ci**Parameters**
3562e41f4b71Sopenharmony_ci
3563e41f4b71Sopenharmony_ci| Name  | Type                         | Mandatory| Description                                  |
3564e41f4b71Sopenharmony_ci| -------- | ----------------------------- | ---- | -------------------------------------- |
3565e41f4b71Sopenharmony_ci| text     | string                        | Yes  | Content to be used for drawing the text blob.                  |
3566e41f4b71Sopenharmony_ci| font     | [Font](#font)                 | Yes  | **Font** object.          |
3567e41f4b71Sopenharmony_ci| encoding | [TextEncoding](#textencoding) | No  | Encoding type. The default value is **TEXT_ENCODING_UTF8**.|
3568e41f4b71Sopenharmony_ci
3569e41f4b71Sopenharmony_ci**Return value**
3570e41f4b71Sopenharmony_ci
3571e41f4b71Sopenharmony_ci| Type                 | Description          |
3572e41f4b71Sopenharmony_ci| --------------------- | -------------- |
3573e41f4b71Sopenharmony_ci| [TextBlob](#textblob) | **TextBlob** object.|
3574e41f4b71Sopenharmony_ci
3575e41f4b71Sopenharmony_ci**Error codes**
3576e41f4b71Sopenharmony_ci
3577e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3578e41f4b71Sopenharmony_ci
3579e41f4b71Sopenharmony_ci| ID| Error Message|
3580e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
3581e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
3582e41f4b71Sopenharmony_ci
3583e41f4b71Sopenharmony_ci**Example**
3584e41f4b71Sopenharmony_ci
3585e41f4b71Sopenharmony_ci```ts
3586e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
3587e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
3588e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
3589e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
3590e41f4b71Sopenharmony_ci    const canvas = context.canvas;
3591e41f4b71Sopenharmony_ci    const brush = new drawing.Brush();
3592e41f4b71Sopenharmony_ci    brush.setColor({alpha: 255, red: 255, green: 0, blue: 0});
3593e41f4b71Sopenharmony_ci    const font = new drawing.Font();
3594e41f4b71Sopenharmony_ci    font.setSize(20);
3595e41f4b71Sopenharmony_ci    const textBlob = drawing.TextBlob.makeFromString("drawing", font, drawing.TextEncoding.TEXT_ENCODING_UTF8);
3596e41f4b71Sopenharmony_ci    canvas.attachBrush(brush);
3597e41f4b71Sopenharmony_ci    canvas.drawTextBlob(textBlob, 20, 20);
3598e41f4b71Sopenharmony_ci    canvas.detachBrush();
3599e41f4b71Sopenharmony_ci  }
3600e41f4b71Sopenharmony_ci}
3601e41f4b71Sopenharmony_ci```
3602e41f4b71Sopenharmony_ci
3603e41f4b71Sopenharmony_ci### makeFromRunBuffer
3604e41f4b71Sopenharmony_ci
3605e41f4b71Sopenharmony_cistatic makeFromRunBuffer(pos: Array\<TextBlobRunBuffer>, font: Font, bounds?: common2D.Rect): TextBlob
3606e41f4b71Sopenharmony_ci
3607e41f4b71Sopenharmony_ciCreates a **Textblob** object based on the RunBuffer information.
3608e41f4b71Sopenharmony_ci
3609e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3610e41f4b71Sopenharmony_ci
3611e41f4b71Sopenharmony_ci**Parameters**
3612e41f4b71Sopenharmony_ci
3613e41f4b71Sopenharmony_ci| Name| Type                                              | Mandatory| Description                          |
3614e41f4b71Sopenharmony_ci| ------ | -------------------------------------------------- | ---- | ------------------------------ |
3615e41f4b71Sopenharmony_ci| pos    | Array\<[TextBlobRunBuffer](#textblobrunbuffer)>    | Yes  | **TextBlobRunBuffer** array.       |
3616e41f4b71Sopenharmony_ci| font   | [Font](#font)                                      | Yes  | **Font** object.  |
3617e41f4b71Sopenharmony_ci| bounds | [common2D.Rect](js-apis-graphics-common2D.md#rect) | No  | Bounding box. If this parameter is not set, there is no bounding box.|
3618e41f4b71Sopenharmony_ci
3619e41f4b71Sopenharmony_ci**Return value**
3620e41f4b71Sopenharmony_ci
3621e41f4b71Sopenharmony_ci| Type                 | Description          |
3622e41f4b71Sopenharmony_ci| --------------------- | -------------- |
3623e41f4b71Sopenharmony_ci| [TextBlob](#textblob) | **TextBlob** object.|
3624e41f4b71Sopenharmony_ci
3625e41f4b71Sopenharmony_ci**Error codes**
3626e41f4b71Sopenharmony_ci
3627e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3628e41f4b71Sopenharmony_ci
3629e41f4b71Sopenharmony_ci| ID| Error Message|
3630e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
3631e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
3632e41f4b71Sopenharmony_ci
3633e41f4b71Sopenharmony_ci**Example**
3634e41f4b71Sopenharmony_ci
3635e41f4b71Sopenharmony_ci```ts
3636e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
3637e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
3638e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
3639e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
3640e41f4b71Sopenharmony_ci    const canvas = context.canvas;
3641e41f4b71Sopenharmony_ci    const font = new drawing.Font();
3642e41f4b71Sopenharmony_ci    font.setSize(20);
3643e41f4b71Sopenharmony_ci    let runBuffer : Array<drawing.TextBlobRunBuffer> = [
3644e41f4b71Sopenharmony_ci      { glyph: 65, positionX: 0, positionY: 0 },
3645e41f4b71Sopenharmony_ci      { glyph: 227, positionX: 14.9, positionY: 0 },
3646e41f4b71Sopenharmony_ci      { glyph: 283, positionX: 25.84, positionY: 0 },
3647e41f4b71Sopenharmony_ci      { glyph: 283, positionX: 30.62, positionY: 0 },
3648e41f4b71Sopenharmony_ci      { glyph: 299, positionX: 35.4, positionY: 0}
3649e41f4b71Sopenharmony_ci    ];
3650e41f4b71Sopenharmony_ci    const textBlob = drawing.TextBlob.makeFromRunBuffer(runBuffer, font, null);
3651e41f4b71Sopenharmony_ci    const brush = new drawing.Brush();
3652e41f4b71Sopenharmony_ci    brush.setColor({alpha: 255, red: 255, green: 0, blue: 0});
3653e41f4b71Sopenharmony_ci    canvas.attachBrush(brush);
3654e41f4b71Sopenharmony_ci    canvas.drawTextBlob(textBlob, 20, 20);
3655e41f4b71Sopenharmony_ci    canvas.detachBrush();
3656e41f4b71Sopenharmony_ci  }
3657e41f4b71Sopenharmony_ci}
3658e41f4b71Sopenharmony_ci```
3659e41f4b71Sopenharmony_ci
3660e41f4b71Sopenharmony_ci### bounds
3661e41f4b71Sopenharmony_ci
3662e41f4b71Sopenharmony_cibounds(): common2D.Rect
3663e41f4b71Sopenharmony_ci
3664e41f4b71Sopenharmony_ciObtains the rectangular bounding box of the text blob.
3665e41f4b71Sopenharmony_ci
3666e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3667e41f4b71Sopenharmony_ci
3668e41f4b71Sopenharmony_ci**Return value**
3669e41f4b71Sopenharmony_ci
3670e41f4b71Sopenharmony_ci| Type                                              | Description                  |
3671e41f4b71Sopenharmony_ci| -------------------------------------------------- | ---------------------- |
3672e41f4b71Sopenharmony_ci| [common2D.Rect](js-apis-graphics-common2D.md#rect) | Rectangular bounding box.|
3673e41f4b71Sopenharmony_ci
3674e41f4b71Sopenharmony_ci**Example**
3675e41f4b71Sopenharmony_ci
3676e41f4b71Sopenharmony_ci```ts
3677e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
3678e41f4b71Sopenharmony_ciconst font = new drawing.Font();
3679e41f4b71Sopenharmony_cifont.setSize(20);
3680e41f4b71Sopenharmony_ciconst textBlob = drawing.TextBlob.makeFromString("drawing", font, drawing.TextEncoding.TEXT_ENCODING_UTF8);
3681e41f4b71Sopenharmony_cilet bounds = textBlob.bounds();
3682e41f4b71Sopenharmony_ci```
3683e41f4b71Sopenharmony_ci
3684e41f4b71Sopenharmony_ci## Typeface
3685e41f4b71Sopenharmony_ci
3686e41f4b71Sopenharmony_ciDescribes the typeface such as SimSun and Kaiti.
3687e41f4b71Sopenharmony_ci
3688e41f4b71Sopenharmony_ci### getFamilyName
3689e41f4b71Sopenharmony_ci
3690e41f4b71Sopenharmony_cigetFamilyName(): string
3691e41f4b71Sopenharmony_ci
3692e41f4b71Sopenharmony_ciObtains the name of the typeface, that is, the name of the font family.
3693e41f4b71Sopenharmony_ci
3694e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3695e41f4b71Sopenharmony_ci
3696e41f4b71Sopenharmony_ci**Return value**
3697e41f4b71Sopenharmony_ci
3698e41f4b71Sopenharmony_ci| Type  | Description                |
3699e41f4b71Sopenharmony_ci| ------ | -------------------- |
3700e41f4b71Sopenharmony_ci| string | Typeface name.|
3701e41f4b71Sopenharmony_ci
3702e41f4b71Sopenharmony_ci**Example**
3703e41f4b71Sopenharmony_ci
3704e41f4b71Sopenharmony_ci```ts
3705e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
3706e41f4b71Sopenharmony_ciconst font = new drawing.Font();
3707e41f4b71Sopenharmony_cilet typeface = font.getTypeface();
3708e41f4b71Sopenharmony_cilet familyName = typeface.getFamilyName();
3709e41f4b71Sopenharmony_ci```
3710e41f4b71Sopenharmony_ci
3711e41f4b71Sopenharmony_ci### makeFromFile<sup>12+</sup>
3712e41f4b71Sopenharmony_ci
3713e41f4b71Sopenharmony_cistatic makeFromFile(filePath: string): Typeface
3714e41f4b71Sopenharmony_ci
3715e41f4b71Sopenharmony_ciConstructs a typeface from a file.
3716e41f4b71Sopenharmony_ci
3717e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3718e41f4b71Sopenharmony_ci
3719e41f4b71Sopenharmony_ci**Parameters**
3720e41f4b71Sopenharmony_ci
3721e41f4b71Sopenharmony_ci| Name        | Type                                      | Mandatory  | Description                 |
3722e41f4b71Sopenharmony_ci| ----------- | ---------------------------------------- | ---- | ------------------- |
3723e41f4b71Sopenharmony_ci| filePath | string           | Yes  | Path of the file.|
3724e41f4b71Sopenharmony_ci
3725e41f4b71Sopenharmony_ci**Return value**
3726e41f4b71Sopenharmony_ci
3727e41f4b71Sopenharmony_ci| Type  | Description                |
3728e41f4b71Sopenharmony_ci| ------ | -------------------- |
3729e41f4b71Sopenharmony_ci| [Typeface](#typeface) | **Typeface** object.|
3730e41f4b71Sopenharmony_ci
3731e41f4b71Sopenharmony_ci**Error codes**
3732e41f4b71Sopenharmony_ci
3733e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3734e41f4b71Sopenharmony_ci
3735e41f4b71Sopenharmony_ci| ID| Error Message|
3736e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
3737e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
3738e41f4b71Sopenharmony_ci
3739e41f4b71Sopenharmony_ci**Example**
3740e41f4b71Sopenharmony_ci
3741e41f4b71Sopenharmony_ci```ts
3742e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
3743e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
3744e41f4b71Sopenharmony_ciclass TextRenderNode extends RenderNode {
3745e41f4b71Sopenharmony_ci  async draw(context: DrawContext) {
3746e41f4b71Sopenharmony_ci    const canvas = context.canvas;
3747e41f4b71Sopenharmony_ci    let font = new drawing.Font();
3748e41f4b71Sopenharmony_ci    let str = "/system/fonts/HarmonyOS_Sans_Italic.ttf";
3749e41f4b71Sopenharmony_ci    const mytypeface = drawing.Typeface.makeFromFile(str);
3750e41f4b71Sopenharmony_ci    font.setTypeface(mytypeface);
3751e41f4b71Sopenharmony_ci    const textBlob = drawing.TextBlob.makeFromString("Hello World", font, drawing.TextEncoding.TEXT_ENCODING_UTF8);
3752e41f4b71Sopenharmony_ci    canvas.drawTextBlob(textBlob, 60, 100);
3753e41f4b71Sopenharmony_ci  }
3754e41f4b71Sopenharmony_ci}
3755e41f4b71Sopenharmony_ci```
3756e41f4b71Sopenharmony_ci
3757e41f4b71Sopenharmony_ci## Font
3758e41f4b71Sopenharmony_ci
3759e41f4b71Sopenharmony_ciDescribes the attributes, such as the size, used for drawing text.
3760e41f4b71Sopenharmony_ci
3761e41f4b71Sopenharmony_ci### isSubpixel<sup>12+</sup>
3762e41f4b71Sopenharmony_ci
3763e41f4b71Sopenharmony_ciisSubpixel(): boolean
3764e41f4b71Sopenharmony_ci
3765e41f4b71Sopenharmony_ciChecks whether sub-pixel rendering is used for this font.
3766e41f4b71Sopenharmony_ci
3767e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3768e41f4b71Sopenharmony_ci
3769e41f4b71Sopenharmony_ci**Return value**
3770e41f4b71Sopenharmony_ci
3771e41f4b71Sopenharmony_ci| Type  | Description                |
3772e41f4b71Sopenharmony_ci| ------ | -------------------- |
3773e41f4b71Sopenharmony_ci| boolean | Check result. The value **true** means that sub-pixel rendering is used, and **false** means the opposite.|
3774e41f4b71Sopenharmony_ci
3775e41f4b71Sopenharmony_ci**Example**
3776e41f4b71Sopenharmony_ci
3777e41f4b71Sopenharmony_ci```ts
3778e41f4b71Sopenharmony_ciimport {drawing} from '@kit.ArkGraphics2D';
3779e41f4b71Sopenharmony_cilet font: drawing.Font = new drawing.Font();
3780e41f4b71Sopenharmony_cifont.enableSubpixel(true)
3781e41f4b71Sopenharmony_ciconsole.info("values=" + font.isSubpixel());
3782e41f4b71Sopenharmony_ci```
3783e41f4b71Sopenharmony_ci
3784e41f4b71Sopenharmony_ci### isLinearMetrics<sup>12+</sup>
3785e41f4b71Sopenharmony_ci
3786e41f4b71Sopenharmony_ciisLinearMetrics(): boolean
3787e41f4b71Sopenharmony_ci
3788e41f4b71Sopenharmony_ciChecks whether linear scaling is used for this font.
3789e41f4b71Sopenharmony_ci
3790e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3791e41f4b71Sopenharmony_ci
3792e41f4b71Sopenharmony_ci**Return value**
3793e41f4b71Sopenharmony_ci
3794e41f4b71Sopenharmony_ci| Type  | Description                |
3795e41f4b71Sopenharmony_ci| ------ | -------------------- |
3796e41f4b71Sopenharmony_ci| boolean | Check result. The value **true** means that linear scaling is used, and **false** means the opposite.|
3797e41f4b71Sopenharmony_ci
3798e41f4b71Sopenharmony_ci**Example**
3799e41f4b71Sopenharmony_ci
3800e41f4b71Sopenharmony_ci```ts
3801e41f4b71Sopenharmony_ciimport {drawing} from '@kit.ArkGraphics2D';
3802e41f4b71Sopenharmony_cilet font: drawing.Font = new drawing.Font();
3803e41f4b71Sopenharmony_cifont.enableLinearMetrics(true)
3804e41f4b71Sopenharmony_ciconsole.info("values=" + font.isLinearMetrics());
3805e41f4b71Sopenharmony_ci```
3806e41f4b71Sopenharmony_ci
3807e41f4b71Sopenharmony_ci### getSkewX<sup>12+</sup>
3808e41f4b71Sopenharmony_ci
3809e41f4b71Sopenharmony_cigetSkewX(): number
3810e41f4b71Sopenharmony_ci
3811e41f4b71Sopenharmony_ciObtains the horizontal skew factor of this font.
3812e41f4b71Sopenharmony_ci
3813e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3814e41f4b71Sopenharmony_ci
3815e41f4b71Sopenharmony_ci**Return value**
3816e41f4b71Sopenharmony_ci
3817e41f4b71Sopenharmony_ci| Type  | Description                |
3818e41f4b71Sopenharmony_ci| ------ | -------------------- |
3819e41f4b71Sopenharmony_ci| number | Horizontal skew factor.|
3820e41f4b71Sopenharmony_ci
3821e41f4b71Sopenharmony_ci**Example**
3822e41f4b71Sopenharmony_ci
3823e41f4b71Sopenharmony_ci```ts
3824e41f4b71Sopenharmony_ciimport {drawing} from '@kit.ArkGraphics2D';
3825e41f4b71Sopenharmony_cilet font: drawing.Font = new drawing.Font();
3826e41f4b71Sopenharmony_cifont.setSkewX(-1)
3827e41f4b71Sopenharmony_ciconsole.info("values=" + font.getSkewX());
3828e41f4b71Sopenharmony_ci```
3829e41f4b71Sopenharmony_ci
3830e41f4b71Sopenharmony_ci### isEmbolden<sup>12+</sup>
3831e41f4b71Sopenharmony_ci
3832e41f4b71Sopenharmony_ciisEmbolden(): boolean
3833e41f4b71Sopenharmony_ci
3834e41f4b71Sopenharmony_ciChecks whether the bold effect is set for this font.
3835e41f4b71Sopenharmony_ci
3836e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3837e41f4b71Sopenharmony_ci
3838e41f4b71Sopenharmony_ci**Return value**
3839e41f4b71Sopenharmony_ci
3840e41f4b71Sopenharmony_ci| Type  | Description                |
3841e41f4b71Sopenharmony_ci| ------ | -------------------- |
3842e41f4b71Sopenharmony_ci| boolean  | Check result. The value **true** means that the bold effect is set, and **false** means the opposite.|
3843e41f4b71Sopenharmony_ci
3844e41f4b71Sopenharmony_ci**Example**
3845e41f4b71Sopenharmony_ci
3846e41f4b71Sopenharmony_ci```ts
3847e41f4b71Sopenharmony_ciimport {drawing} from '@kit.ArkGraphics2D';
3848e41f4b71Sopenharmony_cilet font: drawing.Font = new drawing.Font();
3849e41f4b71Sopenharmony_cifont.enableEmbolden(true);
3850e41f4b71Sopenharmony_ciconsole.info("values=" + font.isEmbolden());
3851e41f4b71Sopenharmony_ci```
3852e41f4b71Sopenharmony_ci
3853e41f4b71Sopenharmony_ci### getScaleX<sup>12+</sup>
3854e41f4b71Sopenharmony_ci
3855e41f4b71Sopenharmony_cigetScaleX(): number
3856e41f4b71Sopenharmony_ci
3857e41f4b71Sopenharmony_ciObtains the horizontal scale ratio of this font.
3858e41f4b71Sopenharmony_ci
3859e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3860e41f4b71Sopenharmony_ci
3861e41f4b71Sopenharmony_ci**Return value**
3862e41f4b71Sopenharmony_ci
3863e41f4b71Sopenharmony_ci| Type  | Description                |
3864e41f4b71Sopenharmony_ci| ------ | -------------------- |
3865e41f4b71Sopenharmony_ci| number  | Horizontal scale ratio.|
3866e41f4b71Sopenharmony_ci
3867e41f4b71Sopenharmony_ci**Example**
3868e41f4b71Sopenharmony_ci
3869e41f4b71Sopenharmony_ci```ts
3870e41f4b71Sopenharmony_ciimport {drawing} from '@kit.ArkGraphics2D';
3871e41f4b71Sopenharmony_cilet font: drawing.Font = new drawing.Font();
3872e41f4b71Sopenharmony_cifont.setScaleX(2);
3873e41f4b71Sopenharmony_ciconsole.info("values=" + font.getScaleX());
3874e41f4b71Sopenharmony_ci```
3875e41f4b71Sopenharmony_ci
3876e41f4b71Sopenharmony_ci### getHinting<sup>12+</sup>
3877e41f4b71Sopenharmony_ci
3878e41f4b71Sopenharmony_cigetHinting(): FontHinting
3879e41f4b71Sopenharmony_ci
3880e41f4b71Sopenharmony_ciObtains the font hinting effect.
3881e41f4b71Sopenharmony_ci
3882e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3883e41f4b71Sopenharmony_ci
3884e41f4b71Sopenharmony_ci**Return value**
3885e41f4b71Sopenharmony_ci
3886e41f4b71Sopenharmony_ci| Type  | Description                |
3887e41f4b71Sopenharmony_ci| ------ | -------------------- |
3888e41f4b71Sopenharmony_ci| [FontHinting](#fonthinting12)  | Font hinting effect.|
3889e41f4b71Sopenharmony_ci
3890e41f4b71Sopenharmony_ci**Example**
3891e41f4b71Sopenharmony_ci
3892e41f4b71Sopenharmony_ci```ts
3893e41f4b71Sopenharmony_ciimport {drawing} from '@kit.ArkGraphics2D';
3894e41f4b71Sopenharmony_cilet font: drawing.Font = new drawing.Font();
3895e41f4b71Sopenharmony_ciconsole.info("values=" + font.getHinting());
3896e41f4b71Sopenharmony_ci```
3897e41f4b71Sopenharmony_ci
3898e41f4b71Sopenharmony_ci### getEdging<sup>12+</sup>
3899e41f4b71Sopenharmony_ci
3900e41f4b71Sopenharmony_cigetEdging(): FontEdging
3901e41f4b71Sopenharmony_ci
3902e41f4b71Sopenharmony_ciObtains the font edging effect.
3903e41f4b71Sopenharmony_ci
3904e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3905e41f4b71Sopenharmony_ci
3906e41f4b71Sopenharmony_ci**Return value**
3907e41f4b71Sopenharmony_ci
3908e41f4b71Sopenharmony_ci| Type  | Description                |
3909e41f4b71Sopenharmony_ci| ------ | -------------------- |
3910e41f4b71Sopenharmony_ci| [FontEdging](#fontedging12)  | Font edging effect.|
3911e41f4b71Sopenharmony_ci
3912e41f4b71Sopenharmony_ci**Example**
3913e41f4b71Sopenharmony_ci
3914e41f4b71Sopenharmony_ci```ts
3915e41f4b71Sopenharmony_ciimport {drawing} from '@kit.ArkGraphics2D';
3916e41f4b71Sopenharmony_cilet font: drawing.Font = new drawing.Font();
3917e41f4b71Sopenharmony_ciconsole.info("values=" + font.getEdging());
3918e41f4b71Sopenharmony_ci```
3919e41f4b71Sopenharmony_ci
3920e41f4b71Sopenharmony_ci### enableSubpixel
3921e41f4b71Sopenharmony_ci
3922e41f4b71Sopenharmony_cienableSubpixel(isSubpixel: boolean): void
3923e41f4b71Sopenharmony_ci
3924e41f4b71Sopenharmony_ciEnables subpixel font rendering.
3925e41f4b71Sopenharmony_ci
3926e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3927e41f4b71Sopenharmony_ci
3928e41f4b71Sopenharmony_ci**Parameters**
3929e41f4b71Sopenharmony_ci
3930e41f4b71Sopenharmony_ci| Name    | Type   | Mandatory| Description                                                        |
3931e41f4b71Sopenharmony_ci| ---------- | ------- | ---- | ------------------------------------------------------------ |
3932e41f4b71Sopenharmony_ci| isSubpixel | boolean | Yes  | Whether to enable subpixel font rendering. The value **true** means to enable subpixel font rendering, and **false** means the opposite.|
3933e41f4b71Sopenharmony_ci
3934e41f4b71Sopenharmony_ci**Error codes**
3935e41f4b71Sopenharmony_ci
3936e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3937e41f4b71Sopenharmony_ci
3938e41f4b71Sopenharmony_ci| ID| Error Message|
3939e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
3940e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
3941e41f4b71Sopenharmony_ci
3942e41f4b71Sopenharmony_ci**Example**
3943e41f4b71Sopenharmony_ci
3944e41f4b71Sopenharmony_ci```ts
3945e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
3946e41f4b71Sopenharmony_cilet font = new drawing.Font();
3947e41f4b71Sopenharmony_cifont.enableSubpixel(true);
3948e41f4b71Sopenharmony_ci```
3949e41f4b71Sopenharmony_ci
3950e41f4b71Sopenharmony_ci### enableEmbolden
3951e41f4b71Sopenharmony_ci
3952e41f4b71Sopenharmony_cienableEmbolden(isEmbolden: boolean): void
3953e41f4b71Sopenharmony_ci
3954e41f4b71Sopenharmony_ciEnables emboldened fonts.
3955e41f4b71Sopenharmony_ci
3956e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3957e41f4b71Sopenharmony_ci
3958e41f4b71Sopenharmony_ci**Parameters**
3959e41f4b71Sopenharmony_ci
3960e41f4b71Sopenharmony_ci| Name    | Type   | Mandatory| Description                                                 |
3961e41f4b71Sopenharmony_ci| ---------- | ------- | ---- | ----------------------------------------------------- |
3962e41f4b71Sopenharmony_ci| isEmbolden | boolean | Yes  | Whether to enable emboldened fonts. The value **true** means to enable emboldened fonts, and **false** means the opposite.|
3963e41f4b71Sopenharmony_ci
3964e41f4b71Sopenharmony_ci**Error codes**
3965e41f4b71Sopenharmony_ci
3966e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3967e41f4b71Sopenharmony_ci
3968e41f4b71Sopenharmony_ci| ID| Error Message|
3969e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
3970e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
3971e41f4b71Sopenharmony_ci
3972e41f4b71Sopenharmony_ci**Example**
3973e41f4b71Sopenharmony_ci
3974e41f4b71Sopenharmony_ci```ts
3975e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
3976e41f4b71Sopenharmony_cilet font = new drawing.Font();
3977e41f4b71Sopenharmony_cifont.enableEmbolden(true);
3978e41f4b71Sopenharmony_ci```
3979e41f4b71Sopenharmony_ci
3980e41f4b71Sopenharmony_ci### enableLinearMetrics
3981e41f4b71Sopenharmony_ci
3982e41f4b71Sopenharmony_cienableLinearMetrics(isLinearMetrics: boolean): void
3983e41f4b71Sopenharmony_ci
3984e41f4b71Sopenharmony_ciEnables linear font scaling.
3985e41f4b71Sopenharmony_ci
3986e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
3987e41f4b71Sopenharmony_ci
3988e41f4b71Sopenharmony_ci**Parameters**
3989e41f4b71Sopenharmony_ci
3990e41f4b71Sopenharmony_ci| Name         | Type   | Mandatory| Description                                                       |
3991e41f4b71Sopenharmony_ci| --------------- | ------- | ---- | ----------------------------------------------------------- |
3992e41f4b71Sopenharmony_ci| isLinearMetrics | boolean | Yes  | Whether to enable linear font scaling. The value **true** means to enable linear font scaling, and **false** means the opposite.|
3993e41f4b71Sopenharmony_ci
3994e41f4b71Sopenharmony_ci**Error codes**
3995e41f4b71Sopenharmony_ci
3996e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3997e41f4b71Sopenharmony_ci
3998e41f4b71Sopenharmony_ci| ID| Error Message|
3999e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
4000e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4001e41f4b71Sopenharmony_ci
4002e41f4b71Sopenharmony_ci**Example**
4003e41f4b71Sopenharmony_ci
4004e41f4b71Sopenharmony_ci```ts
4005e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
4006e41f4b71Sopenharmony_cilet font = new drawing.Font();
4007e41f4b71Sopenharmony_cifont.enableLinearMetrics(true);
4008e41f4b71Sopenharmony_ci```
4009e41f4b71Sopenharmony_ci
4010e41f4b71Sopenharmony_ci### setSize
4011e41f4b71Sopenharmony_ci
4012e41f4b71Sopenharmony_cisetSize(textSize: number): void
4013e41f4b71Sopenharmony_ci
4014e41f4b71Sopenharmony_ciSets the text size.
4015e41f4b71Sopenharmony_ci
4016e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4017e41f4b71Sopenharmony_ci
4018e41f4b71Sopenharmony_ci**Parameters**
4019e41f4b71Sopenharmony_ci
4020e41f4b71Sopenharmony_ci| Name  | Type  | Mandatory| Description            |
4021e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---------------- |
4022e41f4b71Sopenharmony_ci| textSize | number | Yes  | Text size. The value is a floating point number. If a negative number is passed in, the size is set to 0. If the size is 0, the text drawn will not be displayed.|
4023e41f4b71Sopenharmony_ci
4024e41f4b71Sopenharmony_ci**Error codes**
4025e41f4b71Sopenharmony_ci
4026e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4027e41f4b71Sopenharmony_ci
4028e41f4b71Sopenharmony_ci| ID| Error Message|
4029e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
4030e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
4031e41f4b71Sopenharmony_ci
4032e41f4b71Sopenharmony_ci**Example**
4033e41f4b71Sopenharmony_ci
4034e41f4b71Sopenharmony_ci```ts
4035e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
4036e41f4b71Sopenharmony_cilet font = new drawing.Font();
4037e41f4b71Sopenharmony_cifont.setSize(5);
4038e41f4b71Sopenharmony_ci```
4039e41f4b71Sopenharmony_ci
4040e41f4b71Sopenharmony_ci### getSize
4041e41f4b71Sopenharmony_ci
4042e41f4b71Sopenharmony_cigetSize(): number
4043e41f4b71Sopenharmony_ci
4044e41f4b71Sopenharmony_ciObtains the text size.
4045e41f4b71Sopenharmony_ci
4046e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4047e41f4b71Sopenharmony_ci
4048e41f4b71Sopenharmony_ci**Return value**
4049e41f4b71Sopenharmony_ci
4050e41f4b71Sopenharmony_ci| Type  | Description            |
4051e41f4b71Sopenharmony_ci| ------ | ---------------- |
4052e41f4b71Sopenharmony_ci| number | Text size. The value is a floating point number.|
4053e41f4b71Sopenharmony_ci
4054e41f4b71Sopenharmony_ci**Example**
4055e41f4b71Sopenharmony_ci
4056e41f4b71Sopenharmony_ci```ts
4057e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
4058e41f4b71Sopenharmony_cilet font = new drawing.Font();
4059e41f4b71Sopenharmony_cifont.setSize(5);
4060e41f4b71Sopenharmony_cilet fontSize = font.getSize();
4061e41f4b71Sopenharmony_ci```
4062e41f4b71Sopenharmony_ci
4063e41f4b71Sopenharmony_ci### setTypeface
4064e41f4b71Sopenharmony_ci
4065e41f4b71Sopenharmony_cisetTypeface(typeface: Typeface): void
4066e41f4b71Sopenharmony_ci
4067e41f4b71Sopenharmony_ciSets the typeface.
4068e41f4b71Sopenharmony_ci
4069e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4070e41f4b71Sopenharmony_ci
4071e41f4b71Sopenharmony_ci**Parameters**
4072e41f4b71Sopenharmony_ci
4073e41f4b71Sopenharmony_ci| Name  | Type                 | Mandatory| Description  |
4074e41f4b71Sopenharmony_ci| -------- | --------------------- | ---- | ------ |
4075e41f4b71Sopenharmony_ci| typeface | [Typeface](#typeface) | Yes  | **Typeface** object.|
4076e41f4b71Sopenharmony_ci
4077e41f4b71Sopenharmony_ci**Error codes**
4078e41f4b71Sopenharmony_ci
4079e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4080e41f4b71Sopenharmony_ci
4081e41f4b71Sopenharmony_ci| ID| Error Message|
4082e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
4083e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4084e41f4b71Sopenharmony_ci
4085e41f4b71Sopenharmony_ci**Example**
4086e41f4b71Sopenharmony_ci
4087e41f4b71Sopenharmony_ci```ts
4088e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
4089e41f4b71Sopenharmony_cilet font = new drawing.Font();
4090e41f4b71Sopenharmony_cifont.setTypeface(new drawing.Typeface());
4091e41f4b71Sopenharmony_ci```
4092e41f4b71Sopenharmony_ci
4093e41f4b71Sopenharmony_ci### getTypeface
4094e41f4b71Sopenharmony_ci
4095e41f4b71Sopenharmony_cigetTypeface(): Typeface
4096e41f4b71Sopenharmony_ci
4097e41f4b71Sopenharmony_ciObtains the typeface.
4098e41f4b71Sopenharmony_ci
4099e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4100e41f4b71Sopenharmony_ci
4101e41f4b71Sopenharmony_ci**Return value**
4102e41f4b71Sopenharmony_ci
4103e41f4b71Sopenharmony_ci| Type                 | Description  |
4104e41f4b71Sopenharmony_ci| --------------------- | ------ |
4105e41f4b71Sopenharmony_ci| [Typeface](#typeface) | **Typeface** object.|
4106e41f4b71Sopenharmony_ci
4107e41f4b71Sopenharmony_ci**Example**
4108e41f4b71Sopenharmony_ci
4109e41f4b71Sopenharmony_ci```ts
4110e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
4111e41f4b71Sopenharmony_cilet font = new drawing.Font();
4112e41f4b71Sopenharmony_cilet typeface = font.getTypeface();
4113e41f4b71Sopenharmony_ci```
4114e41f4b71Sopenharmony_ci
4115e41f4b71Sopenharmony_ci### getMetrics
4116e41f4b71Sopenharmony_ci
4117e41f4b71Sopenharmony_cigetMetrics(): FontMetrics
4118e41f4b71Sopenharmony_ci
4119e41f4b71Sopenharmony_ciObtains the font metrics of the typeface.
4120e41f4b71Sopenharmony_ci
4121e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4122e41f4b71Sopenharmony_ci
4123e41f4b71Sopenharmony_ci**Return value**
4124e41f4b71Sopenharmony_ci
4125e41f4b71Sopenharmony_ci| Type                       | Description             |
4126e41f4b71Sopenharmony_ci| --------------------------- | ----------------- |
4127e41f4b71Sopenharmony_ci| [FontMetrics](#fontmetrics) | Font metrics.|
4128e41f4b71Sopenharmony_ci
4129e41f4b71Sopenharmony_ci**Example**
4130e41f4b71Sopenharmony_ci
4131e41f4b71Sopenharmony_ci```ts
4132e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
4133e41f4b71Sopenharmony_cilet font = new drawing.Font();
4134e41f4b71Sopenharmony_cilet metrics = font.getMetrics();
4135e41f4b71Sopenharmony_ci```
4136e41f4b71Sopenharmony_ci
4137e41f4b71Sopenharmony_ci### measureText
4138e41f4b71Sopenharmony_ci
4139e41f4b71Sopenharmony_cimeasureText(text: string, encoding: TextEncoding): number
4140e41f4b71Sopenharmony_ci
4141e41f4b71Sopenharmony_ciMeasures the text width.
4142e41f4b71Sopenharmony_ci
4143e41f4b71Sopenharmony_ci> **NOTE**
4144e41f4b71Sopenharmony_ci>
4145e41f4b71Sopenharmony_ci> This API is used to measure the text width of the original string. To measure the text width after typesetting, call [measure.measureText](../apis-arkui/js-apis-measure.md#measuretextmeasuretext).
4146e41f4b71Sopenharmony_ci
4147e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4148e41f4b71Sopenharmony_ci
4149e41f4b71Sopenharmony_ci**Parameters**
4150e41f4b71Sopenharmony_ci
4151e41f4b71Sopenharmony_ci| Name  | Type                         | Mandatory| Description      |
4152e41f4b71Sopenharmony_ci| -------- | ----------------------------- | ---- | ---------- |
4153e41f4b71Sopenharmony_ci| text     | string                        | Yes  | Text content.|
4154e41f4b71Sopenharmony_ci| encoding | [TextEncoding](#textencoding) | Yes  | Encoding format.|
4155e41f4b71Sopenharmony_ci
4156e41f4b71Sopenharmony_ci**Return value**
4157e41f4b71Sopenharmony_ci
4158e41f4b71Sopenharmony_ci| Type  | Description            |
4159e41f4b71Sopenharmony_ci| ------ | ---------------- |
4160e41f4b71Sopenharmony_ci| number | Width of the text. The value is a floating point number.|
4161e41f4b71Sopenharmony_ci
4162e41f4b71Sopenharmony_ci**Error codes**
4163e41f4b71Sopenharmony_ci
4164e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4165e41f4b71Sopenharmony_ci
4166e41f4b71Sopenharmony_ci| ID| Error Message|
4167e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
4168e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4169e41f4b71Sopenharmony_ci
4170e41f4b71Sopenharmony_ci**Example**
4171e41f4b71Sopenharmony_ci
4172e41f4b71Sopenharmony_ci```ts
4173e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
4174e41f4b71Sopenharmony_cilet font = new drawing.Font();
4175e41f4b71Sopenharmony_cifont.measureText("drawing", drawing.TextEncoding.TEXT_ENCODING_UTF8);
4176e41f4b71Sopenharmony_ci```
4177e41f4b71Sopenharmony_ci
4178e41f4b71Sopenharmony_ci### measureSingleCharacter<sup>12+</sup>
4179e41f4b71Sopenharmony_ci
4180e41f4b71Sopenharmony_cimeasureSingleCharacter(text: string): number
4181e41f4b71Sopenharmony_ci
4182e41f4b71Sopenharmony_ciMeasures the width of a single character. If the typeface of the current font does not support the character to measure, the system typeface is used to measure the character width.
4183e41f4b71Sopenharmony_ci
4184e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4185e41f4b71Sopenharmony_ci
4186e41f4b71Sopenharmony_ci**Parameters**
4187e41f4b71Sopenharmony_ci
4188e41f4b71Sopenharmony_ci| Name| Type               | Mandatory| Description       |
4189e41f4b71Sopenharmony_ci| ------ | ------------------- | ---- | ----------- |
4190e41f4b71Sopenharmony_ci| text   | string | Yes  | Single character to measure. The length of the string must be 1. |
4191e41f4b71Sopenharmony_ci
4192e41f4b71Sopenharmony_ci**Return value**
4193e41f4b71Sopenharmony_ci
4194e41f4b71Sopenharmony_ci| Type  | Description            |
4195e41f4b71Sopenharmony_ci| ------ | ---------------- |
4196e41f4b71Sopenharmony_ci| number | Width of the character. The value is a floating point number.|
4197e41f4b71Sopenharmony_ci
4198e41f4b71Sopenharmony_ci**Error codes**
4199e41f4b71Sopenharmony_ci
4200e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4201e41f4b71Sopenharmony_ci
4202e41f4b71Sopenharmony_ci| ID| Error Message|
4203e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
4204e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
4205e41f4b71Sopenharmony_ci
4206e41f4b71Sopenharmony_ci**Example**
4207e41f4b71Sopenharmony_ci
4208e41f4b71Sopenharmony_ci```ts
4209e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
4210e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
4211e41f4b71Sopenharmony_ci
4212e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
4213e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
4214e41f4b71Sopenharmony_ci    const canvas = context.canvas;
4215e41f4b71Sopenharmony_ci    const font = new drawing.Font();
4216e41f4b71Sopenharmony_ci    font.setSize(20);
4217e41f4b71Sopenharmony_ci    let width = font.measureSingleCharacter ("Hello");
4218e41f4b71Sopenharmony_ci  }
4219e41f4b71Sopenharmony_ci}
4220e41f4b71Sopenharmony_ci```
4221e41f4b71Sopenharmony_ci
4222e41f4b71Sopenharmony_ci### setScaleX<sup>12+</sup>
4223e41f4b71Sopenharmony_ci
4224e41f4b71Sopenharmony_cisetScaleX(scaleX: number): void
4225e41f4b71Sopenharmony_ci
4226e41f4b71Sopenharmony_ciSets a horizontal scale factor for this font.
4227e41f4b71Sopenharmony_ci
4228e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4229e41f4b71Sopenharmony_ci
4230e41f4b71Sopenharmony_ci**Parameters**
4231e41f4b71Sopenharmony_ci
4232e41f4b71Sopenharmony_ci| Name  | Type                         | Mandatory| Description      |
4233e41f4b71Sopenharmony_ci| -------- | ----------------------------- | ---- | ---------- |
4234e41f4b71Sopenharmony_ci| scaleX     | number                      | Yes  | Horizontal scale factor. The value is a floating point number.|
4235e41f4b71Sopenharmony_ci
4236e41f4b71Sopenharmony_ci**Error codes**
4237e41f4b71Sopenharmony_ci
4238e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4239e41f4b71Sopenharmony_ci
4240e41f4b71Sopenharmony_ci| ID| Error Message|
4241e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
4242e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4243e41f4b71Sopenharmony_ci
4244e41f4b71Sopenharmony_ci**Example**
4245e41f4b71Sopenharmony_ci
4246e41f4b71Sopenharmony_ci```ts
4247e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
4248e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
4249e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
4250e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
4251e41f4b71Sopenharmony_ci    const canvas = context.canvas;
4252e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
4253e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
4254e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
4255e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
4256e41f4b71Sopenharmony_ci    let font = new drawing.Font();
4257e41f4b71Sopenharmony_ci    font.setSize(100);
4258e41f4b71Sopenharmony_ci    font.setScaleX(2);
4259e41f4b71Sopenharmony_ci    const textBlob = drawing.TextBlob.makeFromString("hello", font, drawing.TextEncoding.TEXT_ENCODING_UTF8);
4260e41f4b71Sopenharmony_ci    canvas.drawTextBlob(textBlob, 200, 200);
4261e41f4b71Sopenharmony_ci  }
4262e41f4b71Sopenharmony_ci}
4263e41f4b71Sopenharmony_ci```
4264e41f4b71Sopenharmony_ci
4265e41f4b71Sopenharmony_ci### setSkewX<sup>12+</sup>
4266e41f4b71Sopenharmony_ci
4267e41f4b71Sopenharmony_cisetSkewX(skewX: number): void
4268e41f4b71Sopenharmony_ci
4269e41f4b71Sopenharmony_ciSets a horizontal skew factor for this font.
4270e41f4b71Sopenharmony_ci
4271e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4272e41f4b71Sopenharmony_ci
4273e41f4b71Sopenharmony_ci**Parameters**
4274e41f4b71Sopenharmony_ci
4275e41f4b71Sopenharmony_ci| Name  | Type                         | Mandatory| Description      |
4276e41f4b71Sopenharmony_ci| -------- | ----------------------------- | ---- | ---------- |
4277e41f4b71Sopenharmony_ci| skewX     | number                      | Yes  | Horizontal skew factor. A positive number means a skew to the left, and a negative number means a skew to the right. The value is a floating point number.|
4278e41f4b71Sopenharmony_ci
4279e41f4b71Sopenharmony_ci**Error codes**
4280e41f4b71Sopenharmony_ci
4281e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4282e41f4b71Sopenharmony_ci
4283e41f4b71Sopenharmony_ci| ID| Error Message|
4284e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
4285e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4286e41f4b71Sopenharmony_ci
4287e41f4b71Sopenharmony_ci**Example**
4288e41f4b71Sopenharmony_ci
4289e41f4b71Sopenharmony_ci```ts
4290e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
4291e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
4292e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
4293e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
4294e41f4b71Sopenharmony_ci    const canvas = context.canvas;
4295e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
4296e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
4297e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
4298e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
4299e41f4b71Sopenharmony_ci    let font = new drawing.Font();
4300e41f4b71Sopenharmony_ci    font.setSize(100);
4301e41f4b71Sopenharmony_ci    font.setSkewX(1);
4302e41f4b71Sopenharmony_ci    const textBlob = drawing.TextBlob.makeFromString("hello", font, drawing.TextEncoding.TEXT_ENCODING_UTF8);
4303e41f4b71Sopenharmony_ci    canvas.drawTextBlob(textBlob, 200, 200);
4304e41f4b71Sopenharmony_ci  }
4305e41f4b71Sopenharmony_ci}
4306e41f4b71Sopenharmony_ci```
4307e41f4b71Sopenharmony_ci
4308e41f4b71Sopenharmony_ci### setEdging<sup>12+</sup>
4309e41f4b71Sopenharmony_ci
4310e41f4b71Sopenharmony_cisetEdging(edging: FontEdging): void
4311e41f4b71Sopenharmony_ci
4312e41f4b71Sopenharmony_ciSets a font edging effect.
4313e41f4b71Sopenharmony_ci
4314e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4315e41f4b71Sopenharmony_ci
4316e41f4b71Sopenharmony_ci**Parameters**
4317e41f4b71Sopenharmony_ci
4318e41f4b71Sopenharmony_ci| Name  | Type                         | Mandatory| Description      |
4319e41f4b71Sopenharmony_ci| -------- | ----------------------------- | ---- | ---------- |
4320e41f4b71Sopenharmony_ci| edging | [FontEdging](#fontedging12) | Yes  | Font edging effect.|
4321e41f4b71Sopenharmony_ci
4322e41f4b71Sopenharmony_ci**Error codes**
4323e41f4b71Sopenharmony_ci
4324e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4325e41f4b71Sopenharmony_ci
4326e41f4b71Sopenharmony_ci| ID| Error Message|
4327e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
4328e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
4329e41f4b71Sopenharmony_ci
4330e41f4b71Sopenharmony_ci**Example**
4331e41f4b71Sopenharmony_ci
4332e41f4b71Sopenharmony_ci```ts
4333e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
4334e41f4b71Sopenharmony_ci
4335e41f4b71Sopenharmony_cilet font = new drawing.Font();
4336e41f4b71Sopenharmony_cifont.setEdging(drawing.FontEdging.SUBPIXEL_ANTI_ALIAS);
4337e41f4b71Sopenharmony_ci```
4338e41f4b71Sopenharmony_ci
4339e41f4b71Sopenharmony_ci### setHinting<sup>12+</sup>
4340e41f4b71Sopenharmony_ci
4341e41f4b71Sopenharmony_cisetHinting(hinting: FontHinting): void
4342e41f4b71Sopenharmony_ci
4343e41f4b71Sopenharmony_ciSets a font hinting effect.
4344e41f4b71Sopenharmony_ci
4345e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4346e41f4b71Sopenharmony_ci
4347e41f4b71Sopenharmony_ci**Parameters**
4348e41f4b71Sopenharmony_ci
4349e41f4b71Sopenharmony_ci| Name  | Type                         | Mandatory| Description      |
4350e41f4b71Sopenharmony_ci| -------- | ----------------------------- | ---- | ---------- |
4351e41f4b71Sopenharmony_ci| hinting | [FontHinting](#fonthinting12) | Yes  | Font hinting effect.|
4352e41f4b71Sopenharmony_ci
4353e41f4b71Sopenharmony_ci**Error codes**
4354e41f4b71Sopenharmony_ci
4355e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4356e41f4b71Sopenharmony_ci
4357e41f4b71Sopenharmony_ci| ID| Error Message|
4358e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
4359e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
4360e41f4b71Sopenharmony_ci
4361e41f4b71Sopenharmony_ci**Example**
4362e41f4b71Sopenharmony_ci
4363e41f4b71Sopenharmony_ci```ts
4364e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
4365e41f4b71Sopenharmony_ci
4366e41f4b71Sopenharmony_cilet font = new drawing.Font();
4367e41f4b71Sopenharmony_cifont.setHinting(drawing.FontHinting.FULL);
4368e41f4b71Sopenharmony_ci```
4369e41f4b71Sopenharmony_ci
4370e41f4b71Sopenharmony_ci### countText<sup>12+</sup>
4371e41f4b71Sopenharmony_ci
4372e41f4b71Sopenharmony_cicountText(text: string): number
4373e41f4b71Sopenharmony_ci
4374e41f4b71Sopenharmony_ciObtains the number of glyphs represented by text.
4375e41f4b71Sopenharmony_ci
4376e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4377e41f4b71Sopenharmony_ci
4378e41f4b71Sopenharmony_ci**Parameters**
4379e41f4b71Sopenharmony_ci
4380e41f4b71Sopenharmony_ci| Name  | Type                         | Mandatory| Description      |
4381e41f4b71Sopenharmony_ci| -------- | ----------------------------- | ---- | ---------- |
4382e41f4b71Sopenharmony_ci| text     | string                        | Yes  | Text content.|
4383e41f4b71Sopenharmony_ci
4384e41f4b71Sopenharmony_ci**Return value**
4385e41f4b71Sopenharmony_ci
4386e41f4b71Sopenharmony_ci| Type  | Description            |
4387e41f4b71Sopenharmony_ci| ------ | ---------------- |
4388e41f4b71Sopenharmony_ci| number | Number of glyphs represented by the text. The value is an integer.|
4389e41f4b71Sopenharmony_ci
4390e41f4b71Sopenharmony_ci**Error codes**
4391e41f4b71Sopenharmony_ci
4392e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4393e41f4b71Sopenharmony_ci
4394e41f4b71Sopenharmony_ci| ID| Error Message|
4395e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
4396e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4397e41f4b71Sopenharmony_ci
4398e41f4b71Sopenharmony_ci**Example**
4399e41f4b71Sopenharmony_ci
4400e41f4b71Sopenharmony_ci```ts
4401e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
4402e41f4b71Sopenharmony_ci
4403e41f4b71Sopenharmony_cilet font = new drawing.Font();
4404e41f4b71Sopenharmony_cilet resultNumber: number = font.countText('ABCDE');
4405e41f4b71Sopenharmony_ciconsole.info("count text number: " + resultNumber);
4406e41f4b71Sopenharmony_ci```
4407e41f4b71Sopenharmony_ci
4408e41f4b71Sopenharmony_ci### setBaselineSnap<sup>12+</sup>
4409e41f4b71Sopenharmony_ci
4410e41f4b71Sopenharmony_cisetBaselineSnap(isBaselineSnap: boolean): void
4411e41f4b71Sopenharmony_ci
4412e41f4b71Sopenharmony_ciSets whether to request that baselines be snapped to pixels when the current canvas matrix is axis aligned.
4413e41f4b71Sopenharmony_ci
4414e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4415e41f4b71Sopenharmony_ci
4416e41f4b71Sopenharmony_ci**Parameters**
4417e41f4b71Sopenharmony_ci
4418e41f4b71Sopenharmony_ci| Name         | Type   | Mandatory| Description                                      |
4419e41f4b71Sopenharmony_ci| --------------- | ------- | ---- | ---------------------------------------- |
4420e41f4b71Sopenharmony_ci| isBaselineSnap | boolean | Yes  | Whether to request that baselines be snapped to pixels. The value **true** means to request that baselines be snapped to pixels, and **false** means the opposite.|
4421e41f4b71Sopenharmony_ci
4422e41f4b71Sopenharmony_ci**Error codes**
4423e41f4b71Sopenharmony_ci
4424e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4425e41f4b71Sopenharmony_ci
4426e41f4b71Sopenharmony_ci| ID| Error Message|
4427e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
4428e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4429e41f4b71Sopenharmony_ci
4430e41f4b71Sopenharmony_ci**Example**
4431e41f4b71Sopenharmony_ci
4432e41f4b71Sopenharmony_ci```ts
4433e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
4434e41f4b71Sopenharmony_ci
4435e41f4b71Sopenharmony_cilet font : drawing.Font = new drawing.Font();
4436e41f4b71Sopenharmony_cifont.setBaselineSnap(true);
4437e41f4b71Sopenharmony_ciconsole.info("drawing font isBaselineSnap: " + font.isBaselineSnap());
4438e41f4b71Sopenharmony_ci```
4439e41f4b71Sopenharmony_ci
4440e41f4b71Sopenharmony_ci### isBaselineSnap()<sup>12+</sup>
4441e41f4b71Sopenharmony_ci
4442e41f4b71Sopenharmony_ciisBaselineSnap(): boolean
4443e41f4b71Sopenharmony_ci
4444e41f4b71Sopenharmony_ciChecks whether baselines are requested to be snapped to pixels when the current canvas matrix is axis aligned.
4445e41f4b71Sopenharmony_ci
4446e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4447e41f4b71Sopenharmony_ci
4448e41f4b71Sopenharmony_ci**Return value**
4449e41f4b71Sopenharmony_ci
4450e41f4b71Sopenharmony_ci| Type  | Description            |
4451e41f4b71Sopenharmony_ci| ------ | ---------------- |
4452e41f4b71Sopenharmony_ci| boolean | Result indicating whether the baselines are requested to be snapped to pixels when the current canvas matrix is axis aligned. The value **true** means that the baselines are requested to be snapped to pixels, and **false** means the opposite.|
4453e41f4b71Sopenharmony_ci
4454e41f4b71Sopenharmony_ci**Example**
4455e41f4b71Sopenharmony_ci
4456e41f4b71Sopenharmony_ci```ts
4457e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
4458e41f4b71Sopenharmony_ci
4459e41f4b71Sopenharmony_cilet font : drawing.Font = new drawing.Font();
4460e41f4b71Sopenharmony_cifont.setTypeface(new drawing.Typeface());
4461e41f4b71Sopenharmony_cifont.setBaselineSnap(true);
4462e41f4b71Sopenharmony_ciconsole.info("drawing font isBaselineSnap: " + font.isBaselineSnap());
4463e41f4b71Sopenharmony_ci```
4464e41f4b71Sopenharmony_ci
4465e41f4b71Sopenharmony_ci### setEmbeddedBitmaps<sup>12+</sup>
4466e41f4b71Sopenharmony_ci
4467e41f4b71Sopenharmony_cisetEmbeddedBitmaps(isEmbeddedBitmaps: boolean): void
4468e41f4b71Sopenharmony_ci
4469e41f4b71Sopenharmony_ciSets whether to use bitmaps in this font.
4470e41f4b71Sopenharmony_ci
4471e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4472e41f4b71Sopenharmony_ci
4473e41f4b71Sopenharmony_ci**Parameters**
4474e41f4b71Sopenharmony_ci
4475e41f4b71Sopenharmony_ci| Name  | Type  | Mandatory| Description            |
4476e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---------------- |
4477e41f4b71Sopenharmony_ci| isEmbeddedBitmaps | boolean | Yes  | Whether to use bitmaps in the font. The value **true** means to use bitmaps in the font, and **false** means the opposite.|
4478e41f4b71Sopenharmony_ci
4479e41f4b71Sopenharmony_ci**Error codes**
4480e41f4b71Sopenharmony_ci
4481e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4482e41f4b71Sopenharmony_ci
4483e41f4b71Sopenharmony_ci| ID| Error Message|
4484e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
4485e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4486e41f4b71Sopenharmony_ci
4487e41f4b71Sopenharmony_ci**Example**
4488e41f4b71Sopenharmony_ci
4489e41f4b71Sopenharmony_ci```ts
4490e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
4491e41f4b71Sopenharmony_ci
4492e41f4b71Sopenharmony_cilet font : drawing.Font = new drawing.Font();
4493e41f4b71Sopenharmony_cifont.setTypeface(new drawing.Typeface());
4494e41f4b71Sopenharmony_cifont.setEmbeddedBitmaps(false);
4495e41f4b71Sopenharmony_ciconsole.info("draw isEmbeddedBitmaps: " + font.isEmbeddedBitmaps());
4496e41f4b71Sopenharmony_ci```
4497e41f4b71Sopenharmony_ci
4498e41f4b71Sopenharmony_ci### isEmbeddedBitmaps()<sup>12+</sup>
4499e41f4b71Sopenharmony_ci
4500e41f4b71Sopenharmony_ciisEmbeddedBitmaps(): boolean
4501e41f4b71Sopenharmony_ci
4502e41f4b71Sopenharmony_ciChecks whether bitmaps are used in this font.
4503e41f4b71Sopenharmony_ci
4504e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4505e41f4b71Sopenharmony_ci
4506e41f4b71Sopenharmony_ci**Return value**
4507e41f4b71Sopenharmony_ci
4508e41f4b71Sopenharmony_ci| Type  | Description            |
4509e41f4b71Sopenharmony_ci| ------ | ---------------- |
4510e41f4b71Sopenharmony_ci| boolean | Result indicating whether the bitmaps are used in the font. The value **true** means that the bitmaps are used, and **false** means the opposite.|
4511e41f4b71Sopenharmony_ci
4512e41f4b71Sopenharmony_ci**Example**
4513e41f4b71Sopenharmony_ci
4514e41f4b71Sopenharmony_ci```ts
4515e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
4516e41f4b71Sopenharmony_ci
4517e41f4b71Sopenharmony_cilet font : drawing.Font = new drawing.Font();
4518e41f4b71Sopenharmony_cifont.setTypeface(new drawing.Typeface());
4519e41f4b71Sopenharmony_cifont.setEmbeddedBitmaps(true);
4520e41f4b71Sopenharmony_ciconsole.info("draw isEmbeddedBitmaps: " + font.isEmbeddedBitmaps());
4521e41f4b71Sopenharmony_ci```
4522e41f4b71Sopenharmony_ci
4523e41f4b71Sopenharmony_ci### setForceAutoHinting<sup>12+</sup>
4524e41f4b71Sopenharmony_ci
4525e41f4b71Sopenharmony_cisetForceAutoHinting(isForceAutoHinting: boolean): void
4526e41f4b71Sopenharmony_ci
4527e41f4b71Sopenharmony_ciSets whether to forcibly use auto hinting, that is, whether to always hint glyphs.
4528e41f4b71Sopenharmony_ci
4529e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4530e41f4b71Sopenharmony_ci
4531e41f4b71Sopenharmony_ci**Parameters**
4532e41f4b71Sopenharmony_ci
4533e41f4b71Sopenharmony_ci| Name  | Type  | Mandatory| Description            |
4534e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---------------- |
4535e41f4b71Sopenharmony_ci| isForceAutoHinting | boolean | Yes  | Whether to forcibly use auto hinting. The value **true** means to forcibly use auto hinting, and **false** means the opposite.|
4536e41f4b71Sopenharmony_ci
4537e41f4b71Sopenharmony_ci**Error codes**
4538e41f4b71Sopenharmony_ci
4539e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4540e41f4b71Sopenharmony_ci
4541e41f4b71Sopenharmony_ci| ID| Error Message|
4542e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
4543e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4544e41f4b71Sopenharmony_ci
4545e41f4b71Sopenharmony_ci**Example**
4546e41f4b71Sopenharmony_ci
4547e41f4b71Sopenharmony_ci```ts
4548e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
4549e41f4b71Sopenharmony_ci
4550e41f4b71Sopenharmony_cilet font : drawing.Font = new drawing.Font();
4551e41f4b71Sopenharmony_cifont.setTypeface(new drawing.Typeface());
4552e41f4b71Sopenharmony_cifont.setForceAutoHinting(false);
4553e41f4b71Sopenharmony_ciconsole.info("drawing isForceAutoHinting:  " + font.isForceAutoHinting());
4554e41f4b71Sopenharmony_ci```
4555e41f4b71Sopenharmony_ci
4556e41f4b71Sopenharmony_ci### isForceAutoHinting<sup>12+</sup>
4557e41f4b71Sopenharmony_ci
4558e41f4b71Sopenharmony_ciisForceAutoHinting(): boolean
4559e41f4b71Sopenharmony_ci
4560e41f4b71Sopenharmony_ciChecks whether auto hinting is forcibly used.
4561e41f4b71Sopenharmony_ci
4562e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4563e41f4b71Sopenharmony_ci
4564e41f4b71Sopenharmony_ci**Return value**
4565e41f4b71Sopenharmony_ci
4566e41f4b71Sopenharmony_ci| Type  | Description            |
4567e41f4b71Sopenharmony_ci| ------ | ---------------- |
4568e41f4b71Sopenharmony_ci| boolean | Result indicating whether auto hinting is forcibly used. The value **true** means that auto hinting is forcibly used, and **false** means the opposite.|
4569e41f4b71Sopenharmony_ci
4570e41f4b71Sopenharmony_ci**Example**
4571e41f4b71Sopenharmony_ci
4572e41f4b71Sopenharmony_ci```ts
4573e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
4574e41f4b71Sopenharmony_ci
4575e41f4b71Sopenharmony_cilet font : drawing.Font = new drawing.Font();
4576e41f4b71Sopenharmony_cifont.setTypeface(new drawing.Typeface());
4577e41f4b71Sopenharmony_cifont.setForceAutoHinting(false);
4578e41f4b71Sopenharmony_ciconsole.info("drawing isForceAutoHinting:  " + font.isForceAutoHinting());
4579e41f4b71Sopenharmony_ci```
4580e41f4b71Sopenharmony_ci
4581e41f4b71Sopenharmony_ci### getWidths<sup>12+</sup>
4582e41f4b71Sopenharmony_ci
4583e41f4b71Sopenharmony_cigetWidths(glyphs: Array\<number>): Array\<number>
4584e41f4b71Sopenharmony_ci
4585e41f4b71Sopenharmony_ciObtains the width of each glyph in an array.
4586e41f4b71Sopenharmony_ci
4587e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4588e41f4b71Sopenharmony_ci
4589e41f4b71Sopenharmony_ci**Parameters**
4590e41f4b71Sopenharmony_ci
4591e41f4b71Sopenharmony_ci| Name  | Type                 | Mandatory| Description  |
4592e41f4b71Sopenharmony_ci| -------- | --------------------- | ---- | ------ |
4593e41f4b71Sopenharmony_ci| glyphs | Array\<number> | Yes  | Glyph array, which can be generated by [textToGlyphs](#texttoglyphs12).|
4594e41f4b71Sopenharmony_ci
4595e41f4b71Sopenharmony_ci**Return value**
4596e41f4b71Sopenharmony_ci
4597e41f4b71Sopenharmony_ci| Type  | Description            |
4598e41f4b71Sopenharmony_ci| ------ | ---------------- |
4599e41f4b71Sopenharmony_ci| Array\<number> | Array that holds the obtained glyph widths.|
4600e41f4b71Sopenharmony_ci
4601e41f4b71Sopenharmony_ci**Error codes**
4602e41f4b71Sopenharmony_ci
4603e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4604e41f4b71Sopenharmony_ci
4605e41f4b71Sopenharmony_ci| ID| Error Message|
4606e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
4607e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4608e41f4b71Sopenharmony_ci
4609e41f4b71Sopenharmony_ci**Example**
4610e41f4b71Sopenharmony_ci
4611e41f4b71Sopenharmony_ci```ts
4612e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
4613e41f4b71Sopenharmony_ci
4614e41f4b71Sopenharmony_cilet font: drawing.Font = new drawing.Font();
4615e41f4b71Sopenharmony_cilet text: string = 'hello world';
4616e41f4b71Sopenharmony_cilet glyphs: number[] = font.textToGlyphs(text);
4617e41f4b71Sopenharmony_cilet fontWidths: Array<number> = font.getWidths(glyphs);
4618e41f4b71Sopenharmony_cifor (let index = 0; index < fontWidths.length; index++) {
4619e41f4b71Sopenharmony_ci  console.info("get fontWidths[", index, "]:", fontWidths[index]);
4620e41f4b71Sopenharmony_ci}
4621e41f4b71Sopenharmony_ci```
4622e41f4b71Sopenharmony_ci
4623e41f4b71Sopenharmony_ci### textToGlyphs<sup>12+</sup>
4624e41f4b71Sopenharmony_ci
4625e41f4b71Sopenharmony_citextToGlyphs(text: string, glyphCount?: number): Array\<number>
4626e41f4b71Sopenharmony_ci
4627e41f4b71Sopenharmony_ciConverts text into glyph indexes.
4628e41f4b71Sopenharmony_ci
4629e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4630e41f4b71Sopenharmony_ci
4631e41f4b71Sopenharmony_ci**Parameters**
4632e41f4b71Sopenharmony_ci
4633e41f4b71Sopenharmony_ci| Name  | Type                         | Mandatory| Description      |
4634e41f4b71Sopenharmony_ci| -------- | ----------------------------- | ---- | ---------- |
4635e41f4b71Sopenharmony_ci| text     | string                        | Yes  | Text string.|
4636e41f4b71Sopenharmony_ci| glyphCount | number | No  | Number of glyphs represented by the text. The value must be the same as the value obtained from [countText](#counttext12). The default value is the number of characters in the text string. The value is an integer.|
4637e41f4b71Sopenharmony_ci
4638e41f4b71Sopenharmony_ci**Return value**
4639e41f4b71Sopenharmony_ci
4640e41f4b71Sopenharmony_ci| Type  | Description            |
4641e41f4b71Sopenharmony_ci| ------ | ---------------- |
4642e41f4b71Sopenharmony_ci| Array\<number> | Array that holds the glyph indexes.|
4643e41f4b71Sopenharmony_ci
4644e41f4b71Sopenharmony_ci**Error codes**
4645e41f4b71Sopenharmony_ci
4646e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4647e41f4b71Sopenharmony_ci
4648e41f4b71Sopenharmony_ci| ID| Error Message|
4649e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
4650e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4651e41f4b71Sopenharmony_ci
4652e41f4b71Sopenharmony_ci**Example**
4653e41f4b71Sopenharmony_ci
4654e41f4b71Sopenharmony_ci```ts
4655e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
4656e41f4b71Sopenharmony_ci
4657e41f4b71Sopenharmony_cilet font : drawing.Font = new drawing.Font();
4658e41f4b71Sopenharmony_cilet text : string = 'hello world';
4659e41f4b71Sopenharmony_cilet glyphs : number[] = font.textToGlyphs(text);
4660e41f4b71Sopenharmony_ciconsole.info("drawing text toglyphs OnTestFunction num =  " + glyphs.length );
4661e41f4b71Sopenharmony_ci```
4662e41f4b71Sopenharmony_ci
4663e41f4b71Sopenharmony_ci## FontMetricsFlags<sup>12+</sup>
4664e41f4b71Sopenharmony_ci
4665e41f4b71Sopenharmony_ciEnumerates the font measurement flags, which is used to specify whether a field in the font measurement information is valid.
4666e41f4b71Sopenharmony_ci
4667e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4668e41f4b71Sopenharmony_ci
4669e41f4b71Sopenharmony_ci| Name                         | Value       | Description                          |
4670e41f4b71Sopenharmony_ci| ----------------------------- | --------- | ------------------------------ |
4671e41f4b71Sopenharmony_ci| UNDERLINE_THICKNESS_VALID     | 1 << 0    | The **underlineThickness** field in the [FontMetrics](#fontmetrics) struct is valid.   |
4672e41f4b71Sopenharmony_ci| UNDERLINE_POSITION_VALID      | 1 << 1    | The **underlinePosition** field in the [FontMetrics](#fontmetrics) struct is valid. |
4673e41f4b71Sopenharmony_ci| STRIKETHROUGH_THICKNESS_VALID | 1 << 2    | The **strikethroughThickness** field in the [FontMetrics](#fontmetrics) struct is valid.|
4674e41f4b71Sopenharmony_ci| STRIKETHROUGH_POSITION_VALID  | 1 << 3    | The **strikethroughPosition** field in the [FontMetrics](#fontmetrics) struct is valid. |
4675e41f4b71Sopenharmony_ci| BOUNDS_INVALID                | 1 << 4    | The boundary metrics (such as **top**, **bottom**, **xMin**, and **xMax**) in the [FontMetrics](#fontmetrics) struct are invalid. |
4676e41f4b71Sopenharmony_ci
4677e41f4b71Sopenharmony_ci## FontMetrics
4678e41f4b71Sopenharmony_ci
4679e41f4b71Sopenharmony_ciDescribes the attributes that describe the font size and layout. A typeface has similar font metrics.
4680e41f4b71Sopenharmony_ci
4681e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4682e41f4b71Sopenharmony_ci
4683e41f4b71Sopenharmony_ci| Name   | Type  | Read Only| Optional| Description                                                        |
4684e41f4b71Sopenharmony_ci| ------- | ------ | ---- | ---- | ------------------------------------------------------------ |
4685e41f4b71Sopenharmony_ci| flags<sup>12+</sup>   | [FontMetricsFlags](#fontmetricsflags12) | Yes  | Yes  | Font measurement flags that are valid.       |
4686e41f4b71Sopenharmony_ci| top     | number | Yes  | No  | Maximum distance from the baseline to the highest coordinate of the text. The value is a floating point number.                        |
4687e41f4b71Sopenharmony_ci| ascent  | number | Yes  | No  | Distance from the baseline to the highest coordinate of the text. The value is a floating point number.                            |
4688e41f4b71Sopenharmony_ci| descent | number | Yes  | No  | Distance from the baseline to the lowest coordinate of the text. The value is a floating point number.                            |
4689e41f4b71Sopenharmony_ci| bottom  | number | Yes  | No  | Maximum distance from the baseline to the lowest coordinate of the text. The value is a floating point number.                        |
4690e41f4b71Sopenharmony_ci| leading | number | Yes  | No  | Interline spacing, that is, the distance from the descent of one line of text to the ascent of the next line. The value is a floating point number.|
4691e41f4b71Sopenharmony_ci| avgCharWidth<sup>12+</sup> | number | Yes  | Yes  | Average character width.                            |
4692e41f4b71Sopenharmony_ci| maxCharWidth<sup>12+</sup> | number | Yes  | Yes  | Maximum character width.                            |
4693e41f4b71Sopenharmony_ci| xMin<sup>12+</sup> | number | Yes   | Yes  | Horizontal distance from the leftmost edge of any glyph bounding box to the origin. This value is usually less than 0, indicating the minimum horizontal coordinate across all glyph bounding boxes.               |
4694e41f4b71Sopenharmony_ci| xMax<sup>12+</sup> | number | Yes  | Yes  | Horizontal distance from the rightmost edge of any glyph bounding box to the origin. The value is a positive number, indicating the maximum horizontal coordinate across all glyph bounding boxes.       |
4695e41f4b71Sopenharmony_ci| xHeight<sup>12+</sup> | number | Yes  | Yes  | Height of the lowercase letter x. The value is usually a negative value.                    |
4696e41f4b71Sopenharmony_ci| capHeight<sup>12+</sup> | number | Yes  | Yes  | Height of a capital letter. The value is usually a negative value.                     |
4697e41f4b71Sopenharmony_ci| underlineThickness<sup>12+</sup> | number | Yes  | Yes  | Thickness of the underline.                                         |
4698e41f4b71Sopenharmony_ci| underlinePosition<sup>12+</sup>  | number | Yes  | Yes  | Vertical distance from the baseline to the top of the underline. The value is usually a positive number.            |
4699e41f4b71Sopenharmony_ci| strikethroughThickness<sup>12+</sup>  | number | Yes  | Yes  | Thickness of the strikethrough.   |
4700e41f4b71Sopenharmony_ci| strikethroughPosition<sup>12+</sup>  | number | Yes  | Yes  | Vertical distance from the baseline to the bottom of the strikethrough. The value is usually a negative value.        |
4701e41f4b71Sopenharmony_ci
4702e41f4b71Sopenharmony_ci## ColorFilter
4703e41f4b71Sopenharmony_ci
4704e41f4b71Sopenharmony_ciDefines a color filter.
4705e41f4b71Sopenharmony_ci
4706e41f4b71Sopenharmony_ci### createBlendModeColorFilter
4707e41f4b71Sopenharmony_ci
4708e41f4b71Sopenharmony_cicreateBlendModeColorFilter(color: common2D.Color, mode: BlendMode) : ColorFilter
4709e41f4b71Sopenharmony_ci
4710e41f4b71Sopenharmony_ciCreates a **ColorFilter** object with a given color and blend mode.
4711e41f4b71Sopenharmony_ci
4712e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4713e41f4b71Sopenharmony_ci
4714e41f4b71Sopenharmony_ci**Parameters**
4715e41f4b71Sopenharmony_ci
4716e41f4b71Sopenharmony_ci| Name| Type                                                | Mandatory| Description            |
4717e41f4b71Sopenharmony_ci| ------ | ---------------------------------------------------- | ---- | ---------------- |
4718e41f4b71Sopenharmony_ci| color  | [common2D.Color](js-apis-graphics-common2D.md#color) | Yes  | Color in ARGB format. Each color channel is an integer ranging from 0 to 255.|
4719e41f4b71Sopenharmony_ci| mode   | [BlendMode](#blendmode)                              | Yes  | Blend mode.|
4720e41f4b71Sopenharmony_ci
4721e41f4b71Sopenharmony_ci**Return value**
4722e41f4b71Sopenharmony_ci
4723e41f4b71Sopenharmony_ci| Type                       | Description              |
4724e41f4b71Sopenharmony_ci| --------------------------- | ------------------ |
4725e41f4b71Sopenharmony_ci| [ColorFilter](#colorfilter) | **ColorFilter** object created.|
4726e41f4b71Sopenharmony_ci
4727e41f4b71Sopenharmony_ci**Error codes**
4728e41f4b71Sopenharmony_ci
4729e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4730e41f4b71Sopenharmony_ci
4731e41f4b71Sopenharmony_ci| ID| Error Message|
4732e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
4733e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
4734e41f4b71Sopenharmony_ci
4735e41f4b71Sopenharmony_ci**Example**
4736e41f4b71Sopenharmony_ci
4737e41f4b71Sopenharmony_ci```ts
4738e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
4739e41f4b71Sopenharmony_ciconst color : common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
4740e41f4b71Sopenharmony_cilet colorFilter = drawing.ColorFilter.createBlendModeColorFilter(color, drawing.BlendMode.SRC);
4741e41f4b71Sopenharmony_ci```
4742e41f4b71Sopenharmony_ci
4743e41f4b71Sopenharmony_ci### createComposeColorFilter
4744e41f4b71Sopenharmony_ci
4745e41f4b71Sopenharmony_cicreateComposeColorFilter(outer: ColorFilter, inner: ColorFilter) : ColorFilter
4746e41f4b71Sopenharmony_ci
4747e41f4b71Sopenharmony_ciCreates a **ColorFilter** object by combining another two color filters.
4748e41f4b71Sopenharmony_ci
4749e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4750e41f4b71Sopenharmony_ci
4751e41f4b71Sopenharmony_ci**Parameters**
4752e41f4b71Sopenharmony_ci
4753e41f4b71Sopenharmony_ci| Name| Type                       | Mandatory| Description                            |
4754e41f4b71Sopenharmony_ci| ------ | --------------------------- | ---- | -------------------------------- |
4755e41f4b71Sopenharmony_ci| outer  | [ColorFilter](#colorfilter) | Yes  | Color filter that takes effect later in the new filter.|
4756e41f4b71Sopenharmony_ci| inner  | [ColorFilter](#colorfilter) | Yes  | Color filter that takes effect first in the new filter.|
4757e41f4b71Sopenharmony_ci
4758e41f4b71Sopenharmony_ci**Return value**
4759e41f4b71Sopenharmony_ci
4760e41f4b71Sopenharmony_ci| Type                       | Description              |
4761e41f4b71Sopenharmony_ci| --------------------------- | ------------------ |
4762e41f4b71Sopenharmony_ci| [ColorFilter](#colorfilter) | **ColorFilter** object created.|
4763e41f4b71Sopenharmony_ci
4764e41f4b71Sopenharmony_ci**Error codes**
4765e41f4b71Sopenharmony_ci
4766e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4767e41f4b71Sopenharmony_ci
4768e41f4b71Sopenharmony_ci| ID| Error Message|
4769e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
4770e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4771e41f4b71Sopenharmony_ci
4772e41f4b71Sopenharmony_ci**Example**
4773e41f4b71Sopenharmony_ci
4774e41f4b71Sopenharmony_ci```ts
4775e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
4776e41f4b71Sopenharmony_ciconst color : common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
4777e41f4b71Sopenharmony_cilet colorFilter1 = drawing.ColorFilter.createBlendModeColorFilter(color, drawing.BlendMode.SRC);
4778e41f4b71Sopenharmony_cilet colorFilter2 = drawing.ColorFilter.createBlendModeColorFilter(color, drawing.BlendMode.DST);
4779e41f4b71Sopenharmony_cilet colorFilter = drawing.ColorFilter.createComposeColorFilter(colorFilter1, colorFilter2);
4780e41f4b71Sopenharmony_ci```
4781e41f4b71Sopenharmony_ci
4782e41f4b71Sopenharmony_ci### createLinearToSRGBGamma
4783e41f4b71Sopenharmony_ci
4784e41f4b71Sopenharmony_cicreateLinearToSRGBGamma() : ColorFilter
4785e41f4b71Sopenharmony_ci
4786e41f4b71Sopenharmony_ciCreates a **ColorFilter** object that applies the sRGB gamma curve to the RGB channels.
4787e41f4b71Sopenharmony_ci
4788e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4789e41f4b71Sopenharmony_ci
4790e41f4b71Sopenharmony_ci**Return value**
4791e41f4b71Sopenharmony_ci
4792e41f4b71Sopenharmony_ci| Type                       | Description              |
4793e41f4b71Sopenharmony_ci| --------------------------- | ------------------ |
4794e41f4b71Sopenharmony_ci| [ColorFilter](#colorfilter) | **ColorFilter** object created.|
4795e41f4b71Sopenharmony_ci
4796e41f4b71Sopenharmony_ci**Example**
4797e41f4b71Sopenharmony_ci
4798e41f4b71Sopenharmony_ci```ts
4799e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
4800e41f4b71Sopenharmony_cilet colorFilter = drawing.ColorFilter.createLinearToSRGBGamma();
4801e41f4b71Sopenharmony_ci```
4802e41f4b71Sopenharmony_ci
4803e41f4b71Sopenharmony_ci### createSRGBGammaToLinear
4804e41f4b71Sopenharmony_ci
4805e41f4b71Sopenharmony_cicreateSRGBGammaToLinear() : ColorFilter
4806e41f4b71Sopenharmony_ci
4807e41f4b71Sopenharmony_ciCreates a **ColorFilter** object that applies the RGB channels to the sRGB gamma curve.
4808e41f4b71Sopenharmony_ci
4809e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4810e41f4b71Sopenharmony_ci
4811e41f4b71Sopenharmony_ci**Return value**
4812e41f4b71Sopenharmony_ci
4813e41f4b71Sopenharmony_ci| Type                       | Description              |
4814e41f4b71Sopenharmony_ci| --------------------------- | ------------------ |
4815e41f4b71Sopenharmony_ci| [ColorFilter](#colorfilter) | **ColorFilter** object created.|
4816e41f4b71Sopenharmony_ci
4817e41f4b71Sopenharmony_ci**Example**
4818e41f4b71Sopenharmony_ci
4819e41f4b71Sopenharmony_ci```ts
4820e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
4821e41f4b71Sopenharmony_cilet colorFilter = drawing.ColorFilter.createSRGBGammaToLinear();
4822e41f4b71Sopenharmony_ci```
4823e41f4b71Sopenharmony_ci
4824e41f4b71Sopenharmony_ci### createLumaColorFilter
4825e41f4b71Sopenharmony_ci
4826e41f4b71Sopenharmony_cicreateLumaColorFilter() : ColorFilter
4827e41f4b71Sopenharmony_ci
4828e41f4b71Sopenharmony_ciCreates a **ColorFilter** object that multiplies the luma into the alpha channel.
4829e41f4b71Sopenharmony_ci
4830e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4831e41f4b71Sopenharmony_ci
4832e41f4b71Sopenharmony_ci**Return value**
4833e41f4b71Sopenharmony_ci
4834e41f4b71Sopenharmony_ci| Type                       | Description              |
4835e41f4b71Sopenharmony_ci| --------------------------- | ------------------ |
4836e41f4b71Sopenharmony_ci| [ColorFilter](#colorfilter) | **ColorFilter** object created.|
4837e41f4b71Sopenharmony_ci
4838e41f4b71Sopenharmony_ci**Example**
4839e41f4b71Sopenharmony_ci
4840e41f4b71Sopenharmony_ci```ts
4841e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
4842e41f4b71Sopenharmony_cilet colorFilter = drawing.ColorFilter.createLumaColorFilter();
4843e41f4b71Sopenharmony_ci```
4844e41f4b71Sopenharmony_ci
4845e41f4b71Sopenharmony_ci### createMatrixColorFilter<sup>12+</sup>
4846e41f4b71Sopenharmony_ci
4847e41f4b71Sopenharmony_cistatic createMatrixColorFilter(matrix: Array\<number>): ColorFilter
4848e41f4b71Sopenharmony_ci
4849e41f4b71Sopenharmony_ciCreates a color filter object with a 4*5 color matrix.
4850e41f4b71Sopenharmony_ci
4851e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4852e41f4b71Sopenharmony_ci
4853e41f4b71Sopenharmony_ci**Parameters**
4854e41f4b71Sopenharmony_ci
4855e41f4b71Sopenharmony_ci| Name  | Type                                        | Mandatory| Description                           |
4856e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | ---- | ------------------------------- |
4857e41f4b71Sopenharmony_ci| matrix | Array\<number> | Yes  | An array of 20 numbers, indicating the 4*5 matrix.                |
4858e41f4b71Sopenharmony_ci
4859e41f4b71Sopenharmony_ci**Return value**
4860e41f4b71Sopenharmony_ci
4861e41f4b71Sopenharmony_ci| Type                       | Description              |
4862e41f4b71Sopenharmony_ci| --------------------------- | ------------------ |
4863e41f4b71Sopenharmony_ci| [ColorFilter](#colorfilter) | Color filter created.|
4864e41f4b71Sopenharmony_ci
4865e41f4b71Sopenharmony_ci**Error codes**
4866e41f4b71Sopenharmony_ci
4867e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4868e41f4b71Sopenharmony_ci
4869e41f4b71Sopenharmony_ci| ID| Error Message|
4870e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
4871e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
4872e41f4b71Sopenharmony_ci
4873e41f4b71Sopenharmony_ci**Example**
4874e41f4b71Sopenharmony_ci
4875e41f4b71Sopenharmony_ci```ts
4876e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
4877e41f4b71Sopenharmony_cilet matrix: Array<number> = [
4878e41f4b71Sopenharmony_ci  1, 0, 0, 0, 0,
4879e41f4b71Sopenharmony_ci  0, 1, 0, 0, 0,
4880e41f4b71Sopenharmony_ci  0, 0, 100, 0, 0,
4881e41f4b71Sopenharmony_ci  0, 0, 0, 1, 0
4882e41f4b71Sopenharmony_ci];
4883e41f4b71Sopenharmony_cilet colorFilter = drawing.ColorFilter.createMatrixColorFilter(matrix);
4884e41f4b71Sopenharmony_ci```
4885e41f4b71Sopenharmony_ci
4886e41f4b71Sopenharmony_ci## JoinStyle<sup>12+</sup>
4887e41f4b71Sopenharmony_ci
4888e41f4b71Sopenharmony_ciEnumerates the join styles of a pen. The join style defines the shape of the joints of a polyline segment drawn by the pen.
4889e41f4b71Sopenharmony_ci
4890e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4891e41f4b71Sopenharmony_ci
4892e41f4b71Sopenharmony_ci| Name       | Value  | Description                                                        | Diagram  |
4893e41f4b71Sopenharmony_ci| ----------- | ---- | ----------------------------------------------------------- | -------- |
4894e41f4b71Sopenharmony_ci| MITER_JOIN | 0    | Mitered corner. If the angle of a polyline is small, its miter length may be inappropriate. In this case, you need to use the miter limit to limit the miter length.| ![MITER_JOIN](./figures/image_JoinStyle_Miter_Join.png) |
4895e41f4b71Sopenharmony_ci| ROUND_JOIN | 1    | Round corner.| ![ROUND_JOIN](./figures/image_JoinStyle_Round_Join.png) |
4896e41f4b71Sopenharmony_ci| BEVEL_JOIN | 2    | Beveled corner.| ![BEVEL_JOIN](./figures/image_JoinStyle_Bevel_Join.png) |
4897e41f4b71Sopenharmony_ci
4898e41f4b71Sopenharmony_ci## CapStyle<sup>12+</sup>
4899e41f4b71Sopenharmony_ci
4900e41f4b71Sopenharmony_ciEnumerates the cap styles of a pen. The cap style defines the style of both ends of a line segment drawn by the pen.
4901e41f4b71Sopenharmony_ci
4902e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4903e41f4b71Sopenharmony_ci
4904e41f4b71Sopenharmony_ci| Name       | Value  | Description                                                        | Diagram  |
4905e41f4b71Sopenharmony_ci| ---------- | ---- | ----------------------------------------------------------- | -------- |
4906e41f4b71Sopenharmony_ci| FLAT_CAP   | 0    | There is no cap style. Both ends of the line segment are cut off square.| ![FLAT_CAP](./figures/image_CapStyle_Flat_Cap.png) |
4907e41f4b71Sopenharmony_ci| SQUARE_CAP | 1    | Square cap style. Both ends have a square, the height of which is half of the width of the line segment, with the same width.| ![SQUARE_CAP](./figures/image_CapStyle_Square_Cap.png) |
4908e41f4b71Sopenharmony_ci| ROUND_CAP  | 2    | Round cap style. Both ends have a semicircle centered, the diameter of which is the same as the width of the line segment.| ![ROUND_CAP](./figures/image_CapStyle_Round_Cap.png) |
4909e41f4b71Sopenharmony_ci
4910e41f4b71Sopenharmony_ci## BlurType<sup>12+</sup>
4911e41f4b71Sopenharmony_ci
4912e41f4b71Sopenharmony_ciEnumerates the blur types of a mask filter.
4913e41f4b71Sopenharmony_ci
4914e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4915e41f4b71Sopenharmony_ci
4916e41f4b71Sopenharmony_ci| Name  | Value| Description              | Diagram  |
4917e41f4b71Sopenharmony_ci| ------ | - | ------------------ | -------- |
4918e41f4b71Sopenharmony_ci| NORMAL | 0 | Blurs both inside and outside the original border.         | ![NORMAL](./figures/image_BlueType_Normal.png) |
4919e41f4b71Sopenharmony_ci| SOLID  | 1 | Draws solid inside the border, and blurs outside.| ![SOLID](./figures/image_BlueType_Solid.png) |
4920e41f4b71Sopenharmony_ci| OUTER  | 2 | Draws nothing inside the border, and blurs outside.| ![OUTER](./figures/image_BlueType_Outer.png) |
4921e41f4b71Sopenharmony_ci| INNER  | 3 | Blurs inside the border, and draws nothing outside.| ![INNER](./figures/image_BlueType_Inner.png) |
4922e41f4b71Sopenharmony_ci
4923e41f4b71Sopenharmony_ci## SamplingOptions<sup>12+</sup>
4924e41f4b71Sopenharmony_ci
4925e41f4b71Sopenharmony_ciImplements sampling options.
4926e41f4b71Sopenharmony_ci
4927e41f4b71Sopenharmony_ci### constructor<sup>12+</sup>
4928e41f4b71Sopenharmony_ci
4929e41f4b71Sopenharmony_ciconstructor()
4930e41f4b71Sopenharmony_ci
4931e41f4b71Sopenharmony_ciCreates a **SamplingOptions** object.
4932e41f4b71Sopenharmony_ci
4933e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4934e41f4b71Sopenharmony_ci
4935e41f4b71Sopenharmony_ci**Example**
4936e41f4b71Sopenharmony_ci
4937e41f4b71Sopenharmony_ci```ts
4938e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
4939e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
4940e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
4941e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
4942e41f4b71Sopenharmony_ci    const canvas = context.canvas;
4943e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
4944e41f4b71Sopenharmony_ci    let samplingOptions = new drawing.SamplingOptions();
4945e41f4b71Sopenharmony_ci  }
4946e41f4b71Sopenharmony_ci}
4947e41f4b71Sopenharmony_ci```
4948e41f4b71Sopenharmony_ci
4949e41f4b71Sopenharmony_ci### constructor<sup>12+</sup>
4950e41f4b71Sopenharmony_ci
4951e41f4b71Sopenharmony_ciconstructor(filterMode: FilterMode)
4952e41f4b71Sopenharmony_ci
4953e41f4b71Sopenharmony_ciCreates a **SamplingOptions** object.
4954e41f4b71Sopenharmony_ci
4955e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4956e41f4b71Sopenharmony_ci
4957e41f4b71Sopenharmony_ci**Parameters**
4958e41f4b71Sopenharmony_ci
4959e41f4b71Sopenharmony_ci| Name    | Type                  | Mandatory| Description                                |
4960e41f4b71Sopenharmony_ci| ---------- | --------------------- | ---- | ----------------------------------- |
4961e41f4b71Sopenharmony_ci| filterMode | [FilterMode](#filtermode12)    | Yes  | Filter mode.                   |
4962e41f4b71Sopenharmony_ci
4963e41f4b71Sopenharmony_ci**Error codes**
4964e41f4b71Sopenharmony_ci
4965e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4966e41f4b71Sopenharmony_ci
4967e41f4b71Sopenharmony_ci| ID| Error Message|
4968e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
4969e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4970e41f4b71Sopenharmony_ci
4971e41f4b71Sopenharmony_ci**Example**
4972e41f4b71Sopenharmony_ci
4973e41f4b71Sopenharmony_ci```ts
4974e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
4975e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
4976e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
4977e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
4978e41f4b71Sopenharmony_ci    const canvas = context.canvas;
4979e41f4b71Sopenharmony_ci    let samplingOptions = new drawing.SamplingOptions(drawing.FilterMode.FILTER_MODE_NEAREST);
4980e41f4b71Sopenharmony_ci  }
4981e41f4b71Sopenharmony_ci}
4982e41f4b71Sopenharmony_ci```
4983e41f4b71Sopenharmony_ci
4984e41f4b71Sopenharmony_ci## Lattice<sup>12+</sup>
4985e41f4b71Sopenharmony_ci
4986e41f4b71Sopenharmony_ciImplements a lattice object, which is used to divide an image by lattice.
4987e41f4b71Sopenharmony_ci
4988e41f4b71Sopenharmony_ci### createImageLattice<sup>12+</sup>
4989e41f4b71Sopenharmony_ci
4990e41f4b71Sopenharmony_cistatic createImageLattice(xDivs: Array\<number>, yDivs: Array\<number>, fXCount: number, fYCount: number, fBounds?: common2D.Rect | null, fRectTypes?: Array\<RectType> | null, fColors?: Array\<common2D.Color> | null): Lattice
4991e41f4b71Sopenharmony_ci
4992e41f4b71Sopenharmony_ciDivides the image into lattices. The lattices on both even columns and even rows are fixed, and they are drawn at their original size if the target is large enough. If the target is too small to hold the fixed lattices, all the fixed lattices are scaled down to fit the target, and the lattices that are not on even columns and even rows are scaled to accommodate the remaining space.
4993e41f4b71Sopenharmony_ci
4994e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
4995e41f4b71Sopenharmony_ci
4996e41f4b71Sopenharmony_ci**Parameters**
4997e41f4b71Sopenharmony_ci
4998e41f4b71Sopenharmony_ci| Name      | Type                                                               | Mandatory| Description                                                                              |
4999e41f4b71Sopenharmony_ci| ------------ | ------------------------------------------------------------------ | ---- | --------------------------------------------------------------------------------- |
5000e41f4b71Sopenharmony_ci| xDivs        | Array\<number>                                                     | Yes  | Array of X coordinates used to divide the image. The value is an integer.                                            |
5001e41f4b71Sopenharmony_ci| yDivs        | Array\<number>                                                     | Yes  | Array of Y coordinates used to divide the image. The value is an integer.                                            |
5002e41f4b71Sopenharmony_ci| fXCount      | number                                                             | Yes  | Size of the array that holds the X coordinates. The value range is [0, 5].                           |
5003e41f4b71Sopenharmony_ci| fYCount      | number                                                             | Yes  | Size of the array that holds the Y coordinates. The value range is [0, 5].                           |
5004e41f4b71Sopenharmony_ci| fBounds      | [common2D.Rect](js-apis-graphics-common2D.md#rect)\|null           | No  | Source bounds to draw. The rectangle parameter must be an integer. The default value is the rectangle size of the original image. If the rectangle parameter is a decimal, the decimal part is discarded and converted into an integer.|
5005e41f4b71Sopenharmony_ci| fRectTypes   | Array\<[RectType](#recttype12)>\|null                              | No  | Array that holds the rectangle types. The default value is null. If this parameter is specified, the array size must be (fXCount + 1) * (fYCount + 1).|
5006e41f4b71Sopenharmony_ci| fColors      | Array\<[common2D.Color](js-apis-graphics-common2D.md#color)>\|null | No  | Array that holds the colors used to fill the lattices. The default value is null. If this parameter is specified, the array size must be (fXCount + 1) * (fYCount + 1).|
5007e41f4b71Sopenharmony_ci
5008e41f4b71Sopenharmony_ci**Return value**
5009e41f4b71Sopenharmony_ci
5010e41f4b71Sopenharmony_ci| Type                      | Description                               |
5011e41f4b71Sopenharmony_ci| ------------------------- | ----------------------------------- |
5012e41f4b71Sopenharmony_ci| [Lattice](#lattice12)     | **Lattice** object obtained.             |
5013e41f4b71Sopenharmony_ci
5014e41f4b71Sopenharmony_ci**Error codes**
5015e41f4b71Sopenharmony_ci
5016e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5017e41f4b71Sopenharmony_ci
5018e41f4b71Sopenharmony_ci| ID| Error Message|
5019e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
5020e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
5021e41f4b71Sopenharmony_ci
5022e41f4b71Sopenharmony_ci**Example**
5023e41f4b71Sopenharmony_ci
5024e41f4b71Sopenharmony_ci```ts
5025e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
5026e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
5027e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
5028e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
5029e41f4b71Sopenharmony_ci    let xDivs : Array<number> = [1, 2, 4];
5030e41f4b71Sopenharmony_ci    let yDivs : Array<number> = [1, 2, 4];
5031e41f4b71Sopenharmony_ci    let lattice = drawing.Lattice.createImageLattice(xDivs, yDivs, 3, 3); // The image is divided into lattices of (3 + 1) x (3 + 1). The blue rectangles in the figure below are fixed lattices.
5032e41f4b71Sopenharmony_ci  }
5033e41f4b71Sopenharmony_ci}
5034e41f4b71Sopenharmony_ci```
5035e41f4b71Sopenharmony_ci![Lattice.png](figures/Lattice.png)
5036e41f4b71Sopenharmony_ci
5037e41f4b71Sopenharmony_ci### createImageLattice<sup>13+</sup>
5038e41f4b71Sopenharmony_ci
5039e41f4b71Sopenharmony_cistatic createImageLattice(xDivs: Array\<number>, yDivs: Array\<number>, fXCount: number, fYCount: number, fBounds?: common2D.Rect | null, fRectTypes?: Array\<RectType> | null, fColors?: Array\<number> | null): Lattice
5040e41f4b71Sopenharmony_ci
5041e41f4b71Sopenharmony_ciDivides the image into lattices. The lattices on both even columns and even rows are fixed, and they are drawn at their original size if the target is large enough. If the target is too small to hold the fixed lattices, all the fixed lattices are scaled down to fit the target, and the lattices that are not on even columns and even rows are scaled to accommodate the remaining space.
5042e41f4b71Sopenharmony_ci
5043e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5044e41f4b71Sopenharmony_ci
5045e41f4b71Sopenharmony_ci**Parameters**
5046e41f4b71Sopenharmony_ci
5047e41f4b71Sopenharmony_ci| Name      | Type                                                               | Mandatory| Description                                                                              |
5048e41f4b71Sopenharmony_ci| ------------ | ------------------------------------------------------------------ | ---- | --------------------------------------------------------------------------------- |
5049e41f4b71Sopenharmony_ci| xDivs        | Array\<number>                                                     | Yes  | Array of X coordinates used to divide the image. The value is an integer.                                            |
5050e41f4b71Sopenharmony_ci| yDivs        | Array\<number>                                                     | Yes  | Array of Y coordinates used to divide the image. The value is an integer.                                            |
5051e41f4b71Sopenharmony_ci| fXCount      | number                                                             | Yes  | Size of the array that holds the X coordinates. The value range is [0, 5].                           |
5052e41f4b71Sopenharmony_ci| fYCount      | number                                                             | Yes  | Size of the array that holds the Y coordinates. The value range is [0, 5].                           |
5053e41f4b71Sopenharmony_ci| fBounds      | [common2D.Rect](js-apis-graphics-common2D.md#rect)\|null           | No  | Source bounds to draw. The rectangle parameter must be an integer. The default value is the rectangle size of the original image. If the rectangle parameter is a decimal, the decimal part is discarded and converted into an integer.|
5054e41f4b71Sopenharmony_ci| fRectTypes   | Array\<[RectType](#recttype12)>\|null                              | No  | Array that holds the rectangle types. The default value is null. If this parameter is specified, the array size must be (fXCount + 1) * (fYCount + 1).|
5055e41f4b71Sopenharmony_ci| fColors      | Array\<number>\|null | No  | Array that holds the colors used to fill the lattices. Each color is represented by a 32-bit unsigned integer in hexadecimal ARGB format. The default value is null. If this parameter is specified, the array size must be (fXCount + 1) * (fYCount + 1).|
5056e41f4b71Sopenharmony_ci
5057e41f4b71Sopenharmony_ci**Return value**
5058e41f4b71Sopenharmony_ci
5059e41f4b71Sopenharmony_ci| Type                      | Description                               |
5060e41f4b71Sopenharmony_ci| ------------------------- | ----------------------------------- |
5061e41f4b71Sopenharmony_ci| [Lattice](#lattice12)     | **Lattice** object obtained.             |
5062e41f4b71Sopenharmony_ci
5063e41f4b71Sopenharmony_ci**Error codes**
5064e41f4b71Sopenharmony_ci
5065e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5066e41f4b71Sopenharmony_ci
5067e41f4b71Sopenharmony_ci| ID| Error Message|
5068e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
5069e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
5070e41f4b71Sopenharmony_ci
5071e41f4b71Sopenharmony_ci**Example**
5072e41f4b71Sopenharmony_ci
5073e41f4b71Sopenharmony_ci```ts
5074e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
5075e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
5076e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
5077e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
5078e41f4b71Sopenharmony_ci    let xDivs : Array<number> = [1, 2, 4];
5079e41f4b71Sopenharmony_ci    let yDivs : Array<number> = [1, 2, 4];
5080e41f4b71Sopenharmony_ci    let colorArray :Array<number>=[0xffffff,0x444444,0x999999,0xffffff,0x444444,0x999999,0xffffff,0x444444,0x999999,0x444444,0x999999,0xffffff,0x444444,0x999999,0xffffff,0x444444];
5081e41f4b71Sopenharmony_ci    let lattice = drawing.Lattice.createImageLattice(xDivs, yDivs, 3, 3,null,null,colorArray);
5082e41f4b71Sopenharmony_ci  }
5083e41f4b71Sopenharmony_ci}
5084e41f4b71Sopenharmony_ci```
5085e41f4b71Sopenharmony_ci
5086e41f4b71Sopenharmony_ci## RectType<sup>12+</sup>
5087e41f4b71Sopenharmony_ci
5088e41f4b71Sopenharmony_ciEnumerates the types of rectangles used to fill the lattices. This enum is used only in [Lattice](#lattice12).
5089e41f4b71Sopenharmony_ci
5090e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5091e41f4b71Sopenharmony_ci
5092e41f4b71Sopenharmony_ci| Name        | Value  | Description                                                            |
5093e41f4b71Sopenharmony_ci| ------------ | ---- | --------------------------------------------------------------- |
5094e41f4b71Sopenharmony_ci| DEFAULT      | 0    | Draws an image into the lattice.                                         |
5095e41f4b71Sopenharmony_ci| TRANSPARENT  | 1    | Sets the lattice to transparent.                                         |
5096e41f4b71Sopenharmony_ci| FIXEDCOLOR   | 2    | Draws the colors in the **fColors** array in [Lattice](#lattice12) into the lattice.      |
5097e41f4b71Sopenharmony_ci
5098e41f4b71Sopenharmony_ci## MaskFilter<sup>12+</sup>
5099e41f4b71Sopenharmony_ci
5100e41f4b71Sopenharmony_ciImplements a mask filter.
5101e41f4b71Sopenharmony_ci
5102e41f4b71Sopenharmony_ci### createBlurMaskFilter<sup>12+</sup>
5103e41f4b71Sopenharmony_ci
5104e41f4b71Sopenharmony_cistatic createBlurMaskFilter(blurType: BlurType, sigma: number): MaskFilter
5105e41f4b71Sopenharmony_ci
5106e41f4b71Sopenharmony_ciCreates a mask filter with a blur effect.
5107e41f4b71Sopenharmony_ci
5108e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5109e41f4b71Sopenharmony_ci
5110e41f4b71Sopenharmony_ci**Parameters**
5111e41f4b71Sopenharmony_ci
5112e41f4b71Sopenharmony_ci| Name    | Type                  | Mandatory| Description                                |
5113e41f4b71Sopenharmony_ci| ---------- | --------------------- | ---- | ----------------------------------- |
5114e41f4b71Sopenharmony_ci| blurType   | [BlurType](#blurtype12) | Yes  | Blur type.                          |
5115e41f4b71Sopenharmony_ci| sigma      | number                | Yes  | Standard deviation of the Gaussian blur to apply. The value must be a floating point number greater than 0.|
5116e41f4b71Sopenharmony_ci
5117e41f4b71Sopenharmony_ci**Return value**
5118e41f4b71Sopenharmony_ci
5119e41f4b71Sopenharmony_ci| Type                     | Description               |
5120e41f4b71Sopenharmony_ci| ------------------------- | ------------------ |
5121e41f4b71Sopenharmony_ci| [MaskFilter](#maskfilter12) | **MaskFilter** object created.|
5122e41f4b71Sopenharmony_ci
5123e41f4b71Sopenharmony_ci**Error codes**
5124e41f4b71Sopenharmony_ci
5125e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5126e41f4b71Sopenharmony_ci
5127e41f4b71Sopenharmony_ci| ID| Error Message|
5128e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
5129e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
5130e41f4b71Sopenharmony_ci
5131e41f4b71Sopenharmony_ci**Example**
5132e41f4b71Sopenharmony_ci
5133e41f4b71Sopenharmony_ci```ts
5134e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
5135e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
5136e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
5137e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
5138e41f4b71Sopenharmony_ci    const canvas = context.canvas;
5139e41f4b71Sopenharmony_ci    let maskFilter = drawing.MaskFilter.createBlurMaskFilter(drawing.BlurType.OUTER, 10);
5140e41f4b71Sopenharmony_ci  }
5141e41f4b71Sopenharmony_ci}
5142e41f4b71Sopenharmony_ci```
5143e41f4b71Sopenharmony_ci
5144e41f4b71Sopenharmony_ci## PathEffect<sup>12+</sup>
5145e41f4b71Sopenharmony_ci
5146e41f4b71Sopenharmony_ciImplements a path effect.
5147e41f4b71Sopenharmony_ci
5148e41f4b71Sopenharmony_ci### createDashPathEffect<sup>12+</sup>
5149e41f4b71Sopenharmony_ci
5150e41f4b71Sopenharmony_cistatic createDashPathEffect(intervals:  Array\<number>, phase: number): PathEffect
5151e41f4b71Sopenharmony_ci
5152e41f4b71Sopenharmony_ciCreates a **PathEffect** object that converts a path into a dotted line.
5153e41f4b71Sopenharmony_ci
5154e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5155e41f4b71Sopenharmony_ci
5156e41f4b71Sopenharmony_ci**Parameters**
5157e41f4b71Sopenharmony_ci
5158e41f4b71Sopenharmony_ci| Name    | Type          | Mandatory   | Description                                              |
5159e41f4b71Sopenharmony_ci| ---------- | ------------- | ------- | -------------------------------------------------- |
5160e41f4b71Sopenharmony_ci| intervals  | Array\<number> | Yes     | Array of ON and OFF lengths of dotted lines. The number of arrays must be an even number and be greater than or equal to 2.|
5161e41f4b71Sopenharmony_ci| phase      | number         | Yes     | Offset used during drawing. The value is a floating point number.                                    |
5162e41f4b71Sopenharmony_ci
5163e41f4b71Sopenharmony_ci**Return value**
5164e41f4b71Sopenharmony_ci
5165e41f4b71Sopenharmony_ci| Type                     | Description                  |
5166e41f4b71Sopenharmony_ci| ------------------------- | --------------------- |
5167e41f4b71Sopenharmony_ci| [PathEffect](#patheffect12) | **PathEffect** object created.|
5168e41f4b71Sopenharmony_ci
5169e41f4b71Sopenharmony_ci**Error codes**
5170e41f4b71Sopenharmony_ci
5171e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5172e41f4b71Sopenharmony_ci
5173e41f4b71Sopenharmony_ci| ID| Error Message|
5174e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
5175e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
5176e41f4b71Sopenharmony_ci
5177e41f4b71Sopenharmony_ci**Example**
5178e41f4b71Sopenharmony_ci
5179e41f4b71Sopenharmony_ci```ts
5180e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
5181e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
5182e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
5183e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
5184e41f4b71Sopenharmony_ci    const canvas = context.canvas;
5185e41f4b71Sopenharmony_ci    let intervals = [10, 5];
5186e41f4b71Sopenharmony_ci    let effect = drawing.PathEffect.createDashPathEffect(intervals, 5);
5187e41f4b71Sopenharmony_ci  }
5188e41f4b71Sopenharmony_ci}
5189e41f4b71Sopenharmony_ci```
5190e41f4b71Sopenharmony_ci
5191e41f4b71Sopenharmony_ci### createCornerPathEffect<sup>12+</sup>
5192e41f4b71Sopenharmony_ci
5193e41f4b71Sopenharmony_cistatic createCornerPathEffect(radius: number): PathEffect
5194e41f4b71Sopenharmony_ci
5195e41f4b71Sopenharmony_ciCreates a path effect that transforms the sharp angle between line segments into a rounded corner with the specified radius.
5196e41f4b71Sopenharmony_ci
5197e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5198e41f4b71Sopenharmony_ci
5199e41f4b71Sopenharmony_ci**Parameters**
5200e41f4b71Sopenharmony_ci
5201e41f4b71Sopenharmony_ci| Name    | Type          | Mandatory   | Description                                              |
5202e41f4b71Sopenharmony_ci| ---------- | ------------- | ------- | -------------------------------------------------- |
5203e41f4b71Sopenharmony_ci| radius     | number        | Yes     | Radius of the rounded corner. The value must be greater than 0. The value is a floating point number.               |
5204e41f4b71Sopenharmony_ci
5205e41f4b71Sopenharmony_ci**Return value**
5206e41f4b71Sopenharmony_ci
5207e41f4b71Sopenharmony_ci| Type                     | Description                  |
5208e41f4b71Sopenharmony_ci| ------------------------- | --------------------- |
5209e41f4b71Sopenharmony_ci| [PathEffect](#patheffect12) | **PathEffect** object created.|
5210e41f4b71Sopenharmony_ci
5211e41f4b71Sopenharmony_ci**Error codes**
5212e41f4b71Sopenharmony_ci
5213e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5214e41f4b71Sopenharmony_ci
5215e41f4b71Sopenharmony_ci| ID| Error Message|
5216e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
5217e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
5218e41f4b71Sopenharmony_ci
5219e41f4b71Sopenharmony_ci**Example**
5220e41f4b71Sopenharmony_ci
5221e41f4b71Sopenharmony_ci```ts
5222e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
5223e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
5224e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
5225e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
5226e41f4b71Sopenharmony_ci    const canvas = context.canvas;
5227e41f4b71Sopenharmony_ci    let effect = drawing.PathEffect.createCornerPathEffect(30);
5228e41f4b71Sopenharmony_ci  }
5229e41f4b71Sopenharmony_ci}
5230e41f4b71Sopenharmony_ci```
5231e41f4b71Sopenharmony_ci
5232e41f4b71Sopenharmony_ci## ShadowLayer<sup>12+</sup>
5233e41f4b71Sopenharmony_ci
5234e41f4b71Sopenharmony_ciImplements a shadow layer.
5235e41f4b71Sopenharmony_ci
5236e41f4b71Sopenharmony_ci### create<sup>12+</sup>
5237e41f4b71Sopenharmony_ci
5238e41f4b71Sopenharmony_cistatic create(blurRadius: number, x: number, y: number, color: common2D.Color): ShadowLayer
5239e41f4b71Sopenharmony_ci
5240e41f4b71Sopenharmony_ciCreates a **ShadowLayer** object.
5241e41f4b71Sopenharmony_ci
5242e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5243e41f4b71Sopenharmony_ci
5244e41f4b71Sopenharmony_ci**Parameters**
5245e41f4b71Sopenharmony_ci
5246e41f4b71Sopenharmony_ci| Name    | Type     | Mandatory| Description                                |
5247e41f4b71Sopenharmony_ci| ---------- | -------- | ---- | ----------------------------------- |
5248e41f4b71Sopenharmony_ci| blurRadius  | number   | Yes  | Radius of the shadow layer. The value must be a floating point number greater than 0.    |
5249e41f4b71Sopenharmony_ci| x           | number   | Yes  | Offset on the X axis. The value is a floating point number.       |
5250e41f4b71Sopenharmony_ci| y           | number   | Yes  | Offset on the Y axis. The value is a floating point number.       |
5251e41f4b71Sopenharmony_ci| color       | [common2D.Color](js-apis-graphics-common2D.md#color) | Yes  | Color in ARGB format. Each color channel is an integer ranging from 0 to 255.|
5252e41f4b71Sopenharmony_ci
5253e41f4b71Sopenharmony_ci**Return value**
5254e41f4b71Sopenharmony_ci
5255e41f4b71Sopenharmony_ci| Type                       | Description                 |
5256e41f4b71Sopenharmony_ci| --------------------------- | -------------------- |
5257e41f4b71Sopenharmony_ci| [ShadowLayer](#shadowlayer12) | **ShadowLayer** object created.|
5258e41f4b71Sopenharmony_ci
5259e41f4b71Sopenharmony_ci**Error codes**
5260e41f4b71Sopenharmony_ci
5261e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5262e41f4b71Sopenharmony_ci
5263e41f4b71Sopenharmony_ci| ID| Error Message|
5264e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
5265e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
5266e41f4b71Sopenharmony_ci
5267e41f4b71Sopenharmony_ci**Example**
5268e41f4b71Sopenharmony_ci
5269e41f4b71Sopenharmony_ci```ts
5270e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
5271e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
5272e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
5273e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
5274e41f4b71Sopenharmony_ci    const canvas = context.canvas;
5275e41f4b71Sopenharmony_ci    let color : common2D.Color = {alpha: 0xFF, red: 0x00, green: 0xFF, blue: 0x00};
5276e41f4b71Sopenharmony_ci    let shadowLayer = drawing.ShadowLayer.create(3, -3, 3, color);
5277e41f4b71Sopenharmony_ci  }
5278e41f4b71Sopenharmony_ci}
5279e41f4b71Sopenharmony_ci```
5280e41f4b71Sopenharmony_ci
5281e41f4b71Sopenharmony_ci## Pen
5282e41f4b71Sopenharmony_ci
5283e41f4b71Sopenharmony_ciDefines a pen, which is used to describe the style and color to outline a shape.
5284e41f4b71Sopenharmony_ci
5285e41f4b71Sopenharmony_ci### constructor<sup>12+</sup>
5286e41f4b71Sopenharmony_ci
5287e41f4b71Sopenharmony_ciconstructor()
5288e41f4b71Sopenharmony_ci
5289e41f4b71Sopenharmony_ciA constructor used to create a **Pen** object.
5290e41f4b71Sopenharmony_ci
5291e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5292e41f4b71Sopenharmony_ci
5293e41f4b71Sopenharmony_ci**Example**
5294e41f4b71Sopenharmony_ci
5295e41f4b71Sopenharmony_ci```ts
5296e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
5297e41f4b71Sopenharmony_ci
5298e41f4b71Sopenharmony_ciconst pen = new drawing.Pen();
5299e41f4b71Sopenharmony_ci```
5300e41f4b71Sopenharmony_ci
5301e41f4b71Sopenharmony_ci### constructor<sup>12+</sup>
5302e41f4b71Sopenharmony_ci
5303e41f4b71Sopenharmony_ciconstructor(pen: Pen)
5304e41f4b71Sopenharmony_ci
5305e41f4b71Sopenharmony_ciCopies a **Pen** object to create a new one.
5306e41f4b71Sopenharmony_ci
5307e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5308e41f4b71Sopenharmony_ci
5309e41f4b71Sopenharmony_ci**Parameters**
5310e41f4b71Sopenharmony_ci
5311e41f4b71Sopenharmony_ci| Name| Type       | Mandatory| Description             |
5312e41f4b71Sopenharmony_ci| ------| ----------- | ---- | ---------------- |
5313e41f4b71Sopenharmony_ci| pen     | [Pen](#pen) | Yes  | **Pen** object to copy.|
5314e41f4b71Sopenharmony_ci
5315e41f4b71Sopenharmony_ci**Error codes**
5316e41f4b71Sopenharmony_ci
5317e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5318e41f4b71Sopenharmony_ci
5319e41f4b71Sopenharmony_ci| ID| Error Message|
5320e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
5321e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
5322e41f4b71Sopenharmony_ci
5323e41f4b71Sopenharmony_ci**Example**
5324e41f4b71Sopenharmony_ci
5325e41f4b71Sopenharmony_ci```ts
5326e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
5327e41f4b71Sopenharmony_ci
5328e41f4b71Sopenharmony_ciconst pen = new drawing.Pen();
5329e41f4b71Sopenharmony_ciconst penColor: common2D.Color = { alpha: 255, red: 0, green: 255, blue: 0 };
5330e41f4b71Sopenharmony_cipen.setColor(penColor);
5331e41f4b71Sopenharmony_cipen.setStrokeWidth(10);
5332e41f4b71Sopenharmony_ciconst newPen = new drawing.Pen(pen);
5333e41f4b71Sopenharmony_ci```
5334e41f4b71Sopenharmony_ci
5335e41f4b71Sopenharmony_ci### setMiterLimit<sup>12+</sup>
5336e41f4b71Sopenharmony_ci
5337e41f4b71Sopenharmony_cisetMiterLimit(miter: number): void
5338e41f4b71Sopenharmony_ci
5339e41f4b71Sopenharmony_ciSets the maximum ratio allowed between the sharp corner length of a polyline and its line width. When drawing a polyline with the pen, if [JoinStyle](#joinstyle12) is set to **MITER_JOIN** and this maximum ratio is exceeded, the corner will be displayed as beveled instead of mitered.
5340e41f4b71Sopenharmony_ci
5341e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5342e41f4b71Sopenharmony_ci
5343e41f4b71Sopenharmony_ci**Parameters**
5344e41f4b71Sopenharmony_ci
5345e41f4b71Sopenharmony_ci| Name| Type   | Mandatory| Description             |
5346e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ---------------- |
5347e41f4b71Sopenharmony_ci| miter  | number | Yes  | Maximum ratio of the sharp corner length of the polyline to the line width. A negative number is processed as 4.0 during drawing. Non-negative numbers take effect normally. The value is a floating point number.|
5348e41f4b71Sopenharmony_ci
5349e41f4b71Sopenharmony_ci**Error codes**
5350e41f4b71Sopenharmony_ci
5351e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5352e41f4b71Sopenharmony_ci
5353e41f4b71Sopenharmony_ci| ID| Error Message|
5354e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
5355e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
5356e41f4b71Sopenharmony_ci
5357e41f4b71Sopenharmony_ci**Example**
5358e41f4b71Sopenharmony_ci
5359e41f4b71Sopenharmony_ci```ts
5360e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
5361e41f4b71Sopenharmony_ci
5362e41f4b71Sopenharmony_ciconst pen = new drawing.Pen();
5363e41f4b71Sopenharmony_cipen.setMiterLimit(5);
5364e41f4b71Sopenharmony_ci```
5365e41f4b71Sopenharmony_ci
5366e41f4b71Sopenharmony_ci### getMiterLimit<sup>12+</sup>
5367e41f4b71Sopenharmony_ci
5368e41f4b71Sopenharmony_cigetMiterLimit(): number
5369e41f4b71Sopenharmony_ci
5370e41f4b71Sopenharmony_ciObtains the maximum ratio allowed between the sharp corner length of a polyline and its line width.
5371e41f4b71Sopenharmony_ci
5372e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5373e41f4b71Sopenharmony_ci
5374e41f4b71Sopenharmony_ci**Return value**
5375e41f4b71Sopenharmony_ci
5376e41f4b71Sopenharmony_ci| Type  | Description                |
5377e41f4b71Sopenharmony_ci| -------| -------------------- |
5378e41f4b71Sopenharmony_ci| number | Maximum ratio obtained.|
5379e41f4b71Sopenharmony_ci
5380e41f4b71Sopenharmony_ci**Example**
5381e41f4b71Sopenharmony_ci
5382e41f4b71Sopenharmony_ci```ts
5383e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
5384e41f4b71Sopenharmony_ci
5385e41f4b71Sopenharmony_ciconst pen = new drawing.Pen();
5386e41f4b71Sopenharmony_cilet miter = pen.getMiterLimit();
5387e41f4b71Sopenharmony_ci```
5388e41f4b71Sopenharmony_ci
5389e41f4b71Sopenharmony_ci### setImageFilter<sup>12+</sup>
5390e41f4b71Sopenharmony_ci
5391e41f4b71Sopenharmony_cisetImageFilter(filter: ImageFilter | null): void
5392e41f4b71Sopenharmony_ci
5393e41f4b71Sopenharmony_ciSets an image filter for this pen.
5394e41f4b71Sopenharmony_ci
5395e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5396e41f4b71Sopenharmony_ci
5397e41f4b71Sopenharmony_ci**Parameters**
5398e41f4b71Sopenharmony_ci
5399e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                   |
5400e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------- |
5401e41f4b71Sopenharmony_ci| filter    | [ImageFilter](#imagefilter12) \| null | Yes  |  Image filter. If null is passed in, the image filter effect of the pen will be cleared.|
5402e41f4b71Sopenharmony_ci
5403e41f4b71Sopenharmony_ci**Error codes**
5404e41f4b71Sopenharmony_ci
5405e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5406e41f4b71Sopenharmony_ci
5407e41f4b71Sopenharmony_ci| ID| Error Message|
5408e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
5409e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types. |
5410e41f4b71Sopenharmony_ci
5411e41f4b71Sopenharmony_ci**Example**
5412e41f4b71Sopenharmony_ci
5413e41f4b71Sopenharmony_ci```ts
5414e41f4b71Sopenharmony_ciimport {drawing} from '@kit.ArkGraphics2D';
5415e41f4b71Sopenharmony_cilet colorfilter = drawing.ColorFilter.createSRGBGammaToLinear();
5416e41f4b71Sopenharmony_cilet imgFilter = drawing.ImageFilter.createFromColorFilter(colorfilter);
5417e41f4b71Sopenharmony_cilet pen = new drawing.Pen();
5418e41f4b71Sopenharmony_cipen.setImageFilter(imgFilter);
5419e41f4b71Sopenharmony_cipen.setImageFilter(null);
5420e41f4b71Sopenharmony_ci```
5421e41f4b71Sopenharmony_ci
5422e41f4b71Sopenharmony_ci### getColorFilter<sup>12+</sup>
5423e41f4b71Sopenharmony_ci
5424e41f4b71Sopenharmony_cigetColorFilter(): ColorFilter
5425e41f4b71Sopenharmony_ci
5426e41f4b71Sopenharmony_ciObtains the color filter of this pen.
5427e41f4b71Sopenharmony_ci
5428e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5429e41f4b71Sopenharmony_ci
5430e41f4b71Sopenharmony_ci**Return value**
5431e41f4b71Sopenharmony_ci
5432e41f4b71Sopenharmony_ci| Type                       | Description              |
5433e41f4b71Sopenharmony_ci| --------------------------- | ------------------ |
5434e41f4b71Sopenharmony_ci| [ColorFilter](#colorfilter) | Color filter.|
5435e41f4b71Sopenharmony_ci
5436e41f4b71Sopenharmony_ci**Example**
5437e41f4b71Sopenharmony_ci
5438e41f4b71Sopenharmony_ci```ts 
5439e41f4b71Sopenharmony_ciimport {drawing} from '@kit.ArkGraphics2D';
5440e41f4b71Sopenharmony_cilet pen = new drawing.Pen();
5441e41f4b71Sopenharmony_cilet colorfilter = drawing.ColorFilter.createLumaColorFilter();
5442e41f4b71Sopenharmony_cipen.setColorFilter(colorfilter);
5443e41f4b71Sopenharmony_cilet filter = pen.getColorFilter();
5444e41f4b71Sopenharmony_ci```
5445e41f4b71Sopenharmony_ci
5446e41f4b71Sopenharmony_ci### setColor
5447e41f4b71Sopenharmony_ci
5448e41f4b71Sopenharmony_cisetColor(color: common2D.Color) : void
5449e41f4b71Sopenharmony_ci
5450e41f4b71Sopenharmony_ciSets a color for this pen.
5451e41f4b71Sopenharmony_ci
5452e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5453e41f4b71Sopenharmony_ci
5454e41f4b71Sopenharmony_ci**Parameters**
5455e41f4b71Sopenharmony_ci
5456e41f4b71Sopenharmony_ci| Name| Type                                                | Mandatory| Description            |
5457e41f4b71Sopenharmony_ci| ------ | ---------------------------------------------------- | ---- | ---------------- |
5458e41f4b71Sopenharmony_ci| color  | [common2D.Color](js-apis-graphics-common2D.md#color) | Yes  | Color in ARGB format. Each color channel is an integer ranging from 0 to 255.|
5459e41f4b71Sopenharmony_ci
5460e41f4b71Sopenharmony_ci**Error codes**
5461e41f4b71Sopenharmony_ci
5462e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5463e41f4b71Sopenharmony_ci
5464e41f4b71Sopenharmony_ci| ID| Error Message|
5465e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
5466e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
5467e41f4b71Sopenharmony_ci
5468e41f4b71Sopenharmony_ci**Example**
5469e41f4b71Sopenharmony_ci
5470e41f4b71Sopenharmony_ci```ts
5471e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
5472e41f4b71Sopenharmony_ciconst color : common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
5473e41f4b71Sopenharmony_ciconst pen = new drawing.Pen();
5474e41f4b71Sopenharmony_cipen.setColor(color);
5475e41f4b71Sopenharmony_ci```
5476e41f4b71Sopenharmony_ci
5477e41f4b71Sopenharmony_ci### setColor<sup>12+</sup>
5478e41f4b71Sopenharmony_ci
5479e41f4b71Sopenharmony_cisetColor(alpha: number, red: number, green: number, blue: number): void
5480e41f4b71Sopenharmony_ci
5481e41f4b71Sopenharmony_ciSets a color for this pen. This API provides better performance than [setColor](#setcolor) and is recommended.
5482e41f4b71Sopenharmony_ci
5483e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5484e41f4b71Sopenharmony_ci
5485e41f4b71Sopenharmony_ci**Parameters**
5486e41f4b71Sopenharmony_ci
5487e41f4b71Sopenharmony_ci| Name| Type   | Mandatory| Description                                               |
5488e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------------------------------------------- |
5489e41f4b71Sopenharmony_ci| alpha  | number | Yes  | Alpha channel value of the color in ARGB format. The value is an integer ranging from 0 to 255. Any passed-in floating point number is rounded down.|
5490e41f4b71Sopenharmony_ci| red    | number | Yes  | Red channel value of the color in ARGB format. The value is an integer ranging from 0 to 255. Any passed-in floating point number is rounded down.  |
5491e41f4b71Sopenharmony_ci| green  | number | Yes  | Green channel value of the color in ARGB format. The value is an integer ranging from 0 to 255. Any passed-in floating point number is rounded down.  |
5492e41f4b71Sopenharmony_ci| blue   | number | Yes  | Blue channel value of the color in ARGB format. The value is an integer ranging from 0 to 255. Any passed-in floating point number is rounded down.  |
5493e41f4b71Sopenharmony_ci
5494e41f4b71Sopenharmony_ci**Error codes**
5495e41f4b71Sopenharmony_ci
5496e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5497e41f4b71Sopenharmony_ci
5498e41f4b71Sopenharmony_ci| ID| Error Message|
5499e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
5500e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
5501e41f4b71Sopenharmony_ci
5502e41f4b71Sopenharmony_ci**Example**
5503e41f4b71Sopenharmony_ci
5504e41f4b71Sopenharmony_ci```ts
5505e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
5506e41f4b71Sopenharmony_ciconst pen = new drawing.Pen();
5507e41f4b71Sopenharmony_cipen.setColor(255, 255, 0, 0);
5508e41f4b71Sopenharmony_ci```
5509e41f4b71Sopenharmony_ci
5510e41f4b71Sopenharmony_ci### getColor<sup>12+</sup>
5511e41f4b71Sopenharmony_ci
5512e41f4b71Sopenharmony_cigetColor(): common2D.Color
5513e41f4b71Sopenharmony_ci
5514e41f4b71Sopenharmony_ciObtains the color of this pen.
5515e41f4b71Sopenharmony_ci
5516e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5517e41f4b71Sopenharmony_ci
5518e41f4b71Sopenharmony_ci**Return value**
5519e41f4b71Sopenharmony_ci
5520e41f4b71Sopenharmony_ci| Type          | Description           |
5521e41f4b71Sopenharmony_ci| -------------- | -------------- |
5522e41f4b71Sopenharmony_ci| common2D.Color | Color of the pen.|
5523e41f4b71Sopenharmony_ci
5524e41f4b71Sopenharmony_ci**Example**
5525e41f4b71Sopenharmony_ci
5526e41f4b71Sopenharmony_ci```ts
5527e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
5528e41f4b71Sopenharmony_ci
5529e41f4b71Sopenharmony_ciconst color : common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
5530e41f4b71Sopenharmony_ciconst pen = new drawing.Pen();
5531e41f4b71Sopenharmony_cipen.setColor(color);
5532e41f4b71Sopenharmony_cilet colorGet = pen.getColor();
5533e41f4b71Sopenharmony_ci```
5534e41f4b71Sopenharmony_ci
5535e41f4b71Sopenharmony_ci### getHexColor<sup>13+</sup>
5536e41f4b71Sopenharmony_ci
5537e41f4b71Sopenharmony_cigetHexColor(): number
5538e41f4b71Sopenharmony_ci
5539e41f4b71Sopenharmony_ciObtains the color of this pen.
5540e41f4b71Sopenharmony_ci
5541e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5542e41f4b71Sopenharmony_ci
5543e41f4b71Sopenharmony_ci**Return value**
5544e41f4b71Sopenharmony_ci
5545e41f4b71Sopenharmony_ci| Type          | Description           |
5546e41f4b71Sopenharmony_ci| -------------- | -------------- |
5547e41f4b71Sopenharmony_ci| number | Color, represented as a 32-bit unsigned integer in hexadecimal ARGB format.|
5548e41f4b71Sopenharmony_ci
5549e41f4b71Sopenharmony_ci**Example**
5550e41f4b71Sopenharmony_ci
5551e41f4b71Sopenharmony_ci```ts
5552e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
5553e41f4b71Sopenharmony_ci
5554e41f4b71Sopenharmony_cilet color : common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
5555e41f4b71Sopenharmony_cilet pen = new drawing.Pen();
5556e41f4b71Sopenharmony_cipen.setColor(color);
5557e41f4b71Sopenharmony_cilet hex_color: number = pen.getHexColor();
5558e41f4b71Sopenharmony_ciconsole.info('getHexColor: ', hex_color.toString(16));
5559e41f4b71Sopenharmony_ci```
5560e41f4b71Sopenharmony_ci
5561e41f4b71Sopenharmony_ci### setStrokeWidth
5562e41f4b71Sopenharmony_ci
5563e41f4b71Sopenharmony_cisetStrokeWidth(width: number) : void
5564e41f4b71Sopenharmony_ci
5565e41f4b71Sopenharmony_ciSets the stroke width for this pen. The value **0** is treated as an unusually thin width. During drawing, the width of 0 is always drawn as 1 pixel wide, regardless of any scaling applied to the canvas. Negative values are also regarded as the value **0** during the drawing process.
5566e41f4b71Sopenharmony_ci
5567e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5568e41f4b71Sopenharmony_ci
5569e41f4b71Sopenharmony_ci**Parameters**
5570e41f4b71Sopenharmony_ci
5571e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description            |
5572e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ---------------- |
5573e41f4b71Sopenharmony_ci| width  | number | Yes  | Stroke width. The value is a floating point number.|
5574e41f4b71Sopenharmony_ci
5575e41f4b71Sopenharmony_ci**Error codes**
5576e41f4b71Sopenharmony_ci
5577e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5578e41f4b71Sopenharmony_ci
5579e41f4b71Sopenharmony_ci| ID| Error Message|
5580e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
5581e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
5582e41f4b71Sopenharmony_ci
5583e41f4b71Sopenharmony_ci**Example**
5584e41f4b71Sopenharmony_ci
5585e41f4b71Sopenharmony_ci```ts
5586e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
5587e41f4b71Sopenharmony_ciconst pen = new drawing.Pen();
5588e41f4b71Sopenharmony_cipen.setStrokeWidth(5);
5589e41f4b71Sopenharmony_ci```
5590e41f4b71Sopenharmony_ci
5591e41f4b71Sopenharmony_ci### getWidth<sup>12+</sup>
5592e41f4b71Sopenharmony_ci
5593e41f4b71Sopenharmony_cigetWidth(): number
5594e41f4b71Sopenharmony_ci
5595e41f4b71Sopenharmony_ciObtains the stroke width of this pen. The width describes the thickness of the outline of a shape.
5596e41f4b71Sopenharmony_ci
5597e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5598e41f4b71Sopenharmony_ci
5599e41f4b71Sopenharmony_ci**Return value**
5600e41f4b71Sopenharmony_ci
5601e41f4b71Sopenharmony_ci| Type  | Description           |
5602e41f4b71Sopenharmony_ci| ------ | -------------- |
5603e41f4b71Sopenharmony_ci| number | Stroke width of the pen.|
5604e41f4b71Sopenharmony_ci
5605e41f4b71Sopenharmony_ci**Example**
5606e41f4b71Sopenharmony_ci
5607e41f4b71Sopenharmony_ci```ts
5608e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
5609e41f4b71Sopenharmony_ci
5610e41f4b71Sopenharmony_ciconst pen = new drawing.Pen();
5611e41f4b71Sopenharmony_cilet width = pen.getWidth();
5612e41f4b71Sopenharmony_ci```
5613e41f4b71Sopenharmony_ci
5614e41f4b71Sopenharmony_ci### setAntiAlias
5615e41f4b71Sopenharmony_ci
5616e41f4b71Sopenharmony_cisetAntiAlias(aa: boolean) : void
5617e41f4b71Sopenharmony_ci
5618e41f4b71Sopenharmony_ciEnables anti-aliasing for this pen. Anti-aliasing makes the edges of the content smoother.
5619e41f4b71Sopenharmony_ci
5620e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5621e41f4b71Sopenharmony_ci
5622e41f4b71Sopenharmony_ci**Parameters**
5623e41f4b71Sopenharmony_ci
5624e41f4b71Sopenharmony_ci| Name| Type   | Mandatory| Description                                             |
5625e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------------------- |
5626e41f4b71Sopenharmony_ci| aa     | boolean | Yes  | Whether to enable anti-aliasing. The value **true** means to enable anti-aliasing, and **false** means the opposite.|
5627e41f4b71Sopenharmony_ci
5628e41f4b71Sopenharmony_ci**Error codes**
5629e41f4b71Sopenharmony_ci
5630e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5631e41f4b71Sopenharmony_ci
5632e41f4b71Sopenharmony_ci| ID| Error Message|
5633e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
5634e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
5635e41f4b71Sopenharmony_ci
5636e41f4b71Sopenharmony_ci**Example**
5637e41f4b71Sopenharmony_ci
5638e41f4b71Sopenharmony_ci```ts
5639e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
5640e41f4b71Sopenharmony_ciconst pen = new drawing.Pen();
5641e41f4b71Sopenharmony_cipen.setAntiAlias(true);
5642e41f4b71Sopenharmony_ci```
5643e41f4b71Sopenharmony_ci
5644e41f4b71Sopenharmony_ci### isAntiAlias<sup>12+</sup>
5645e41f4b71Sopenharmony_ci
5646e41f4b71Sopenharmony_ciisAntiAlias(): boolean
5647e41f4b71Sopenharmony_ci
5648e41f4b71Sopenharmony_ciChecks whether anti-aliasing is enabled for this pen.
5649e41f4b71Sopenharmony_ci
5650e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5651e41f4b71Sopenharmony_ci
5652e41f4b71Sopenharmony_ci**Return value**
5653e41f4b71Sopenharmony_ci
5654e41f4b71Sopenharmony_ci| Type   | Description                      |
5655e41f4b71Sopenharmony_ci| ------- | ------------------------- |
5656e41f4b71Sopenharmony_ci| boolean | Result indicating whether anti-aliasing is enabled. The value **true** means that anti-aliasing is enabled, and **false** means the opposite.|
5657e41f4b71Sopenharmony_ci
5658e41f4b71Sopenharmony_ci**Example**
5659e41f4b71Sopenharmony_ci
5660e41f4b71Sopenharmony_ci```ts
5661e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
5662e41f4b71Sopenharmony_ci
5663e41f4b71Sopenharmony_ciconst pen = new drawing.Pen();
5664e41f4b71Sopenharmony_cilet isAntiAlias = pen.isAntiAlias();
5665e41f4b71Sopenharmony_ci```
5666e41f4b71Sopenharmony_ci
5667e41f4b71Sopenharmony_ci### setAlpha
5668e41f4b71Sopenharmony_ci
5669e41f4b71Sopenharmony_cisetAlpha(alpha: number) : void
5670e41f4b71Sopenharmony_ci
5671e41f4b71Sopenharmony_ciSets an alpha value for this pen.
5672e41f4b71Sopenharmony_ci
5673e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5674e41f4b71Sopenharmony_ci
5675e41f4b71Sopenharmony_ci**Parameters**
5676e41f4b71Sopenharmony_ci
5677e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                    |
5678e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ---------------------------------------- |
5679e41f4b71Sopenharmony_ci| alpha  | number | Yes  | Alpha value. The value is an integer in the range [0, 255]. If a floating point number is passed in, the value is rounded down.|
5680e41f4b71Sopenharmony_ci
5681e41f4b71Sopenharmony_ci**Error codes**
5682e41f4b71Sopenharmony_ci
5683e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5684e41f4b71Sopenharmony_ci
5685e41f4b71Sopenharmony_ci| ID| Error Message|
5686e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
5687e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
5688e41f4b71Sopenharmony_ci
5689e41f4b71Sopenharmony_ci**Example**
5690e41f4b71Sopenharmony_ci
5691e41f4b71Sopenharmony_ci```ts
5692e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
5693e41f4b71Sopenharmony_ciconst pen = new drawing.Pen();
5694e41f4b71Sopenharmony_cipen.setAlpha(128);
5695e41f4b71Sopenharmony_ci```
5696e41f4b71Sopenharmony_ci
5697e41f4b71Sopenharmony_ci### getAlpha<sup>12+</sup>
5698e41f4b71Sopenharmony_ci
5699e41f4b71Sopenharmony_cigetAlpha(): number
5700e41f4b71Sopenharmony_ci
5701e41f4b71Sopenharmony_ciObtains the alpha value of this pen.
5702e41f4b71Sopenharmony_ci
5703e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5704e41f4b71Sopenharmony_ci
5705e41f4b71Sopenharmony_ci**Return value**
5706e41f4b71Sopenharmony_ci
5707e41f4b71Sopenharmony_ci| Type  | Description             |
5708e41f4b71Sopenharmony_ci| ------ | ---------------- |
5709e41f4b71Sopenharmony_ci| number | Alpha value of the pen. The return value is an integer ranging from 0 to 255.|
5710e41f4b71Sopenharmony_ci
5711e41f4b71Sopenharmony_ci**Example**
5712e41f4b71Sopenharmony_ci
5713e41f4b71Sopenharmony_ci```ts
5714e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
5715e41f4b71Sopenharmony_ci
5716e41f4b71Sopenharmony_ciconst pen = new drawing.Pen();
5717e41f4b71Sopenharmony_cilet alpha = pen.getAlpha();
5718e41f4b71Sopenharmony_ci```
5719e41f4b71Sopenharmony_ci
5720e41f4b71Sopenharmony_ci### setColorFilter
5721e41f4b71Sopenharmony_ci
5722e41f4b71Sopenharmony_cisetColorFilter(filter: ColorFilter) : void
5723e41f4b71Sopenharmony_ci
5724e41f4b71Sopenharmony_ciSets a color filter for this pen.
5725e41f4b71Sopenharmony_ci
5726e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5727e41f4b71Sopenharmony_ci
5728e41f4b71Sopenharmony_ci**Parameters**
5729e41f4b71Sopenharmony_ci
5730e41f4b71Sopenharmony_ci| Name| Type                       | Mandatory| Description        |
5731e41f4b71Sopenharmony_ci| ------ | --------------------------- | ---- | ------------ |
5732e41f4b71Sopenharmony_ci| filter | [ColorFilter](#colorfilter) | Yes  | Color filter. If null is passed in, the color filter is cleared.|
5733e41f4b71Sopenharmony_ci
5734e41f4b71Sopenharmony_ci**Error codes**
5735e41f4b71Sopenharmony_ci
5736e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5737e41f4b71Sopenharmony_ci
5738e41f4b71Sopenharmony_ci| ID| Error Message|
5739e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
5740e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
5741e41f4b71Sopenharmony_ci
5742e41f4b71Sopenharmony_ci**Example**
5743e41f4b71Sopenharmony_ci
5744e41f4b71Sopenharmony_ci```ts
5745e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
5746e41f4b71Sopenharmony_ciconst pen = new drawing.Pen();
5747e41f4b71Sopenharmony_cilet colorFilter = drawing.ColorFilter.createLinearToSRGBGamma();
5748e41f4b71Sopenharmony_cipen.setColorFilter(colorFilter);
5749e41f4b71Sopenharmony_ci```
5750e41f4b71Sopenharmony_ci
5751e41f4b71Sopenharmony_ci### setMaskFilter<sup>12+</sup>
5752e41f4b71Sopenharmony_ci
5753e41f4b71Sopenharmony_cisetMaskFilter(filter: MaskFilter): void
5754e41f4b71Sopenharmony_ci
5755e41f4b71Sopenharmony_ciAdds a mask filter for this pen.
5756e41f4b71Sopenharmony_ci
5757e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5758e41f4b71Sopenharmony_ci
5759e41f4b71Sopenharmony_ci**Parameters**
5760e41f4b71Sopenharmony_ci
5761e41f4b71Sopenharmony_ci| Name| Type                      | Mandatory| Description     |
5762e41f4b71Sopenharmony_ci| ------ | ------------------------- | ---- | --------- |
5763e41f4b71Sopenharmony_ci| filter | [MaskFilter](#maskfilter12) | Yes  | Mask filter. If null is passed in, the mask filter is cleared.|
5764e41f4b71Sopenharmony_ci
5765e41f4b71Sopenharmony_ci**Error codes**
5766e41f4b71Sopenharmony_ci
5767e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5768e41f4b71Sopenharmony_ci
5769e41f4b71Sopenharmony_ci| ID| Error Message|
5770e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
5771e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
5772e41f4b71Sopenharmony_ci
5773e41f4b71Sopenharmony_ci**Example**
5774e41f4b71Sopenharmony_ci
5775e41f4b71Sopenharmony_ci```ts
5776e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
5777e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
5778e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
5779e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
5780e41f4b71Sopenharmony_ci    const canvas = context.canvas;
5781e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
5782e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
5783e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
5784e41f4b71Sopenharmony_ci    let maskFilter = drawing.MaskFilter.createBlurMaskFilter(drawing.BlurType.OUTER, 10);
5785e41f4b71Sopenharmony_ci    pen.setMaskFilter(maskFilter);
5786e41f4b71Sopenharmony_ci  }
5787e41f4b71Sopenharmony_ci}
5788e41f4b71Sopenharmony_ci```
5789e41f4b71Sopenharmony_ci
5790e41f4b71Sopenharmony_ci### setPathEffect<sup>12+</sup>
5791e41f4b71Sopenharmony_ci
5792e41f4b71Sopenharmony_cisetPathEffect(effect: PathEffect): void
5793e41f4b71Sopenharmony_ci
5794e41f4b71Sopenharmony_ciSets the path effect for this pen.
5795e41f4b71Sopenharmony_ci
5796e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5797e41f4b71Sopenharmony_ci
5798e41f4b71Sopenharmony_ci**Parameters**
5799e41f4b71Sopenharmony_ci
5800e41f4b71Sopenharmony_ci| Name | Type                      | Mandatory| Description        |
5801e41f4b71Sopenharmony_ci| ------- | ------------------------- | ---- | ------------ |
5802e41f4b71Sopenharmony_ci| effect  | [PathEffect](#patheffect12) | Yes  | Path effect. If null is passed in, the path filter is cleared.|
5803e41f4b71Sopenharmony_ci
5804e41f4b71Sopenharmony_ci**Error codes**
5805e41f4b71Sopenharmony_ci
5806e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5807e41f4b71Sopenharmony_ci
5808e41f4b71Sopenharmony_ci| ID| Error Message|
5809e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
5810e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
5811e41f4b71Sopenharmony_ci
5812e41f4b71Sopenharmony_ci**Example**
5813e41f4b71Sopenharmony_ci
5814e41f4b71Sopenharmony_ci```ts
5815e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
5816e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
5817e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
5818e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
5819e41f4b71Sopenharmony_ci    const canvas = context.canvas;
5820e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
5821e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
5822e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
5823e41f4b71Sopenharmony_ci    let pathEffect = drawing.PathEffect.createDashPathEffect([30, 10], 0);
5824e41f4b71Sopenharmony_ci    pen.setPathEffect(pathEffect);
5825e41f4b71Sopenharmony_ci  }
5826e41f4b71Sopenharmony_ci}
5827e41f4b71Sopenharmony_ci```
5828e41f4b71Sopenharmony_ci
5829e41f4b71Sopenharmony_ci### setShaderEffect<sup>12+</sup>
5830e41f4b71Sopenharmony_ci
5831e41f4b71Sopenharmony_cisetShaderEffect(shaderEffect: ShaderEffect): void
5832e41f4b71Sopenharmony_ci
5833e41f4b71Sopenharmony_ciSets the shader effect for this pen.
5834e41f4b71Sopenharmony_ci
5835e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5836e41f4b71Sopenharmony_ci
5837e41f4b71Sopenharmony_ci**Parameters**
5838e41f4b71Sopenharmony_ci
5839e41f4b71Sopenharmony_ci| Name | Type                      | Mandatory| Description        |
5840e41f4b71Sopenharmony_ci| ------- | ------------------------- | ---- | ------------ |
5841e41f4b71Sopenharmony_ci| shaderEffect  | [ShaderEffect](#shadereffect12) | Yes  | **ShaderEffect** object. If null is passed in, the shader effect will be cleared.|
5842e41f4b71Sopenharmony_ci
5843e41f4b71Sopenharmony_ci**Error codes**
5844e41f4b71Sopenharmony_ci
5845e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5846e41f4b71Sopenharmony_ci
5847e41f4b71Sopenharmony_ci| ID| Error Message|
5848e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
5849e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
5850e41f4b71Sopenharmony_ci
5851e41f4b71Sopenharmony_ci**Example**
5852e41f4b71Sopenharmony_ci
5853e41f4b71Sopenharmony_ci```ts
5854e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
5855e41f4b71Sopenharmony_ci
5856e41f4b71Sopenharmony_ciconst pen = new drawing.Pen();
5857e41f4b71Sopenharmony_cilet shaderEffect = drawing.ShaderEffect.createLinearGradient({x: 100, y: 100}, {x: 300, y: 300}, [0xFF00FF00, 0xFFFF0000], drawing.TileMode.REPEAT);
5858e41f4b71Sopenharmony_cipen.setShaderEffect(shaderEffect);
5859e41f4b71Sopenharmony_ci```
5860e41f4b71Sopenharmony_ci
5861e41f4b71Sopenharmony_ci### setShadowLayer<sup>12+</sup>
5862e41f4b71Sopenharmony_ci
5863e41f4b71Sopenharmony_cisetShadowLayer(shadowLayer: ShadowLayer): void
5864e41f4b71Sopenharmony_ci
5865e41f4b71Sopenharmony_ciSets a shadow layer for this pen. The shadow layer effect takes effect only when text is drawn.
5866e41f4b71Sopenharmony_ci
5867e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5868e41f4b71Sopenharmony_ci
5869e41f4b71Sopenharmony_ci**Parameters**
5870e41f4b71Sopenharmony_ci
5871e41f4b71Sopenharmony_ci| Name | Type                      | Mandatory| Description     |
5872e41f4b71Sopenharmony_ci| ------- | ------------------------- | ---- | --------- |
5873e41f4b71Sopenharmony_ci| shadowLayer  | [ShadowLayer](#shadowlayer12) | Yes  | Shadow layer. If null is passed in, the shadow layer is cleared.|
5874e41f4b71Sopenharmony_ci
5875e41f4b71Sopenharmony_ci**Error codes**
5876e41f4b71Sopenharmony_ci
5877e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5878e41f4b71Sopenharmony_ci
5879e41f4b71Sopenharmony_ci| ID| Error Message|
5880e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
5881e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
5882e41f4b71Sopenharmony_ci
5883e41f4b71Sopenharmony_ci**Example**
5884e41f4b71Sopenharmony_ci
5885e41f4b71Sopenharmony_ci```ts
5886e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
5887e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
5888e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
5889e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
5890e41f4b71Sopenharmony_ci    const canvas = context.canvas;
5891e41f4b71Sopenharmony_ci    let font = new drawing.Font();
5892e41f4b71Sopenharmony_ci    font.setSize(60);
5893e41f4b71Sopenharmony_ci    let textBlob = drawing.TextBlob.makeFromString("hello", font, drawing.TextEncoding.TEXT_ENCODING_UTF8);
5894e41f4b71Sopenharmony_ci    let pen = new drawing.Pen();
5895e41f4b71Sopenharmony_ci    pen.setStrokeWidth(2.0);
5896e41f4b71Sopenharmony_ci    let pen_color : common2D.Color = {alpha: 0xFF, red: 0xFF, green: 0x00, blue: 0x00};
5897e41f4b71Sopenharmony_ci    pen.setColor(pen_color);
5898e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
5899e41f4b71Sopenharmony_ci    canvas.drawTextBlob(textBlob, 100, 100);
5900e41f4b71Sopenharmony_ci    canvas.detachPen();
5901e41f4b71Sopenharmony_ci    let color : common2D.Color = {alpha: 0xFF, red: 0x00, green: 0xFF, blue: 0x00};
5902e41f4b71Sopenharmony_ci    let shadowLayer = drawing.ShadowLayer.create(3, -3, 3, color);
5903e41f4b71Sopenharmony_ci    pen.setShadowLayer(shadowLayer);
5904e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
5905e41f4b71Sopenharmony_ci    canvas.drawTextBlob(textBlob, 100, 200);
5906e41f4b71Sopenharmony_ci    canvas.detachPen();
5907e41f4b71Sopenharmony_ci  }
5908e41f4b71Sopenharmony_ci}
5909e41f4b71Sopenharmony_ci```
5910e41f4b71Sopenharmony_ci
5911e41f4b71Sopenharmony_ci### setBlendMode
5912e41f4b71Sopenharmony_ci
5913e41f4b71Sopenharmony_cisetBlendMode(mode: BlendMode) : void
5914e41f4b71Sopenharmony_ci
5915e41f4b71Sopenharmony_ciSets a blend mode for this pen.
5916e41f4b71Sopenharmony_ci
5917e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5918e41f4b71Sopenharmony_ci
5919e41f4b71Sopenharmony_ci**Parameters**
5920e41f4b71Sopenharmony_ci
5921e41f4b71Sopenharmony_ci| Name| Type                   | Mandatory| Description            |
5922e41f4b71Sopenharmony_ci| ------ | ----------------------- | ---- | ---------------- |
5923e41f4b71Sopenharmony_ci| mode   | [BlendMode](#blendmode) | Yes  | Blend mode.|
5924e41f4b71Sopenharmony_ci
5925e41f4b71Sopenharmony_ci**Error codes**
5926e41f4b71Sopenharmony_ci
5927e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5928e41f4b71Sopenharmony_ci
5929e41f4b71Sopenharmony_ci| ID| Error Message|
5930e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
5931e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
5932e41f4b71Sopenharmony_ci
5933e41f4b71Sopenharmony_ci**Example**
5934e41f4b71Sopenharmony_ci
5935e41f4b71Sopenharmony_ci```ts
5936e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
5937e41f4b71Sopenharmony_ciconst pen = new drawing.Pen();
5938e41f4b71Sopenharmony_cipen.setBlendMode(drawing.BlendMode.SRC);
5939e41f4b71Sopenharmony_ci```
5940e41f4b71Sopenharmony_ci
5941e41f4b71Sopenharmony_ci### setJoinStyle<sup>12+</sup>
5942e41f4b71Sopenharmony_ci
5943e41f4b71Sopenharmony_cisetJoinStyle(style: JoinStyle): void
5944e41f4b71Sopenharmony_ci
5945e41f4b71Sopenharmony_ciSets the join style for this pen.
5946e41f4b71Sopenharmony_ci
5947e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5948e41f4b71Sopenharmony_ci
5949e41f4b71Sopenharmony_ci**Parameters**
5950e41f4b71Sopenharmony_ci
5951e41f4b71Sopenharmony_ci| Name| Type                    | Mandatory| Description            |
5952e41f4b71Sopenharmony_ci| ------ | ----------------------- | ---- | --------------- |
5953e41f4b71Sopenharmony_ci| style  | [JoinStyle](#joinstyle12) | Yes  | Join style.    |
5954e41f4b71Sopenharmony_ci
5955e41f4b71Sopenharmony_ci**Error codes**
5956e41f4b71Sopenharmony_ci
5957e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5958e41f4b71Sopenharmony_ci
5959e41f4b71Sopenharmony_ci| ID| Error Message|
5960e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
5961e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
5962e41f4b71Sopenharmony_ci
5963e41f4b71Sopenharmony_ci**Example**
5964e41f4b71Sopenharmony_ci
5965e41f4b71Sopenharmony_ci```ts
5966e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
5967e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
5968e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
5969e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
5970e41f4b71Sopenharmony_ci    const canvas = context.canvas;
5971e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
5972e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
5973e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
5974e41f4b71Sopenharmony_ci    pen.setJoinStyle(drawing.JoinStyle.ROUND_JOIN);
5975e41f4b71Sopenharmony_ci  }
5976e41f4b71Sopenharmony_ci}
5977e41f4b71Sopenharmony_ci```
5978e41f4b71Sopenharmony_ci
5979e41f4b71Sopenharmony_ci### getJoinStyle<sup>12+</sup>
5980e41f4b71Sopenharmony_ci
5981e41f4b71Sopenharmony_cigetJoinStyle(): JoinStyle
5982e41f4b71Sopenharmony_ci
5983e41f4b71Sopenharmony_ciObtains the join style of this pen.
5984e41f4b71Sopenharmony_ci
5985e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
5986e41f4b71Sopenharmony_ci
5987e41f4b71Sopenharmony_ci**Return value**
5988e41f4b71Sopenharmony_ci
5989e41f4b71Sopenharmony_ci| Type         | Description                   |
5990e41f4b71Sopenharmony_ci| ------------- | ---------------------- |
5991e41f4b71Sopenharmony_ci| JoinStyle | Join style.        |
5992e41f4b71Sopenharmony_ci
5993e41f4b71Sopenharmony_ci**Example**
5994e41f4b71Sopenharmony_ci
5995e41f4b71Sopenharmony_ci```ts
5996e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
5997e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
5998e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
5999e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
6000e41f4b71Sopenharmony_ci    const canvas = context.canvas;
6001e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
6002e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
6003e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
6004e41f4b71Sopenharmony_ci    pen.setJoinStyle(drawing.JoinStyle.ROUND_JOIN);
6005e41f4b71Sopenharmony_ci    let joinStyle = pen.getJoinStyle();
6006e41f4b71Sopenharmony_ci  }
6007e41f4b71Sopenharmony_ci}
6008e41f4b71Sopenharmony_ci```
6009e41f4b71Sopenharmony_ci
6010e41f4b71Sopenharmony_ci### setCapStyle<sup>12+</sup>
6011e41f4b71Sopenharmony_ci
6012e41f4b71Sopenharmony_cisetCapStyle(style: CapStyle): void
6013e41f4b71Sopenharmony_ci
6014e41f4b71Sopenharmony_ciSets the cap style for this pen.
6015e41f4b71Sopenharmony_ci
6016e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6017e41f4b71Sopenharmony_ci
6018e41f4b71Sopenharmony_ci**Parameters**
6019e41f4b71Sopenharmony_ci
6020e41f4b71Sopenharmony_ci| Name| Type                    | Mandatory| Description                  |
6021e41f4b71Sopenharmony_ci| ------ | ----------------------- | ---- | --------------------- |
6022e41f4b71Sopenharmony_ci| style  | [CapStyle](#capstyle12)   | Yes  | A variable that describes the cap style.   |
6023e41f4b71Sopenharmony_ci
6024e41f4b71Sopenharmony_ci**Error codes**
6025e41f4b71Sopenharmony_ci
6026e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6027e41f4b71Sopenharmony_ci
6028e41f4b71Sopenharmony_ci| ID| Error Message|
6029e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
6030e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
6031e41f4b71Sopenharmony_ci
6032e41f4b71Sopenharmony_ci**Example**
6033e41f4b71Sopenharmony_ci
6034e41f4b71Sopenharmony_ci```ts
6035e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
6036e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
6037e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
6038e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
6039e41f4b71Sopenharmony_ci    const canvas = context.canvas;
6040e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
6041e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
6042e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
6043e41f4b71Sopenharmony_ci    pen.setCapStyle(drawing.CapStyle.SQUARE_CAP);
6044e41f4b71Sopenharmony_ci  }
6045e41f4b71Sopenharmony_ci}
6046e41f4b71Sopenharmony_ci```
6047e41f4b71Sopenharmony_ci
6048e41f4b71Sopenharmony_ci### getCapStyle<sup>12+</sup>
6049e41f4b71Sopenharmony_ci
6050e41f4b71Sopenharmony_cigetCapStyle(): CapStyle
6051e41f4b71Sopenharmony_ci
6052e41f4b71Sopenharmony_ciObtains the cap style of this pen.
6053e41f4b71Sopenharmony_ci
6054e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6055e41f4b71Sopenharmony_ci
6056e41f4b71Sopenharmony_ci**Return value**
6057e41f4b71Sopenharmony_ci
6058e41f4b71Sopenharmony_ci| Type        | Description               |
6059e41f4b71Sopenharmony_ci| ------------ | ------------------ |
6060e41f4b71Sopenharmony_ci| CapStyle     | Cap style.|
6061e41f4b71Sopenharmony_ci
6062e41f4b71Sopenharmony_ci**Example**
6063e41f4b71Sopenharmony_ci
6064e41f4b71Sopenharmony_ci```ts
6065e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
6066e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
6067e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
6068e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
6069e41f4b71Sopenharmony_ci    const canvas = context.canvas;
6070e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
6071e41f4b71Sopenharmony_ci    pen.setStrokeWidth(5);
6072e41f4b71Sopenharmony_ci    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
6073e41f4b71Sopenharmony_ci    pen.setCapStyle(drawing.CapStyle.SQUARE_CAP);
6074e41f4b71Sopenharmony_ci    let capStyle = pen.getCapStyle();
6075e41f4b71Sopenharmony_ci  }
6076e41f4b71Sopenharmony_ci}
6077e41f4b71Sopenharmony_ci```
6078e41f4b71Sopenharmony_ci
6079e41f4b71Sopenharmony_ci### setDither
6080e41f4b71Sopenharmony_ci
6081e41f4b71Sopenharmony_cisetDither(dither: boolean) : void
6082e41f4b71Sopenharmony_ci
6083e41f4b71Sopenharmony_ciEnables dithering for this pen. Dithering make the drawn color more realistic.
6084e41f4b71Sopenharmony_ci
6085e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6086e41f4b71Sopenharmony_ci
6087e41f4b71Sopenharmony_ci**Parameters**
6088e41f4b71Sopenharmony_ci
6089e41f4b71Sopenharmony_ci| Name| Type   | Mandatory| Description                                                     |
6090e41f4b71Sopenharmony_ci| ------ | ------- | ---- | --------------------------------------------------------- |
6091e41f4b71Sopenharmony_ci| dither | boolean | Yes  | Whether to enable dithering. The value **true** means to enable dithering, and **false** means the opposite.|
6092e41f4b71Sopenharmony_ci
6093e41f4b71Sopenharmony_ci**Error codes**
6094e41f4b71Sopenharmony_ci
6095e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6096e41f4b71Sopenharmony_ci
6097e41f4b71Sopenharmony_ci| ID| Error Message|
6098e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
6099e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6100e41f4b71Sopenharmony_ci
6101e41f4b71Sopenharmony_ci**Example**
6102e41f4b71Sopenharmony_ci
6103e41f4b71Sopenharmony_ci```ts
6104e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
6105e41f4b71Sopenharmony_ciconst pen = new drawing.Pen();
6106e41f4b71Sopenharmony_cipen.setDither(true);
6107e41f4b71Sopenharmony_ci```
6108e41f4b71Sopenharmony_ci
6109e41f4b71Sopenharmony_ci### getFillPath<sup>12+</sup>
6110e41f4b71Sopenharmony_ci
6111e41f4b71Sopenharmony_cigetFillPath(src: Path, dst: Path): boolean
6112e41f4b71Sopenharmony_ci
6113e41f4b71Sopenharmony_ciObtains the source path outline drawn using this pen and represents it using a destination path.
6114e41f4b71Sopenharmony_ci
6115e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6116e41f4b71Sopenharmony_ci
6117e41f4b71Sopenharmony_ci**Parameters**
6118e41f4b71Sopenharmony_ci
6119e41f4b71Sopenharmony_ci| Name  | Type                                        | Mandatory| Description                           |
6120e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | ---- | ------------------------------- |
6121e41f4b71Sopenharmony_ci| src | [Path](#path) | Yes  | Source path.                |
6122e41f4b71Sopenharmony_ci| dst     | [Path](#path)                | Yes  | Destination path.|
6123e41f4b71Sopenharmony_ci
6124e41f4b71Sopenharmony_ci**Return value**
6125e41f4b71Sopenharmony_ci
6126e41f4b71Sopenharmony_ci| Type                 | Description          |
6127e41f4b71Sopenharmony_ci| --------------------- | -------------- |
6128e41f4b71Sopenharmony_ci| boolean | Result indicating whether the source path outline is obtained. The value **true** means that the source path outline is obtained, and **false** means the opposite.|
6129e41f4b71Sopenharmony_ci
6130e41f4b71Sopenharmony_ci**Error codes**
6131e41f4b71Sopenharmony_ci
6132e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6133e41f4b71Sopenharmony_ci
6134e41f4b71Sopenharmony_ci| ID| Error Message|
6135e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
6136e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6137e41f4b71Sopenharmony_ci
6138e41f4b71Sopenharmony_ci**Example**
6139e41f4b71Sopenharmony_ci
6140e41f4b71Sopenharmony_ci```ts
6141e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
6142e41f4b71Sopenharmony_cilet pen = new drawing.Pen();
6143e41f4b71Sopenharmony_cilet pathSrc: drawing.Path = new drawing.Path();
6144e41f4b71Sopenharmony_cilet pathDst: drawing.Path = new drawing.Path();
6145e41f4b71Sopenharmony_cipathSrc.moveTo(0, 0);
6146e41f4b71Sopenharmony_cipathSrc.lineTo(700, 700);
6147e41f4b71Sopenharmony_cilet value = pen.getFillPath(pathSrc, pathDst);
6148e41f4b71Sopenharmony_ci```
6149e41f4b71Sopenharmony_ci
6150e41f4b71Sopenharmony_ci### reset<sup>12+</sup>
6151e41f4b71Sopenharmony_ci
6152e41f4b71Sopenharmony_cireset(): void
6153e41f4b71Sopenharmony_ci
6154e41f4b71Sopenharmony_ciResets this pen to the initial state.
6155e41f4b71Sopenharmony_ci
6156e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6157e41f4b71Sopenharmony_ci
6158e41f4b71Sopenharmony_ci**Example**
6159e41f4b71Sopenharmony_ci
6160e41f4b71Sopenharmony_ci```ts
6161e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
6162e41f4b71Sopenharmony_ci
6163e41f4b71Sopenharmony_ciconst pen = new drawing.Pen();
6164e41f4b71Sopenharmony_cipen.reset();
6165e41f4b71Sopenharmony_ci```
6166e41f4b71Sopenharmony_ci
6167e41f4b71Sopenharmony_ci## Brush
6168e41f4b71Sopenharmony_ci
6169e41f4b71Sopenharmony_ciDefines a brush, which is used to describe the style and color to fill in a shape.
6170e41f4b71Sopenharmony_ci
6171e41f4b71Sopenharmony_ci### constructor<sup>12+</sup>
6172e41f4b71Sopenharmony_ci
6173e41f4b71Sopenharmony_ciconstructor()
6174e41f4b71Sopenharmony_ci
6175e41f4b71Sopenharmony_ciA constructor used to create a **Brush** object.
6176e41f4b71Sopenharmony_ci
6177e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6178e41f4b71Sopenharmony_ci
6179e41f4b71Sopenharmony_ci**Example**
6180e41f4b71Sopenharmony_ci
6181e41f4b71Sopenharmony_ci```ts
6182e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
6183e41f4b71Sopenharmony_ci
6184e41f4b71Sopenharmony_ciconst brush = new drawing.Brush();
6185e41f4b71Sopenharmony_ci```
6186e41f4b71Sopenharmony_ci
6187e41f4b71Sopenharmony_ci### constructor<sup>12+</sup>
6188e41f4b71Sopenharmony_ci
6189e41f4b71Sopenharmony_ciconstructor(brush: Brush)
6190e41f4b71Sopenharmony_ci
6191e41f4b71Sopenharmony_ciCopies a **Brush** object to create a new one.
6192e41f4b71Sopenharmony_ci
6193e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6194e41f4b71Sopenharmony_ci
6195e41f4b71Sopenharmony_ci**Parameters**
6196e41f4b71Sopenharmony_ci
6197e41f4b71Sopenharmony_ci| Name| Type       | Mandatory| Description             |
6198e41f4b71Sopenharmony_ci| ------| ----------- | ---- | ---------------- |
6199e41f4b71Sopenharmony_ci| brush     | [Brush](#brush) | Yes  | **Brush** object to copy.|
6200e41f4b71Sopenharmony_ci
6201e41f4b71Sopenharmony_ci**Error codes**
6202e41f4b71Sopenharmony_ci
6203e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6204e41f4b71Sopenharmony_ci
6205e41f4b71Sopenharmony_ci| ID| Error Message|
6206e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
6207e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6208e41f4b71Sopenharmony_ci
6209e41f4b71Sopenharmony_ci**Example**
6210e41f4b71Sopenharmony_ci
6211e41f4b71Sopenharmony_ci```ts
6212e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
6213e41f4b71Sopenharmony_ci
6214e41f4b71Sopenharmony_ciconst brush = new drawing.Brush();
6215e41f4b71Sopenharmony_ciconst brushColor: common2D.Color = { alpha: 255, red: 0, green: 255, blue: 0 };
6216e41f4b71Sopenharmony_cibrush.setColor(brushColor);
6217e41f4b71Sopenharmony_ciconst newBrush = new drawing.Brush(brush);
6218e41f4b71Sopenharmony_ci```
6219e41f4b71Sopenharmony_ci
6220e41f4b71Sopenharmony_ci### setColor
6221e41f4b71Sopenharmony_ci
6222e41f4b71Sopenharmony_cisetColor(color: common2D.Color) : void
6223e41f4b71Sopenharmony_ci
6224e41f4b71Sopenharmony_ciSets a color for this brush.
6225e41f4b71Sopenharmony_ci
6226e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6227e41f4b71Sopenharmony_ci
6228e41f4b71Sopenharmony_ci**Parameters**
6229e41f4b71Sopenharmony_ci
6230e41f4b71Sopenharmony_ci| Name| Type                                                | Mandatory| Description            |
6231e41f4b71Sopenharmony_ci| ------ | ---------------------------------------------------- | ---- | ---------------- |
6232e41f4b71Sopenharmony_ci| color  | [common2D.Color](js-apis-graphics-common2D.md#color) | Yes  | Color in ARGB format. Each color channel is an integer ranging from 0 to 255.|
6233e41f4b71Sopenharmony_ci
6234e41f4b71Sopenharmony_ci**Error codes**
6235e41f4b71Sopenharmony_ci
6236e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6237e41f4b71Sopenharmony_ci
6238e41f4b71Sopenharmony_ci| ID| Error Message|
6239e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
6240e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
6241e41f4b71Sopenharmony_ci
6242e41f4b71Sopenharmony_ci**Example**
6243e41f4b71Sopenharmony_ci
6244e41f4b71Sopenharmony_ci```ts
6245e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
6246e41f4b71Sopenharmony_ciconst color : common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
6247e41f4b71Sopenharmony_ciconst brush = new drawing.Brush();
6248e41f4b71Sopenharmony_cibrush.setColor(color);
6249e41f4b71Sopenharmony_ci```
6250e41f4b71Sopenharmony_ci
6251e41f4b71Sopenharmony_ci### setColor<sup>12+</sup>
6252e41f4b71Sopenharmony_ci
6253e41f4b71Sopenharmony_cisetColor(alpha: number, red: number, green: number, blue: number): void
6254e41f4b71Sopenharmony_ci
6255e41f4b71Sopenharmony_ciSets a color for this brush. This API provides better performance than [setColor](#setcolor-1) and is recommended.
6256e41f4b71Sopenharmony_ci
6257e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6258e41f4b71Sopenharmony_ci 
6259e41f4b71Sopenharmony_ci**Parameters**
6260e41f4b71Sopenharmony_ci
6261e41f4b71Sopenharmony_ci| Name| Type   | Mandatory| Description                                              |
6262e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------------------------------------------- |
6263e41f4b71Sopenharmony_ci| alpha  | number | Yes  | Alpha channel value of the color in ARGB format. The value is an integer ranging from 0 to 255. Any passed-in floating point number is rounded down.|
6264e41f4b71Sopenharmony_ci| red    | number | Yes  | Red channel value of the color in ARGB format. The value is an integer ranging from 0 to 255. Any passed-in floating point number is rounded down.  |
6265e41f4b71Sopenharmony_ci| green  | number | Yes  | Green channel value of the color in ARGB format. The value is an integer ranging from 0 to 255. Any passed-in floating point number is rounded down.  |
6266e41f4b71Sopenharmony_ci| blue   | number | Yes  | Blue channel value of the color in ARGB format. The value is an integer ranging from 0 to 255. Any passed-in floating point number is rounded down.  |
6267e41f4b71Sopenharmony_ci
6268e41f4b71Sopenharmony_ci**Error codes**
6269e41f4b71Sopenharmony_ci
6270e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6271e41f4b71Sopenharmony_ci
6272e41f4b71Sopenharmony_ci| ID| Error Message|
6273e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
6274e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
6275e41f4b71Sopenharmony_ci
6276e41f4b71Sopenharmony_ci**Example**
6277e41f4b71Sopenharmony_ci
6278e41f4b71Sopenharmony_ci```ts
6279e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
6280e41f4b71Sopenharmony_ciconst brush = new drawing.Brush();
6281e41f4b71Sopenharmony_cibrush.setColor(255, 255, 0, 0);
6282e41f4b71Sopenharmony_ci```
6283e41f4b71Sopenharmony_ci
6284e41f4b71Sopenharmony_ci### getColor<sup>12+</sup>
6285e41f4b71Sopenharmony_ci
6286e41f4b71Sopenharmony_cigetColor(): common2D.Color
6287e41f4b71Sopenharmony_ci
6288e41f4b71Sopenharmony_ciObtains the color of this brush.
6289e41f4b71Sopenharmony_ci
6290e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6291e41f4b71Sopenharmony_ci
6292e41f4b71Sopenharmony_ci**Return value**
6293e41f4b71Sopenharmony_ci
6294e41f4b71Sopenharmony_ci| Type          | Description           |
6295e41f4b71Sopenharmony_ci| -------------- | -------------- |
6296e41f4b71Sopenharmony_ci| common2D.Color | Color of the brush.|
6297e41f4b71Sopenharmony_ci
6298e41f4b71Sopenharmony_ci**Example**
6299e41f4b71Sopenharmony_ci
6300e41f4b71Sopenharmony_ci```ts
6301e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
6302e41f4b71Sopenharmony_ci
6303e41f4b71Sopenharmony_ciconst color : common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
6304e41f4b71Sopenharmony_ciconst brush = new drawing.Brush();
6305e41f4b71Sopenharmony_cibrush.setColor(color);
6306e41f4b71Sopenharmony_cilet colorGet = brush.getColor();
6307e41f4b71Sopenharmony_ci```
6308e41f4b71Sopenharmony_ci
6309e41f4b71Sopenharmony_ci### getHexColor<sup>13+</sup>
6310e41f4b71Sopenharmony_ci
6311e41f4b71Sopenharmony_ciObtains the color of this brush.
6312e41f4b71Sopenharmony_ci
6313e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6314e41f4b71Sopenharmony_ci
6315e41f4b71Sopenharmony_ci**Return value**
6316e41f4b71Sopenharmony_ci
6317e41f4b71Sopenharmony_ci| Type          | Description           |
6318e41f4b71Sopenharmony_ci| -------------- | -------------- |
6319e41f4b71Sopenharmony_ci| number | Color, represented as a 32-bit unsigned integer in hexadecimal ARGB format.|
6320e41f4b71Sopenharmony_ci
6321e41f4b71Sopenharmony_ci**Example**
6322e41f4b71Sopenharmony_ci
6323e41f4b71Sopenharmony_ci```ts
6324e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
6325e41f4b71Sopenharmony_ci
6326e41f4b71Sopenharmony_cilet color : common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
6327e41f4b71Sopenharmony_cilet brush = new drawing.Brush();
6328e41f4b71Sopenharmony_cibrush.setColor(color);
6329e41f4b71Sopenharmony_cilet hex_color: number = brush.getHexColor();
6330e41f4b71Sopenharmony_ciconsole.info('getHexColor: ', hex_color.toString(16));
6331e41f4b71Sopenharmony_ci```
6332e41f4b71Sopenharmony_ci
6333e41f4b71Sopenharmony_ci### setAntiAlias
6334e41f4b71Sopenharmony_ci
6335e41f4b71Sopenharmony_cisetAntiAlias(aa: boolean) : void
6336e41f4b71Sopenharmony_ci
6337e41f4b71Sopenharmony_ciEnables anti-aliasing for this brush. Anti-aliasing makes the edges of the content smoother.
6338e41f4b71Sopenharmony_ci
6339e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6340e41f4b71Sopenharmony_ci
6341e41f4b71Sopenharmony_ci**Parameters**
6342e41f4b71Sopenharmony_ci
6343e41f4b71Sopenharmony_ci| Name| Type   | Mandatory| Description                                             |
6344e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------------------- |
6345e41f4b71Sopenharmony_ci| aa     | boolean | Yes  | Whether to enable anti-aliasing. The value **true** means to enable anti-aliasing, and **false** means the opposite.|
6346e41f4b71Sopenharmony_ci
6347e41f4b71Sopenharmony_ci**Error codes**
6348e41f4b71Sopenharmony_ci
6349e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6350e41f4b71Sopenharmony_ci
6351e41f4b71Sopenharmony_ci| ID| Error Message|
6352e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
6353e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6354e41f4b71Sopenharmony_ci
6355e41f4b71Sopenharmony_ci**Example**
6356e41f4b71Sopenharmony_ci
6357e41f4b71Sopenharmony_ci```ts
6358e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
6359e41f4b71Sopenharmony_ciconst brush = new drawing.Brush();
6360e41f4b71Sopenharmony_cibrush.setAntiAlias(true);
6361e41f4b71Sopenharmony_ci```
6362e41f4b71Sopenharmony_ci
6363e41f4b71Sopenharmony_ci### isAntiAlias<sup>12+</sup>
6364e41f4b71Sopenharmony_ci
6365e41f4b71Sopenharmony_ciisAntiAlias(): boolean
6366e41f4b71Sopenharmony_ci
6367e41f4b71Sopenharmony_ciChecks whether anti-aliasing is enabled for this brush.
6368e41f4b71Sopenharmony_ci
6369e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6370e41f4b71Sopenharmony_ci
6371e41f4b71Sopenharmony_ci**Return value**
6372e41f4b71Sopenharmony_ci
6373e41f4b71Sopenharmony_ci| Type   | Description                      |
6374e41f4b71Sopenharmony_ci| ------- | ------------------------- |
6375e41f4b71Sopenharmony_ci| boolean | Result indicating whether anti-aliasing is enabled. The value **true** means that anti-aliasing is enabled, and **false** means the opposite.|
6376e41f4b71Sopenharmony_ci
6377e41f4b71Sopenharmony_ci**Example**
6378e41f4b71Sopenharmony_ci
6379e41f4b71Sopenharmony_ci```ts
6380e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
6381e41f4b71Sopenharmony_ci
6382e41f4b71Sopenharmony_ciconst brush = new drawing.Brush();
6383e41f4b71Sopenharmony_cilet isAntiAlias = brush.isAntiAlias();
6384e41f4b71Sopenharmony_ci```
6385e41f4b71Sopenharmony_ci
6386e41f4b71Sopenharmony_ci### setAlpha
6387e41f4b71Sopenharmony_ci
6388e41f4b71Sopenharmony_cisetAlpha(alpha: number) : void
6389e41f4b71Sopenharmony_ci
6390e41f4b71Sopenharmony_ciSets an alpha value for this brush.
6391e41f4b71Sopenharmony_ci
6392e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6393e41f4b71Sopenharmony_ci
6394e41f4b71Sopenharmony_ci**Parameters**
6395e41f4b71Sopenharmony_ci
6396e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                                    |
6397e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ---------------------------------------- |
6398e41f4b71Sopenharmony_ci| alpha  | number | Yes  | Alpha value. The value is an integer in the range [0, 255]. If a floating point number is passed in, the value is rounded down.|
6399e41f4b71Sopenharmony_ci
6400e41f4b71Sopenharmony_ci**Error codes**
6401e41f4b71Sopenharmony_ci
6402e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6403e41f4b71Sopenharmony_ci
6404e41f4b71Sopenharmony_ci| ID| Error Message|
6405e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
6406e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
6407e41f4b71Sopenharmony_ci
6408e41f4b71Sopenharmony_ci**Example**
6409e41f4b71Sopenharmony_ci
6410e41f4b71Sopenharmony_ci```ts
6411e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
6412e41f4b71Sopenharmony_ciconst brush = new drawing.Brush();
6413e41f4b71Sopenharmony_cibrush.setAlpha(128);
6414e41f4b71Sopenharmony_ci```
6415e41f4b71Sopenharmony_ci
6416e41f4b71Sopenharmony_ci### getAlpha<sup>12+</sup>
6417e41f4b71Sopenharmony_ci
6418e41f4b71Sopenharmony_cigetAlpha(): number
6419e41f4b71Sopenharmony_ci
6420e41f4b71Sopenharmony_ciObtains the alpha value of this brush.
6421e41f4b71Sopenharmony_ci
6422e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6423e41f4b71Sopenharmony_ci
6424e41f4b71Sopenharmony_ci**Return value**
6425e41f4b71Sopenharmony_ci
6426e41f4b71Sopenharmony_ci| Type  | Description             |
6427e41f4b71Sopenharmony_ci| ------ | ---------------- |
6428e41f4b71Sopenharmony_ci| number | Alpha value of the brush. The return value is an integer ranging from 0 to 255.|
6429e41f4b71Sopenharmony_ci
6430e41f4b71Sopenharmony_ci**Example**
6431e41f4b71Sopenharmony_ci
6432e41f4b71Sopenharmony_ci```ts
6433e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
6434e41f4b71Sopenharmony_ci
6435e41f4b71Sopenharmony_ciconst brush = new drawing.Brush();
6436e41f4b71Sopenharmony_cilet alpha = brush.getAlpha();
6437e41f4b71Sopenharmony_ci```
6438e41f4b71Sopenharmony_ci
6439e41f4b71Sopenharmony_ci### setColorFilter
6440e41f4b71Sopenharmony_ci
6441e41f4b71Sopenharmony_cisetColorFilter(filter: ColorFilter) : void
6442e41f4b71Sopenharmony_ci
6443e41f4b71Sopenharmony_ciSets a color filter for this brush.
6444e41f4b71Sopenharmony_ci
6445e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6446e41f4b71Sopenharmony_ci
6447e41f4b71Sopenharmony_ci**Parameters**
6448e41f4b71Sopenharmony_ci
6449e41f4b71Sopenharmony_ci| Name| Type                       | Mandatory| Description        |
6450e41f4b71Sopenharmony_ci| ------ | --------------------------- | ---- | ------------ |
6451e41f4b71Sopenharmony_ci| filter | [ColorFilter](#colorfilter) | Yes  | Color filter. If null is passed in, the color filter is cleared.|
6452e41f4b71Sopenharmony_ci
6453e41f4b71Sopenharmony_ci**Error codes**
6454e41f4b71Sopenharmony_ci
6455e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6456e41f4b71Sopenharmony_ci
6457e41f4b71Sopenharmony_ci| ID| Error Message|
6458e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
6459e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6460e41f4b71Sopenharmony_ci
6461e41f4b71Sopenharmony_ci**Example**
6462e41f4b71Sopenharmony_ci
6463e41f4b71Sopenharmony_ci```ts
6464e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
6465e41f4b71Sopenharmony_ciconst brush = new drawing.Brush();
6466e41f4b71Sopenharmony_cilet colorFilter = drawing.ColorFilter.createLinearToSRGBGamma();
6467e41f4b71Sopenharmony_cibrush.setColorFilter(colorFilter);
6468e41f4b71Sopenharmony_ci```
6469e41f4b71Sopenharmony_ci
6470e41f4b71Sopenharmony_ci### setMaskFilter<sup>12+</sup>
6471e41f4b71Sopenharmony_ci
6472e41f4b71Sopenharmony_cisetMaskFilter(filter: MaskFilter): void
6473e41f4b71Sopenharmony_ci
6474e41f4b71Sopenharmony_ciAdds a mask filter for this brush.
6475e41f4b71Sopenharmony_ci
6476e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6477e41f4b71Sopenharmony_ci
6478e41f4b71Sopenharmony_ci**Parameters**
6479e41f4b71Sopenharmony_ci
6480e41f4b71Sopenharmony_ci| Name| Type                      | Mandatory| Description     |
6481e41f4b71Sopenharmony_ci| ------ | ------------------------- | ---- | --------- |
6482e41f4b71Sopenharmony_ci| filter | [MaskFilter](#maskfilter12) | Yes  | Mask filter. If null is passed in, the mask filter is cleared.|
6483e41f4b71Sopenharmony_ci
6484e41f4b71Sopenharmony_ci**Error codes**
6485e41f4b71Sopenharmony_ci
6486e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6487e41f4b71Sopenharmony_ci
6488e41f4b71Sopenharmony_ci| ID| Error Message|
6489e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
6490e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6491e41f4b71Sopenharmony_ci
6492e41f4b71Sopenharmony_ci**Example**
6493e41f4b71Sopenharmony_ci
6494e41f4b71Sopenharmony_ci```ts
6495e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
6496e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
6497e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
6498e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
6499e41f4b71Sopenharmony_ci    const canvas = context.canvas;
6500e41f4b71Sopenharmony_ci    const brush = new drawing.Brush();
6501e41f4b71Sopenharmony_ci    let maskFilter = drawing.MaskFilter.createBlurMaskFilter(drawing.BlurType.OUTER, 10);
6502e41f4b71Sopenharmony_ci    brush.setMaskFilter(maskFilter);
6503e41f4b71Sopenharmony_ci  }
6504e41f4b71Sopenharmony_ci}
6505e41f4b71Sopenharmony_ci```
6506e41f4b71Sopenharmony_ci
6507e41f4b71Sopenharmony_ci### setShaderEffect<sup>12+</sup>
6508e41f4b71Sopenharmony_ci
6509e41f4b71Sopenharmony_cisetShaderEffect(shaderEffect: ShaderEffect): void
6510e41f4b71Sopenharmony_ci
6511e41f4b71Sopenharmony_ciSets the shader effect for this brush.
6512e41f4b71Sopenharmony_ci
6513e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6514e41f4b71Sopenharmony_ci
6515e41f4b71Sopenharmony_ci**Parameters**
6516e41f4b71Sopenharmony_ci
6517e41f4b71Sopenharmony_ci| Name | Type                      | Mandatory| Description        |
6518e41f4b71Sopenharmony_ci| ------- | ------------------------- | ---- | ------------ |
6519e41f4b71Sopenharmony_ci| shaderEffect  | [ShaderEffect](#shadereffect12) | Yes  | **ShaderEffect** object. If null is passed in, the shader effect will be cleared.|
6520e41f4b71Sopenharmony_ci
6521e41f4b71Sopenharmony_ci**Error codes**
6522e41f4b71Sopenharmony_ci
6523e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6524e41f4b71Sopenharmony_ci
6525e41f4b71Sopenharmony_ci| ID| Error Message|
6526e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
6527e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6528e41f4b71Sopenharmony_ci
6529e41f4b71Sopenharmony_ci**Example**
6530e41f4b71Sopenharmony_ci
6531e41f4b71Sopenharmony_ci```ts
6532e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
6533e41f4b71Sopenharmony_ci
6534e41f4b71Sopenharmony_ciconst brush = new drawing.Brush();
6535e41f4b71Sopenharmony_cilet shaderEffect = drawing.ShaderEffect.createLinearGradient({x: 100, y: 100}, {x: 300, y: 300}, [0xFF00FF00, 0xFFFF0000], drawing.TileMode.REPEAT);
6536e41f4b71Sopenharmony_cibrush.setShaderEffect(shaderEffect);
6537e41f4b71Sopenharmony_ci```
6538e41f4b71Sopenharmony_ci
6539e41f4b71Sopenharmony_ci### setShadowLayer<sup>12+</sup>
6540e41f4b71Sopenharmony_ci
6541e41f4b71Sopenharmony_cisetShadowLayer(shadowLayer: ShadowLayer): void
6542e41f4b71Sopenharmony_ci
6543e41f4b71Sopenharmony_ciSets a shadow layer for this brush. The shadow layer effect takes effect only when text is drawn.
6544e41f4b71Sopenharmony_ci
6545e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6546e41f4b71Sopenharmony_ci
6547e41f4b71Sopenharmony_ci**Parameters**
6548e41f4b71Sopenharmony_ci
6549e41f4b71Sopenharmony_ci| Name | Type                      | Mandatory| Description     |
6550e41f4b71Sopenharmony_ci| ------- | ------------------------- | ---- | --------- |
6551e41f4b71Sopenharmony_ci| shadowLayer  | [ShadowLayer](#shadowlayer12) | Yes  | Shadow layer. If null is passed in, the shadow layer is cleared.|
6552e41f4b71Sopenharmony_ci
6553e41f4b71Sopenharmony_ci**Error codes**
6554e41f4b71Sopenharmony_ci
6555e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6556e41f4b71Sopenharmony_ci
6557e41f4b71Sopenharmony_ci| ID| Error Message|
6558e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
6559e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6560e41f4b71Sopenharmony_ci
6561e41f4b71Sopenharmony_ci**Example**
6562e41f4b71Sopenharmony_ci
6563e41f4b71Sopenharmony_ci```ts
6564e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
6565e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
6566e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
6567e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
6568e41f4b71Sopenharmony_ci    const canvas = context.canvas;
6569e41f4b71Sopenharmony_ci    let font = new drawing.Font();
6570e41f4b71Sopenharmony_ci    font.setSize(60);
6571e41f4b71Sopenharmony_ci
6572e41f4b71Sopenharmony_ci    let textBlob = drawing.TextBlob.makeFromString("hello", font, drawing.TextEncoding.TEXT_ENCODING_UTF8);
6573e41f4b71Sopenharmony_ci    let pen = new drawing.Pen();
6574e41f4b71Sopenharmony_ci    pen.setStrokeWidth(2.0);
6575e41f4b71Sopenharmony_ci
6576e41f4b71Sopenharmony_ci    let pen_color : common2D.Color = {alpha: 0xFF, red: 0xFF, green: 0x00, blue: 0x00};
6577e41f4b71Sopenharmony_ci    pen.setColor(pen_color);
6578e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
6579e41f4b71Sopenharmony_ci    canvas.drawTextBlob(textBlob, 100, 100);
6580e41f4b71Sopenharmony_ci    canvas.detachPen();
6581e41f4b71Sopenharmony_ci
6582e41f4b71Sopenharmony_ci    let color : common2D.Color = {alpha: 0xFF, red: 0x00, green: 0xFF, blue: 0x00};
6583e41f4b71Sopenharmony_ci    let shadowLayer = drawing.ShadowLayer.create(3, -3, 3, color);
6584e41f4b71Sopenharmony_ci    pen.setShadowLayer(shadowLayer);
6585e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
6586e41f4b71Sopenharmony_ci    canvas.drawTextBlob(textBlob, 100, 200);
6587e41f4b71Sopenharmony_ci    canvas.detachPen();
6588e41f4b71Sopenharmony_ci
6589e41f4b71Sopenharmony_ci    let brush = new drawing.Brush();
6590e41f4b71Sopenharmony_ci    let brush_color : common2D.Color = {alpha: 0xFF, red: 0xFF, green: 0x00, blue: 0x00};
6591e41f4b71Sopenharmony_ci    brush.setColor(brush_color);
6592e41f4b71Sopenharmony_ci    canvas.attachBrush(brush);
6593e41f4b71Sopenharmony_ci    canvas.drawTextBlob(textBlob, 300, 100);
6594e41f4b71Sopenharmony_ci    canvas.detachBrush();
6595e41f4b71Sopenharmony_ci
6596e41f4b71Sopenharmony_ci    brush.setShadowLayer(shadowLayer);
6597e41f4b71Sopenharmony_ci    canvas.attachBrush(brush);
6598e41f4b71Sopenharmony_ci    canvas.drawTextBlob(textBlob, 300, 200);
6599e41f4b71Sopenharmony_ci    canvas.detachBrush();
6600e41f4b71Sopenharmony_ci  }
6601e41f4b71Sopenharmony_ci}
6602e41f4b71Sopenharmony_ci```
6603e41f4b71Sopenharmony_ci
6604e41f4b71Sopenharmony_ci### setBlendMode
6605e41f4b71Sopenharmony_ci
6606e41f4b71Sopenharmony_cisetBlendMode(mode: BlendMode) : void
6607e41f4b71Sopenharmony_ci
6608e41f4b71Sopenharmony_ciSets a blend mode for this brush.
6609e41f4b71Sopenharmony_ci
6610e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6611e41f4b71Sopenharmony_ci
6612e41f4b71Sopenharmony_ci**Parameters**
6613e41f4b71Sopenharmony_ci
6614e41f4b71Sopenharmony_ci| Name| Type                   | Mandatory| Description            |
6615e41f4b71Sopenharmony_ci| ------ | ----------------------- | ---- | ---------------- |
6616e41f4b71Sopenharmony_ci| mode   | [BlendMode](#blendmode) | Yes  | Blend mode.|
6617e41f4b71Sopenharmony_ci
6618e41f4b71Sopenharmony_ci**Error codes**
6619e41f4b71Sopenharmony_ci
6620e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6621e41f4b71Sopenharmony_ci
6622e41f4b71Sopenharmony_ci| ID| Error Message|
6623e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
6624e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
6625e41f4b71Sopenharmony_ci
6626e41f4b71Sopenharmony_ci**Example**
6627e41f4b71Sopenharmony_ci
6628e41f4b71Sopenharmony_ci```ts
6629e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
6630e41f4b71Sopenharmony_ciconst brush = new drawing.Brush();
6631e41f4b71Sopenharmony_cibrush.setBlendMode(drawing.BlendMode.SRC);
6632e41f4b71Sopenharmony_ci```
6633e41f4b71Sopenharmony_ci
6634e41f4b71Sopenharmony_ci### setImageFilter<sup>12+</sup>
6635e41f4b71Sopenharmony_ci
6636e41f4b71Sopenharmony_cisetImageFilter(filter: ImageFilter | null): void
6637e41f4b71Sopenharmony_ci
6638e41f4b71Sopenharmony_ciSets an image filter for this brush.
6639e41f4b71Sopenharmony_ci
6640e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6641e41f4b71Sopenharmony_ci
6642e41f4b71Sopenharmony_ci**Parameters**
6643e41f4b71Sopenharmony_ci
6644e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                   |
6645e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------- |
6646e41f4b71Sopenharmony_ci| filter    | [ImageFilter](#imagefilter12) \| null | Yes  | Image filter. If null is passed in, the image filter effect of the brush will be cleared.|
6647e41f4b71Sopenharmony_ci
6648e41f4b71Sopenharmony_ci**Error codes**
6649e41f4b71Sopenharmony_ci
6650e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6651e41f4b71Sopenharmony_ci
6652e41f4b71Sopenharmony_ci| ID| Error Message|
6653e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
6654e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types. | 
6655e41f4b71Sopenharmony_ci
6656e41f4b71Sopenharmony_ci**Example**
6657e41f4b71Sopenharmony_ci
6658e41f4b71Sopenharmony_ci```ts
6659e41f4b71Sopenharmony_ciimport {drawing} from '@kit.ArkGraphics2D';
6660e41f4b71Sopenharmony_cilet brush = new drawing.Brush();
6661e41f4b71Sopenharmony_cilet imgFilter = drawing.ImageFilter.createBlurImageFilter(5, 10, drawing.TileMode.DECAL);
6662e41f4b71Sopenharmony_cibrush.setImageFilter(imgFilter);
6663e41f4b71Sopenharmony_cibrush.setImageFilter(null);
6664e41f4b71Sopenharmony_ci```
6665e41f4b71Sopenharmony_ci
6666e41f4b71Sopenharmony_ci### getColorFilter<sup>12+</sup>
6667e41f4b71Sopenharmony_ci
6668e41f4b71Sopenharmony_cigetColorFilter(): ColorFilter
6669e41f4b71Sopenharmony_ci
6670e41f4b71Sopenharmony_ciObtains the color filter of this brush.
6671e41f4b71Sopenharmony_ci
6672e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6673e41f4b71Sopenharmony_ci
6674e41f4b71Sopenharmony_ci**Return value**
6675e41f4b71Sopenharmony_ci
6676e41f4b71Sopenharmony_ci| Type                       | Description              |
6677e41f4b71Sopenharmony_ci| --------------------------- | ------------------ |
6678e41f4b71Sopenharmony_ci| [ColorFilter](#colorfilter) | Color filter.|
6679e41f4b71Sopenharmony_ci
6680e41f4b71Sopenharmony_ci**Example**
6681e41f4b71Sopenharmony_ci
6682e41f4b71Sopenharmony_ci```ts 
6683e41f4b71Sopenharmony_ciimport {drawing} from '@kit.ArkGraphics2D';
6684e41f4b71Sopenharmony_cilet brush = new drawing.Brush();
6685e41f4b71Sopenharmony_cilet setColorFilter = drawing.ColorFilter.createSRGBGammaToLinear();
6686e41f4b71Sopenharmony_cibrush.setColorFilter(setColorFilter);
6687e41f4b71Sopenharmony_cilet filter = brush.getColorFilter();   
6688e41f4b71Sopenharmony_ci```
6689e41f4b71Sopenharmony_ci
6690e41f4b71Sopenharmony_ci### reset<sup>12+</sup>
6691e41f4b71Sopenharmony_ci
6692e41f4b71Sopenharmony_cireset(): void
6693e41f4b71Sopenharmony_ci
6694e41f4b71Sopenharmony_ciResets this brush to the initial state.
6695e41f4b71Sopenharmony_ci
6696e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6697e41f4b71Sopenharmony_ci
6698e41f4b71Sopenharmony_ci**Example**
6699e41f4b71Sopenharmony_ci
6700e41f4b71Sopenharmony_ci```ts
6701e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
6702e41f4b71Sopenharmony_ci
6703e41f4b71Sopenharmony_ciconst brush = new drawing.Brush();
6704e41f4b71Sopenharmony_cibrush.reset();
6705e41f4b71Sopenharmony_ci```
6706e41f4b71Sopenharmony_ci
6707e41f4b71Sopenharmony_ci## ScaleToFit<sup>12+</sup>
6708e41f4b71Sopenharmony_ci
6709e41f4b71Sopenharmony_ciEnumerates the modes of scaling a source rectangle into a destination rectangle.
6710e41f4b71Sopenharmony_ci
6711e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6712e41f4b71Sopenharmony_ci
6713e41f4b71Sopenharmony_ci| Name                  | Value  | Description                          |
6714e41f4b71Sopenharmony_ci| ---------------------- | ---- | ------------------------------ |
6715e41f4b71Sopenharmony_ci| FILL_SCALE_TO_FIT     | 0    | Scales the source rectangle to completely fill the destination rectangle, potentially changing the aspect ratio of the source rectangle. |
6716e41f4b71Sopenharmony_ci| START_SCALE_TO_FIT    | 1    | Scales the source rectangle, preserving its aspect ratio, to align it to the upper left corner of the destination rectangle.|
6717e41f4b71Sopenharmony_ci| CENTER_SCALE_TO_FIT    | 2    | Scales the source rectangle, preserving its aspect ratio, to align it to the center of the destination rectangle.  |
6718e41f4b71Sopenharmony_ci| END_SCALE_TO_FIT | 3    | Scales the source rectangle, preserving its aspect ratio, to align it to the lower right corner of the destination rectangle.  |
6719e41f4b71Sopenharmony_ci
6720e41f4b71Sopenharmony_ci## Matrix<sup>12+</sup>
6721e41f4b71Sopenharmony_ci
6722e41f4b71Sopenharmony_ciImplements a matrix.
6723e41f4b71Sopenharmony_ci
6724e41f4b71Sopenharmony_ciA 3 x 3 matrix is shown as below.
6725e41f4b71Sopenharmony_ci
6726e41f4b71Sopenharmony_ci![matrix_3x3](figures/matrix3X3.PNG)
6727e41f4b71Sopenharmony_ci
6728e41f4b71Sopenharmony_ciElements in the matrix from left to right and from top to bottom respectively represent a horizontal scale coefficient, a horizontal skew coefficient, a horizontal translation coefficient, a vertical skew coefficient, a vertical scale coefficient, a vertical translation coefficient, an X-axis perspective coefficient, a Y-axis perspective coefficient, and a perspective scale coefficient.
6729e41f4b71Sopenharmony_ciIf (x<sub>1</sub>, y<sub>1</sub>) is the source coordinate point, (x<sub>2</sub>, y<sub>2</sub>) is the coordinate point obtained by transforming the source coordinate point using the matrix, then the relationship between the two coordinate points is as follows:
6730e41f4b71Sopenharmony_ci
6731e41f4b71Sopenharmony_ci![matrix_xy](figures/matrix_xy.PNG)
6732e41f4b71Sopenharmony_ci
6733e41f4b71Sopenharmony_ci### constructor<sup>12+</sup>
6734e41f4b71Sopenharmony_ci
6735e41f4b71Sopenharmony_ciconstructor()
6736e41f4b71Sopenharmony_ci
6737e41f4b71Sopenharmony_ciCreates a **Matrix** object.
6738e41f4b71Sopenharmony_ci
6739e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6740e41f4b71Sopenharmony_ci
6741e41f4b71Sopenharmony_ci**Example**
6742e41f4b71Sopenharmony_ci
6743e41f4b71Sopenharmony_ci```ts
6744e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
6745e41f4b71Sopenharmony_ci
6746e41f4b71Sopenharmony_cilet matrix = new drawing.Matrix();
6747e41f4b71Sopenharmony_ci```
6748e41f4b71Sopenharmony_ci
6749e41f4b71Sopenharmony_ci### setRotation<sup>12+</sup>
6750e41f4b71Sopenharmony_ci
6751e41f4b71Sopenharmony_cisetRotation(degree: number, px: number, py: number): void
6752e41f4b71Sopenharmony_ci
6753e41f4b71Sopenharmony_ciSets this matrix as an identity matrix and rotates it by a given degree around the rotation point (px, py).
6754e41f4b71Sopenharmony_ci
6755e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6756e41f4b71Sopenharmony_ci
6757e41f4b71Sopenharmony_ci**Parameters**
6758e41f4b71Sopenharmony_ci
6759e41f4b71Sopenharmony_ci| Name        | Type                                      | Mandatory  | Description                 |
6760e41f4b71Sopenharmony_ci| ----------- | ---------------------------------------- | ---- | ------------------- |
6761e41f4b71Sopenharmony_ci| degree      | number                  | Yes   | Angle to rotate, in degrees. A positive number indicates a clockwise rotation, and a negative number indicates a counterclockwise rotation. The value is a floating point number.|
6762e41f4b71Sopenharmony_ci| px          | number                  | Yes   | X coordinate of the rotation point. The value is a floating point number.    |
6763e41f4b71Sopenharmony_ci| py          | number                  | Yes   | Y coordinate of the rotation point. The value is a floating point number.    |
6764e41f4b71Sopenharmony_ci
6765e41f4b71Sopenharmony_ci**Error codes**
6766e41f4b71Sopenharmony_ci
6767e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6768e41f4b71Sopenharmony_ci
6769e41f4b71Sopenharmony_ci| ID| Error Message|
6770e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
6771e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6772e41f4b71Sopenharmony_ci
6773e41f4b71Sopenharmony_ci**Example**
6774e41f4b71Sopenharmony_ci
6775e41f4b71Sopenharmony_ci```ts
6776e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
6777e41f4b71Sopenharmony_ci
6778e41f4b71Sopenharmony_cilet matrix = new drawing.Matrix();
6779e41f4b71Sopenharmony_cimatrix.setRotation(90, 100, 100);
6780e41f4b71Sopenharmony_ci```
6781e41f4b71Sopenharmony_ci
6782e41f4b71Sopenharmony_ci### setScale<sup>12+</sup>
6783e41f4b71Sopenharmony_ci
6784e41f4b71Sopenharmony_cisetScale(sx: number, sy: number, px: number, py: number): void
6785e41f4b71Sopenharmony_ci
6786e41f4b71Sopenharmony_ciSets this matrix as an identity matrix and scales it with the coefficients (sx, sy) at the rotation point (px, py).
6787e41f4b71Sopenharmony_ci
6788e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6789e41f4b71Sopenharmony_ci
6790e41f4b71Sopenharmony_ci**Parameters**
6791e41f4b71Sopenharmony_ci
6792e41f4b71Sopenharmony_ci| Name        | Type                                      | Mandatory  | Description                 |
6793e41f4b71Sopenharmony_ci| ----------- | ---------------------------------------- | ---- | ------------------- |
6794e41f4b71Sopenharmony_ci| sx          | number                  | Yes   | Scale coefficient along the X axis. If a negative number is passed in, the matrix is mirrored around y = px before being scaled. The value is a floating point number.    |
6795e41f4b71Sopenharmony_ci| sy          | number                  | Yes   | Scale coefficient along the Y axis. If a negative number is passed in, the matrix is mirrored around x = py before being scaled. The value is a floating point number.    |
6796e41f4b71Sopenharmony_ci| px          | number                  | Yes   |  X coordinate of the rotation point. The value is a floating point number.     |
6797e41f4b71Sopenharmony_ci| py          | number                  | Yes   |  Y coordinate of the rotation point. The value is a floating point number.     |
6798e41f4b71Sopenharmony_ci
6799e41f4b71Sopenharmony_ci**Error codes**
6800e41f4b71Sopenharmony_ci
6801e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6802e41f4b71Sopenharmony_ci
6803e41f4b71Sopenharmony_ci| ID| Error Message|
6804e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
6805e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6806e41f4b71Sopenharmony_ci
6807e41f4b71Sopenharmony_ci**Example**
6808e41f4b71Sopenharmony_ci
6809e41f4b71Sopenharmony_ci```ts
6810e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
6811e41f4b71Sopenharmony_ci
6812e41f4b71Sopenharmony_cilet matrix = new drawing.Matrix();
6813e41f4b71Sopenharmony_cimatrix.setScale(100, 100, 150, 150);
6814e41f4b71Sopenharmony_ci```
6815e41f4b71Sopenharmony_ci
6816e41f4b71Sopenharmony_ci### setTranslation<sup>12+</sup>
6817e41f4b71Sopenharmony_ci
6818e41f4b71Sopenharmony_cisetTranslation(dx: number, dy: number): void
6819e41f4b71Sopenharmony_ci
6820e41f4b71Sopenharmony_ciSets this matrix as an identity matrix and translates it by a given distance (dx, dy).
6821e41f4b71Sopenharmony_ci
6822e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6823e41f4b71Sopenharmony_ci
6824e41f4b71Sopenharmony_ci**Parameters**
6825e41f4b71Sopenharmony_ci
6826e41f4b71Sopenharmony_ci| Name        | Type                                      | Mandatory  | Description                 |
6827e41f4b71Sopenharmony_ci| ----------- | ---------------------------------------- | ---- | ------------------- |
6828e41f4b71Sopenharmony_ci| dx          | number                  | Yes   | Horizontal distance to translate. A positive number indicates a translation towards the positive direction of the X axis, and a negative number indicates a translation towards the negative direction of the X axis. The value is a floating point number.    |
6829e41f4b71Sopenharmony_ci| dy          | number                  | Yes   | Vertical distance to translate. A positive number indicates a translation towards the positive direction of the Y axis, and a negative number indicates a translation towards the negative direction of the Y axis. The value is a floating point number.    |
6830e41f4b71Sopenharmony_ci
6831e41f4b71Sopenharmony_ci**Error codes**
6832e41f4b71Sopenharmony_ci
6833e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6834e41f4b71Sopenharmony_ci
6835e41f4b71Sopenharmony_ci| ID| Error Message|
6836e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
6837e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6838e41f4b71Sopenharmony_ci
6839e41f4b71Sopenharmony_ci**Example**
6840e41f4b71Sopenharmony_ci
6841e41f4b71Sopenharmony_ci```ts
6842e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
6843e41f4b71Sopenharmony_ci
6844e41f4b71Sopenharmony_cilet matrix = new drawing.Matrix();
6845e41f4b71Sopenharmony_cimatrix.setTranslation(100, 100);
6846e41f4b71Sopenharmony_ci```
6847e41f4b71Sopenharmony_ci
6848e41f4b71Sopenharmony_ci### setMatrix<sup>12+</sup>
6849e41f4b71Sopenharmony_ci
6850e41f4b71Sopenharmony_cisetMatrix(values: Array\<number>): void
6851e41f4b71Sopenharmony_ci
6852e41f4b71Sopenharmony_ciSets parameters for this matrix.
6853e41f4b71Sopenharmony_ci
6854e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6855e41f4b71Sopenharmony_ci
6856e41f4b71Sopenharmony_ci**Parameters**
6857e41f4b71Sopenharmony_ci
6858e41f4b71Sopenharmony_ci| Name| Type                                                | Mandatory| Description            |
6859e41f4b71Sopenharmony_ci| ------ | ---------------------------------------------------- | ---- | ---------------- |
6860e41f4b71Sopenharmony_ci| values  | Array\<number> | Yes  | Floating-point array that holds the parameter values, with the array length set to 9. The values in the array respectively represent a horizontal scale coefficient, a horizontal skew coefficient, a horizontal translation coefficient, a vertical skew coefficient, a vertical scale coefficient, a vertical translation coefficient, an X-axis perspective coefficient, a Y-axis perspective coefficient, and a perspective scale coefficient, in ascending order of indexes.|
6861e41f4b71Sopenharmony_ci
6862e41f4b71Sopenharmony_ci**Error codes**
6863e41f4b71Sopenharmony_ci
6864e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6865e41f4b71Sopenharmony_ci
6866e41f4b71Sopenharmony_ci| ID| Error Message|
6867e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
6868e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; 3. Parameter verification failed. |
6869e41f4b71Sopenharmony_ci
6870e41f4b71Sopenharmony_ci**Example**
6871e41f4b71Sopenharmony_ci
6872e41f4b71Sopenharmony_ci```ts
6873e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
6874e41f4b71Sopenharmony_ci
6875e41f4b71Sopenharmony_cilet matrix = new drawing.Matrix();
6876e41f4b71Sopenharmony_cilet value : Array<number> = [2, 2, 2, 2, 2, 2, 2, 2, 2];
6877e41f4b71Sopenharmony_cimatrix.setMatrix(value);
6878e41f4b71Sopenharmony_ci```
6879e41f4b71Sopenharmony_ci
6880e41f4b71Sopenharmony_ci### preConcat<sup>12+</sup>
6881e41f4b71Sopenharmony_ci
6882e41f4b71Sopenharmony_cipreConcat(matrix: Matrix): void
6883e41f4b71Sopenharmony_ci
6884e41f4b71Sopenharmony_ciPreconcats the existing matrix with the passed-in matrix.
6885e41f4b71Sopenharmony_ci
6886e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6887e41f4b71Sopenharmony_ci
6888e41f4b71Sopenharmony_ci**Parameters**
6889e41f4b71Sopenharmony_ci
6890e41f4b71Sopenharmony_ci| Name| Type                                                | Mandatory| Description            |
6891e41f4b71Sopenharmony_ci| ------ | ---------------------------------------------------- | ---- | ---------------- |
6892e41f4b71Sopenharmony_ci| matrix  | [Matrix](#matrix12) | Yes  | **Matrix** object, which is on the right of a multiplication expression.|
6893e41f4b71Sopenharmony_ci
6894e41f4b71Sopenharmony_ci**Error codes**
6895e41f4b71Sopenharmony_ci
6896e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6897e41f4b71Sopenharmony_ci
6898e41f4b71Sopenharmony_ci| ID| Error Message|
6899e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
6900e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6901e41f4b71Sopenharmony_ci
6902e41f4b71Sopenharmony_ci**Example**
6903e41f4b71Sopenharmony_ci
6904e41f4b71Sopenharmony_ci```ts
6905e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
6906e41f4b71Sopenharmony_ci
6907e41f4b71Sopenharmony_cilet matrix1 = new drawing.Matrix();
6908e41f4b71Sopenharmony_cimatrix1.setMatrix([2, 1, 3, 1, 2, 1, 3, 1, 2]);
6909e41f4b71Sopenharmony_cilet matrix2 = new drawing.Matrix();
6910e41f4b71Sopenharmony_cimatrix2.setMatrix([-2, 1, 3, 1, 0, -1, 3, -1, 2]);
6911e41f4b71Sopenharmony_cimatrix1.preConcat(matrix2);
6912e41f4b71Sopenharmony_ci```
6913e41f4b71Sopenharmony_ci
6914e41f4b71Sopenharmony_ci### isEqual<sup>12+</sup>
6915e41f4b71Sopenharmony_ci
6916e41f4b71Sopenharmony_ciisEqual(matrix: Matrix): Boolean
6917e41f4b71Sopenharmony_ci
6918e41f4b71Sopenharmony_ciChecks whether this matrix is equal to another matrix.
6919e41f4b71Sopenharmony_ci
6920e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6921e41f4b71Sopenharmony_ci
6922e41f4b71Sopenharmony_ci**Parameters**
6923e41f4b71Sopenharmony_ci
6924e41f4b71Sopenharmony_ci| Name| Type                                                | Mandatory| Description            |
6925e41f4b71Sopenharmony_ci| ------ | ---------------------------------------------------- | ---- | ---------------- |
6926e41f4b71Sopenharmony_ci| matrix  | [Matrix](#matrix12) | Yes  | Matrix to compare.|
6927e41f4b71Sopenharmony_ci
6928e41f4b71Sopenharmony_ci**Return value**
6929e41f4b71Sopenharmony_ci
6930e41f4b71Sopenharmony_ci| Type                       | Description                 |
6931e41f4b71Sopenharmony_ci| --------------------------- | -------------------- |
6932e41f4b71Sopenharmony_ci| Boolean | Comparison result of the two matrices. The value **true** means that the two matrices are equal, and **false** means the opposite.|
6933e41f4b71Sopenharmony_ci
6934e41f4b71Sopenharmony_ci**Error codes**
6935e41f4b71Sopenharmony_ci
6936e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6937e41f4b71Sopenharmony_ci
6938e41f4b71Sopenharmony_ci| ID| Error Message|
6939e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
6940e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6941e41f4b71Sopenharmony_ci
6942e41f4b71Sopenharmony_ci**Example**
6943e41f4b71Sopenharmony_ci
6944e41f4b71Sopenharmony_ci```ts
6945e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
6946e41f4b71Sopenharmony_ci
6947e41f4b71Sopenharmony_cilet matrix1 = new drawing.Matrix();
6948e41f4b71Sopenharmony_cimatrix1.setMatrix([2, 1, 3, 1, 2, 1, 3, 1, 2]);
6949e41f4b71Sopenharmony_cilet matrix2 = new drawing.Matrix();
6950e41f4b71Sopenharmony_cimatrix2.setMatrix([-2, 1, 3, 1, 0, -1, 3, -1, 2]);
6951e41f4b71Sopenharmony_ciif (matrix1.isEqual(matrix2)) {
6952e41f4b71Sopenharmony_ci  console.info("matrix1 and matrix2 are equal.");
6953e41f4b71Sopenharmony_ci} else {
6954e41f4b71Sopenharmony_ci  console.info("matrix1 and matrix2 are not equal.");
6955e41f4b71Sopenharmony_ci}
6956e41f4b71Sopenharmony_ci```
6957e41f4b71Sopenharmony_ci
6958e41f4b71Sopenharmony_ci### invert<sup>12+</sup>
6959e41f4b71Sopenharmony_ci
6960e41f4b71Sopenharmony_ciinvert(matrix: Matrix): Boolean
6961e41f4b71Sopenharmony_ci
6962e41f4b71Sopenharmony_ciInverts this matrix and returns the result.
6963e41f4b71Sopenharmony_ci
6964e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
6965e41f4b71Sopenharmony_ci
6966e41f4b71Sopenharmony_ci**Parameters**
6967e41f4b71Sopenharmony_ci
6968e41f4b71Sopenharmony_ci| Name| Type                                                | Mandatory| Description            |
6969e41f4b71Sopenharmony_ci| ------ | ---------------------------------------------------- | ---- | ---------------- |
6970e41f4b71Sopenharmony_ci| matrix  | [Matrix](#matrix12) | Yes  | **Matrix** object used to store the inverted matrix.|
6971e41f4b71Sopenharmony_ci
6972e41f4b71Sopenharmony_ci**Return value**
6973e41f4b71Sopenharmony_ci
6974e41f4b71Sopenharmony_ci| Type                       | Description                 |
6975e41f4b71Sopenharmony_ci| --------------------------- | -------------------- |
6976e41f4b71Sopenharmony_ci| Boolean | Result indicating whether the matrix is revertible. The value **true** means that the matrix is revertible and the **matrix** object is filled with the inverted matrix, and **false** means that the matrix is not revertible and the **matrix** object is filled with the current matrix (not changed).|
6977e41f4b71Sopenharmony_ci
6978e41f4b71Sopenharmony_ci**Error codes**
6979e41f4b71Sopenharmony_ci
6980e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6981e41f4b71Sopenharmony_ci
6982e41f4b71Sopenharmony_ci| ID| Error Message|
6983e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
6984e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6985e41f4b71Sopenharmony_ci
6986e41f4b71Sopenharmony_ci**Example**
6987e41f4b71Sopenharmony_ci
6988e41f4b71Sopenharmony_ci```ts
6989e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
6990e41f4b71Sopenharmony_ci
6991e41f4b71Sopenharmony_cilet matrix1 = new drawing.Matrix();
6992e41f4b71Sopenharmony_cimatrix1.setMatrix([2, 1, 3, 1, 2, 1, 3, 1, 2]);
6993e41f4b71Sopenharmony_cilet matrix2 = new drawing.Matrix();
6994e41f4b71Sopenharmony_cimatrix2.setMatrix([-2, 1, 3, 1, 0, -1, 3, -1, 2]);
6995e41f4b71Sopenharmony_ciif (matrix1.invert(matrix2)) {
6996e41f4b71Sopenharmony_ci  console.info("matrix1 is invertible and matrix2 is set as an inverse matrix of the matrix1.");
6997e41f4b71Sopenharmony_ci} else {
6998e41f4b71Sopenharmony_ci  console.info("matrix1 is not invertible and matrix2 is not changed.");
6999e41f4b71Sopenharmony_ci}
7000e41f4b71Sopenharmony_ci```
7001e41f4b71Sopenharmony_ci
7002e41f4b71Sopenharmony_ci### isIdentity<sup>12+</sup>
7003e41f4b71Sopenharmony_ci
7004e41f4b71Sopenharmony_ciisIdentity(): Boolean
7005e41f4b71Sopenharmony_ci
7006e41f4b71Sopenharmony_ciChecks whether this matrix is an identity matrix.
7007e41f4b71Sopenharmony_ci
7008e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7009e41f4b71Sopenharmony_ci
7010e41f4b71Sopenharmony_ci**Return value**
7011e41f4b71Sopenharmony_ci
7012e41f4b71Sopenharmony_ci| Type                       | Description                 |
7013e41f4b71Sopenharmony_ci| --------------------------- | -------------------- |
7014e41f4b71Sopenharmony_ci| Boolean | Result indicating whether the matrix is an identity matrix. The value **true** means that the matrix is an identity matrix, and **false** means the opposite.|
7015e41f4b71Sopenharmony_ci
7016e41f4b71Sopenharmony_ci**Example**
7017e41f4b71Sopenharmony_ci
7018e41f4b71Sopenharmony_ci```ts
7019e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
7020e41f4b71Sopenharmony_ci
7021e41f4b71Sopenharmony_cilet matrix = new drawing.Matrix();
7022e41f4b71Sopenharmony_ciif (matrix.isIdentity()) {
7023e41f4b71Sopenharmony_ci  console.info("matrix is identity.");
7024e41f4b71Sopenharmony_ci} else {
7025e41f4b71Sopenharmony_ci  console.info("matrix is not identity.");
7026e41f4b71Sopenharmony_ci}
7027e41f4b71Sopenharmony_ci```
7028e41f4b71Sopenharmony_ci
7029e41f4b71Sopenharmony_ci### getValue<sup>12+</sup>
7030e41f4b71Sopenharmony_ci
7031e41f4b71Sopenharmony_cigetValue(index: number): number
7032e41f4b71Sopenharmony_ci
7033e41f4b71Sopenharmony_ciObtains the value of a given index in this matrix. The index ranges from 0 to 8.
7034e41f4b71Sopenharmony_ci
7035e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7036e41f4b71Sopenharmony_ci
7037e41f4b71Sopenharmony_ci**Parameters**
7038e41f4b71Sopenharmony_ci
7039e41f4b71Sopenharmony_ci| Name         | Type   | Mandatory| Description                                                       |
7040e41f4b71Sopenharmony_ci| --------------- | ------- | ---- | ----------------------------------------------------------- |
7041e41f4b71Sopenharmony_ci| index | number | Yes  | Index. The value is an integer ranging from 0 to 8.|
7042e41f4b71Sopenharmony_ci
7043e41f4b71Sopenharmony_ci**Return value**
7044e41f4b71Sopenharmony_ci
7045e41f4b71Sopenharmony_ci| Type                 | Description          |
7046e41f4b71Sopenharmony_ci| --------------------- | -------------- |
7047e41f4b71Sopenharmony_ci| number | Value obtained, which is an integer.|
7048e41f4b71Sopenharmony_ci
7049e41f4b71Sopenharmony_ci**Error codes**
7050e41f4b71Sopenharmony_ci
7051e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7052e41f4b71Sopenharmony_ci
7053e41f4b71Sopenharmony_ci| ID| Error Message|
7054e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
7055e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed.|
7056e41f4b71Sopenharmony_ci
7057e41f4b71Sopenharmony_ci**Example**
7058e41f4b71Sopenharmony_ci
7059e41f4b71Sopenharmony_ci```ts
7060e41f4b71Sopenharmony_ciimport {drawing} from "@kit.ArkGraphics2D"
7061e41f4b71Sopenharmony_cilet matrix = new drawing.Matrix();
7062e41f4b71Sopenharmony_cifor (let i = 0; i < 9; i++) {
7063e41f4b71Sopenharmony_ci    console.info("matrix "+matrix.getValue(i).toString());
7064e41f4b71Sopenharmony_ci}
7065e41f4b71Sopenharmony_ci```
7066e41f4b71Sopenharmony_ci
7067e41f4b71Sopenharmony_ci### postRotate<sup>12+</sup>
7068e41f4b71Sopenharmony_ci
7069e41f4b71Sopenharmony_cipostRotate(degree: number, px: number, py: number): void
7070e41f4b71Sopenharmony_ci
7071e41f4b71Sopenharmony_ciPost multiplies this matrix by a matrix that is derived from an identity matrix after it has been rotated by a given degree around the rotation point (px, py).
7072e41f4b71Sopenharmony_ci
7073e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7074e41f4b71Sopenharmony_ci
7075e41f4b71Sopenharmony_ci**Parameters**
7076e41f4b71Sopenharmony_ci
7077e41f4b71Sopenharmony_ci| Name         | Type   | Mandatory| Description                                                       |
7078e41f4b71Sopenharmony_ci| --------------- | ------- | ---- | ----------------------------------------------------------- |
7079e41f4b71Sopenharmony_ci| degree | number | Yes  | Angle to rotate, in degrees. A positive number indicates a clockwise rotation, and a negative number indicates a counterclockwise rotation. The value is a floating point number.|
7080e41f4b71Sopenharmony_ci| px | number | Yes  | X coordinate of the rotation point. The value is a floating point number.|
7081e41f4b71Sopenharmony_ci| py | number | Yes  | Y coordinate of the rotation point. The value is a floating point number.|
7082e41f4b71Sopenharmony_ci
7083e41f4b71Sopenharmony_ci**Error codes**
7084e41f4b71Sopenharmony_ci
7085e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7086e41f4b71Sopenharmony_ci
7087e41f4b71Sopenharmony_ci| ID| Error Message|
7088e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
7089e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7090e41f4b71Sopenharmony_ci
7091e41f4b71Sopenharmony_ci**Example**
7092e41f4b71Sopenharmony_ci
7093e41f4b71Sopenharmony_ci```ts
7094e41f4b71Sopenharmony_ciimport {drawing} from "@kit.ArkGraphics2D"
7095e41f4b71Sopenharmony_cilet matrix = new drawing.Matrix();
7096e41f4b71Sopenharmony_cilet degree: number = 2;
7097e41f4b71Sopenharmony_cilet px: number = 3;
7098e41f4b71Sopenharmony_cilet py: number = 4;
7099e41f4b71Sopenharmony_cimatrix.postRotate(degree, px, py);
7100e41f4b71Sopenharmony_ciconsole.info("matrix= "+matrix.getAll().toString());
7101e41f4b71Sopenharmony_ci```
7102e41f4b71Sopenharmony_ci
7103e41f4b71Sopenharmony_ci### postScale<sup>12+</sup>
7104e41f4b71Sopenharmony_ci
7105e41f4b71Sopenharmony_cipostScale(sx: number, sy: number, px: number, py: number): void
7106e41f4b71Sopenharmony_ci
7107e41f4b71Sopenharmony_ciPost multiplies this matrix by a matrix that is derived from an identity matrix after it has been scaled with the coefficient (sx, sy) at the scale point (px, py).
7108e41f4b71Sopenharmony_ci
7109e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7110e41f4b71Sopenharmony_ci
7111e41f4b71Sopenharmony_ci**Parameters**
7112e41f4b71Sopenharmony_ci
7113e41f4b71Sopenharmony_ci| Name         | Type   | Mandatory| Description                                                       |
7114e41f4b71Sopenharmony_ci| --------------- | ------- | ---- | ----------------------------------------------------------- |
7115e41f4b71Sopenharmony_ci| sx | number | Yes  | Scale coefficient along the X axis. If a negative number is passed in, the matrix is mirrored around y = px before being scaled. The value is a floating point number.|
7116e41f4b71Sopenharmony_ci| sy | number | Yes  | Scale coefficient along the Y axis. If a negative number is passed in, the matrix is mirrored around x = py before being scaled. The value is a floating point number.|
7117e41f4b71Sopenharmony_ci| px | number | Yes  | X coordinate of the scale point. The value is a floating point number.|
7118e41f4b71Sopenharmony_ci| py | number | Yes  | Y coordinate of the scale point. The value is a floating point number.|
7119e41f4b71Sopenharmony_ci
7120e41f4b71Sopenharmony_ci**Error codes**
7121e41f4b71Sopenharmony_ci
7122e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7123e41f4b71Sopenharmony_ci
7124e41f4b71Sopenharmony_ci| ID| Error Message|
7125e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
7126e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7127e41f4b71Sopenharmony_ci
7128e41f4b71Sopenharmony_ci**Example**
7129e41f4b71Sopenharmony_ci
7130e41f4b71Sopenharmony_ci```ts
7131e41f4b71Sopenharmony_ciimport {drawing} from "@kit.ArkGraphics2D"
7132e41f4b71Sopenharmony_cilet matrix = new drawing.Matrix();
7133e41f4b71Sopenharmony_cilet sx: number = 2;
7134e41f4b71Sopenharmony_cilet sy: number = 0.5;
7135e41f4b71Sopenharmony_cilet px: number = 1;
7136e41f4b71Sopenharmony_cilet py: number = 1;
7137e41f4b71Sopenharmony_cimatrix.postScale(sx, sy, px, py);
7138e41f4b71Sopenharmony_ciconsole.info("matrix= "+matrix.getAll().toString());
7139e41f4b71Sopenharmony_ci```
7140e41f4b71Sopenharmony_ci
7141e41f4b71Sopenharmony_ci### postTranslate<sup>12+</sup>
7142e41f4b71Sopenharmony_ci
7143e41f4b71Sopenharmony_cipostTranslate(dx: number, dy: number): void
7144e41f4b71Sopenharmony_ci
7145e41f4b71Sopenharmony_ciPost multiplies this matrix by a matrix that is derived from an identity matrix after it has been translated by a given distance (dx, dy).
7146e41f4b71Sopenharmony_ci
7147e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7148e41f4b71Sopenharmony_ci
7149e41f4b71Sopenharmony_ci**Parameters**
7150e41f4b71Sopenharmony_ci
7151e41f4b71Sopenharmony_ci| Name         | Type   | Mandatory| Description                                                       |
7152e41f4b71Sopenharmony_ci| --------------- | ------- | ---- | ----------------------------------------------------------- |
7153e41f4b71Sopenharmony_ci| dx | number | Yes  | Horizontal distance to translate. A positive number indicates a translation towards the positive direction of the X axis, and a negative number indicates a translation towards the negative direction of the X axis. The value is a floating point number.|
7154e41f4b71Sopenharmony_ci| dy | number | Yes  | Vertical distance to translate. A positive number indicates a translation towards the positive direction of the Y axis, and a negative number indicates a translation towards the negative direction of the Y axis. The value is a floating point number.|
7155e41f4b71Sopenharmony_ci
7156e41f4b71Sopenharmony_ci**Error codes**
7157e41f4b71Sopenharmony_ci
7158e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7159e41f4b71Sopenharmony_ci
7160e41f4b71Sopenharmony_ci| ID| Error Message|
7161e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
7162e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7163e41f4b71Sopenharmony_ci
7164e41f4b71Sopenharmony_ci**Example**
7165e41f4b71Sopenharmony_ci
7166e41f4b71Sopenharmony_ci```ts
7167e41f4b71Sopenharmony_ciimport {drawing} from "@kit.ArkGraphics2D"
7168e41f4b71Sopenharmony_cilet matrix = new drawing.Matrix();
7169e41f4b71Sopenharmony_cilet dx: number = 3;
7170e41f4b71Sopenharmony_cilet dy: number = 4;
7171e41f4b71Sopenharmony_cimatrix.postTranslate(dx, dy);
7172e41f4b71Sopenharmony_ciconsole.info("matrix= "+matrix.getAll().toString());
7173e41f4b71Sopenharmony_ci```
7174e41f4b71Sopenharmony_ci
7175e41f4b71Sopenharmony_ci### preRotate<sup>12+</sup>
7176e41f4b71Sopenharmony_ci
7177e41f4b71Sopenharmony_cipreRotate(degree: number, px: number, py: number): void
7178e41f4b71Sopenharmony_ci
7179e41f4b71Sopenharmony_ciPremultiplies this matrix by a matrix that is derived from an identity matrix after it has been rotated by a given degree around the rotation point (px, py).
7180e41f4b71Sopenharmony_ci
7181e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7182e41f4b71Sopenharmony_ci
7183e41f4b71Sopenharmony_ci**Parameters**
7184e41f4b71Sopenharmony_ci
7185e41f4b71Sopenharmony_ci| Name         | Type   | Mandatory| Description                                                       |
7186e41f4b71Sopenharmony_ci| --------------- | ------- | ---- | ----------------------------------------------------------- |
7187e41f4b71Sopenharmony_ci| degree | number | Yes  | Angle to rotate, in degrees. A positive number indicates a clockwise rotation, and a negative number indicates a counterclockwise rotation. The value is a floating point number.|
7188e41f4b71Sopenharmony_ci| px | number | Yes  | X coordinate of the rotation point. The value is a floating point number.|
7189e41f4b71Sopenharmony_ci| py | number | Yes  | Y coordinate of the rotation point. The value is a floating point number.|
7190e41f4b71Sopenharmony_ci
7191e41f4b71Sopenharmony_ci**Error codes**
7192e41f4b71Sopenharmony_ci
7193e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7194e41f4b71Sopenharmony_ci
7195e41f4b71Sopenharmony_ci| ID| Error Message|
7196e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
7197e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7198e41f4b71Sopenharmony_ci
7199e41f4b71Sopenharmony_ci**Example**
7200e41f4b71Sopenharmony_ci
7201e41f4b71Sopenharmony_ci```ts
7202e41f4b71Sopenharmony_ciimport {drawing} from "@kit.ArkGraphics2D"
7203e41f4b71Sopenharmony_cilet matrix = new drawing.Matrix();
7204e41f4b71Sopenharmony_cilet degree: number = 2;
7205e41f4b71Sopenharmony_cilet px: number = 3;
7206e41f4b71Sopenharmony_cilet py: number = 4;
7207e41f4b71Sopenharmony_cimatrix.preRotate(degree, px, py);
7208e41f4b71Sopenharmony_ciconsole.info("matrix= "+matrix.getAll().toString());
7209e41f4b71Sopenharmony_ci```
7210e41f4b71Sopenharmony_ci
7211e41f4b71Sopenharmony_ci### preScale<sup>12+</sup>
7212e41f4b71Sopenharmony_ci
7213e41f4b71Sopenharmony_cipreScale(sx: number, sy: number, px: number, py: number): void
7214e41f4b71Sopenharmony_ci
7215e41f4b71Sopenharmony_ciPremultiplies this matrix by a matrix that is derived from an identity matrix after it has been scaled with the coefficient (sx, sy) at the scale point (px, py).
7216e41f4b71Sopenharmony_ci
7217e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7218e41f4b71Sopenharmony_ci
7219e41f4b71Sopenharmony_ci**Parameters**
7220e41f4b71Sopenharmony_ci
7221e41f4b71Sopenharmony_ci| Name         | Type   | Mandatory| Description                                                       |
7222e41f4b71Sopenharmony_ci| --------------- | ------- | ---- | ----------------------------------------------------------- |
7223e41f4b71Sopenharmony_ci| sx | number | Yes  | Scale coefficient along the X axis. If a negative number is passed in, the matrix is mirrored around y = px before being scaled. The value is a floating point number.|
7224e41f4b71Sopenharmony_ci| sy | number | Yes  | Scale coefficient along the Y axis. If a negative number is passed in, the matrix is mirrored around x = py before being scaled. The value is a floating point number.|
7225e41f4b71Sopenharmony_ci| px | number | Yes  | X coordinate of the scale point. The value is a floating point number.|
7226e41f4b71Sopenharmony_ci| py | number | Yes  | Y coordinate of the scale point. The value is a floating point number.|
7227e41f4b71Sopenharmony_ci
7228e41f4b71Sopenharmony_ci**Error codes**
7229e41f4b71Sopenharmony_ci
7230e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7231e41f4b71Sopenharmony_ci
7232e41f4b71Sopenharmony_ci| ID| Error Message|
7233e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
7234e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7235e41f4b71Sopenharmony_ci
7236e41f4b71Sopenharmony_ci**Example**
7237e41f4b71Sopenharmony_ci
7238e41f4b71Sopenharmony_ci```ts
7239e41f4b71Sopenharmony_ciimport {drawing} from "@kit.ArkGraphics2D"
7240e41f4b71Sopenharmony_cilet matrix = new drawing.Matrix();
7241e41f4b71Sopenharmony_cilet sx: number = 2;
7242e41f4b71Sopenharmony_cilet sy: number = 0.5;
7243e41f4b71Sopenharmony_cilet px: number = 1;
7244e41f4b71Sopenharmony_cilet py: number = 1;
7245e41f4b71Sopenharmony_cimatrix.preScale(sx, sy, px, py);
7246e41f4b71Sopenharmony_ciconsole.info("matrix"+matrix.getAll().toString());
7247e41f4b71Sopenharmony_ci```
7248e41f4b71Sopenharmony_ci
7249e41f4b71Sopenharmony_ci### preTranslate<sup>12+</sup>
7250e41f4b71Sopenharmony_ci
7251e41f4b71Sopenharmony_cipreTranslate(dx: number, dy: number): void
7252e41f4b71Sopenharmony_ci
7253e41f4b71Sopenharmony_ciPremultiplies a matrix by a matrix that is derived from an identity matrix after it has been translated by a given distance (dx, dy).
7254e41f4b71Sopenharmony_ci
7255e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7256e41f4b71Sopenharmony_ci
7257e41f4b71Sopenharmony_ci**Parameters**
7258e41f4b71Sopenharmony_ci
7259e41f4b71Sopenharmony_ci| Name         | Type   | Mandatory| Description                                                       |
7260e41f4b71Sopenharmony_ci| --------------- | ------- | ---- | ----------------------------------------------------------- |
7261e41f4b71Sopenharmony_ci| dx | number | Yes  | Horizontal distance to translate. A positive number indicates a translation towards the positive direction of the X axis, and a negative number indicates a translation towards the negative direction of the X axis. The value is a floating point number.|
7262e41f4b71Sopenharmony_ci| dy | number | Yes  | Vertical distance to translate. A positive number indicates a translation towards the positive direction of the Y axis, and a negative number indicates a translation towards the negative direction of the Y axis. The value is a floating point number.|
7263e41f4b71Sopenharmony_ci
7264e41f4b71Sopenharmony_ci**Error codes**
7265e41f4b71Sopenharmony_ci
7266e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7267e41f4b71Sopenharmony_ci
7268e41f4b71Sopenharmony_ci| ID| Error Message|
7269e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
7270e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7271e41f4b71Sopenharmony_ci
7272e41f4b71Sopenharmony_ci**Example**
7273e41f4b71Sopenharmony_ci
7274e41f4b71Sopenharmony_ci```ts
7275e41f4b71Sopenharmony_ciimport {drawing} from "@kit.ArkGraphics2D"
7276e41f4b71Sopenharmony_cilet matrix = new drawing.Matrix();
7277e41f4b71Sopenharmony_cilet dx: number = 3;
7278e41f4b71Sopenharmony_cilet dy: number = 4;
7279e41f4b71Sopenharmony_cimatrix.preTranslate(dx, dy);
7280e41f4b71Sopenharmony_ciconsole.info("matrix"+matrix.getAll().toString());
7281e41f4b71Sopenharmony_ci```
7282e41f4b71Sopenharmony_ci
7283e41f4b71Sopenharmony_ci### reset<sup>12+</sup>
7284e41f4b71Sopenharmony_ci
7285e41f4b71Sopenharmony_cireset(): void
7286e41f4b71Sopenharmony_ci
7287e41f4b71Sopenharmony_ciResets this matrix to an identity matrix.
7288e41f4b71Sopenharmony_ci
7289e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7290e41f4b71Sopenharmony_ci
7291e41f4b71Sopenharmony_ci**Example**
7292e41f4b71Sopenharmony_ci
7293e41f4b71Sopenharmony_ci```ts
7294e41f4b71Sopenharmony_ciimport {drawing} from "@kit.ArkGraphics2D"
7295e41f4b71Sopenharmony_cilet matrix = new drawing.Matrix();
7296e41f4b71Sopenharmony_cimatrix.postScale(2, 3, 4, 5);
7297e41f4b71Sopenharmony_cimatrix.reset();
7298e41f4b71Sopenharmony_ciconsole.info("matrix= "+matrix.getAll().toString());
7299e41f4b71Sopenharmony_ci```
7300e41f4b71Sopenharmony_ci
7301e41f4b71Sopenharmony_ci### mapPoints<sup>12+</sup>
7302e41f4b71Sopenharmony_ci
7303e41f4b71Sopenharmony_cimapPoints(src: Array\<common2D.Point>): Array\<common2D.Point>
7304e41f4b71Sopenharmony_ci
7305e41f4b71Sopenharmony_ciMaps a source point array to a destination point array by means of matrix transformation.
7306e41f4b71Sopenharmony_ci
7307e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7308e41f4b71Sopenharmony_ci
7309e41f4b71Sopenharmony_ci**Parameters**
7310e41f4b71Sopenharmony_ci
7311e41f4b71Sopenharmony_ci| Name         | Type   | Mandatory| Description                                                       |
7312e41f4b71Sopenharmony_ci| --------------- | ------- | ---- | ----------------------------------------------------------- |
7313e41f4b71Sopenharmony_ci| src | Array\<[common2D.Point](js-apis-graphics-common2D.md#point)> | Yes  | Array of source points.|
7314e41f4b71Sopenharmony_ci
7315e41f4b71Sopenharmony_ci**Return value**
7316e41f4b71Sopenharmony_ci
7317e41f4b71Sopenharmony_ci| Type                 | Description          |
7318e41f4b71Sopenharmony_ci| --------------------- | -------------- |
7319e41f4b71Sopenharmony_ci| Array\<[common2D.Point](js-apis-graphics-common2D.md#point)> | Array of points obtained.|
7320e41f4b71Sopenharmony_ci
7321e41f4b71Sopenharmony_ci**Error codes**
7322e41f4b71Sopenharmony_ci
7323e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7324e41f4b71Sopenharmony_ci
7325e41f4b71Sopenharmony_ci| ID| Error Message|
7326e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
7327e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7328e41f4b71Sopenharmony_ci
7329e41f4b71Sopenharmony_ci**Example**
7330e41f4b71Sopenharmony_ci
7331e41f4b71Sopenharmony_ci```ts
7332e41f4b71Sopenharmony_ciimport {drawing,common2D} from "@kit.ArkGraphics2D"
7333e41f4b71Sopenharmony_cilet src: Array<common2D.Point> = [];
7334e41f4b71Sopenharmony_cisrc.push({x: 15, y: 20});
7335e41f4b71Sopenharmony_cisrc.push({x: 20, y: 15});
7336e41f4b71Sopenharmony_cisrc.push({x: 30, y: 10});
7337e41f4b71Sopenharmony_cilet matrix = new drawing.Matrix();
7338e41f4b71Sopenharmony_cilet dst: Array<common2D.Point> = matrix.mapPoints(src);
7339e41f4b71Sopenharmony_ciconsole.info("matrix= src: "+JSON.stringify(src));
7340e41f4b71Sopenharmony_ciconsole.info("matrix= dst: "+JSON.stringify(dst));
7341e41f4b71Sopenharmony_ci```
7342e41f4b71Sopenharmony_ci
7343e41f4b71Sopenharmony_ci### getAll<sup>12+</sup>
7344e41f4b71Sopenharmony_ci
7345e41f4b71Sopenharmony_cigetAll(): Array\<number>
7346e41f4b71Sopenharmony_ci
7347e41f4b71Sopenharmony_ciObtains all element values of this matrix.
7348e41f4b71Sopenharmony_ci
7349e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7350e41f4b71Sopenharmony_ci
7351e41f4b71Sopenharmony_ci**Return value**
7352e41f4b71Sopenharmony_ci
7353e41f4b71Sopenharmony_ci| Type                 | Description          |
7354e41f4b71Sopenharmony_ci| --------------------- | -------------- |
7355e41f4b71Sopenharmony_ci| Array\<number> | Array of matrix values obtained. The length is 9. Each value is a floating point number.|
7356e41f4b71Sopenharmony_ci
7357e41f4b71Sopenharmony_ci**Example**
7358e41f4b71Sopenharmony_ci
7359e41f4b71Sopenharmony_ci```ts
7360e41f4b71Sopenharmony_ciimport {drawing} from "@kit.ArkGraphics2D"
7361e41f4b71Sopenharmony_cilet matrix = new drawing.Matrix();
7362e41f4b71Sopenharmony_ciconsole.info("matrix "+ matrix.getAll());
7363e41f4b71Sopenharmony_ci```
7364e41f4b71Sopenharmony_ci
7365e41f4b71Sopenharmony_ci### mapRect<sup>12+</sup>
7366e41f4b71Sopenharmony_ci
7367e41f4b71Sopenharmony_cimapRect(dst: common2D.Rect, src: common2D.Rect): boolean
7368e41f4b71Sopenharmony_ci
7369e41f4b71Sopenharmony_ciSets the destination rectangle to the bounding rectangle of the shape obtained after transforming the source rectangle with a matrix transformation. As shown in the figure below, the blue rectangle represents the source rectangle, and the yellow rectangle is the shape obtained after a matrix transformation is applied to the source rectangle. Since the edges of the yellow rectangle are not aligned with the coordinate axes, it cannot be represented by a rectangle object. To address this issue, a destination rectangle (black rectangle) is defined as the bounding rectangle.
7370e41f4b71Sopenharmony_ci
7371e41f4b71Sopenharmony_ci![mapRect](./figures/matrix_mapRect.png)
7372e41f4b71Sopenharmony_ci
7373e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7374e41f4b71Sopenharmony_ci
7375e41f4b71Sopenharmony_ci**Parameters**
7376e41f4b71Sopenharmony_ci
7377e41f4b71Sopenharmony_ci| Name         | Type   | Mandatory| Description                                                       |
7378e41f4b71Sopenharmony_ci| --------------- | ------- | ---- | ----------------------------------------------------------- |
7379e41f4b71Sopenharmony_ci| dst | [common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes  | **Rectangle** object, which is used to store the bounding rectangle.|
7380e41f4b71Sopenharmony_ci| src |[common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes  | Source rectangle.|
7381e41f4b71Sopenharmony_ci
7382e41f4b71Sopenharmony_ci**Return value**
7383e41f4b71Sopenharmony_ci
7384e41f4b71Sopenharmony_ci| Type                 | Description          |
7385e41f4b71Sopenharmony_ci| --------------------- | -------------- |
7386e41f4b71Sopenharmony_ci| boolean | Result indicating whether the shape, transformed from the source rectangle via a matrix transformation, retains a rectangular form. The value **true** means that the shape retains a rectangular form, and **false** means the opposite.|
7387e41f4b71Sopenharmony_ci
7388e41f4b71Sopenharmony_ci**Error codes**
7389e41f4b71Sopenharmony_ci
7390e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7391e41f4b71Sopenharmony_ci
7392e41f4b71Sopenharmony_ci| ID| Error Message|
7393e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
7394e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7395e41f4b71Sopenharmony_ci
7396e41f4b71Sopenharmony_ci**Example**
7397e41f4b71Sopenharmony_ci
7398e41f4b71Sopenharmony_ci```ts
7399e41f4b71Sopenharmony_ciimport {drawing,common2D} from "@kit.ArkGraphics2D"
7400e41f4b71Sopenharmony_cilet dst: common2D.Rect = { left: 100, top: 20, right: 130, bottom: 60 };
7401e41f4b71Sopenharmony_cilet src: common2D.Rect = { left: 100, top: 80, right: 130, bottom: 120 };
7402e41f4b71Sopenharmony_cilet matrix = new drawing.Matrix();
7403e41f4b71Sopenharmony_ciif (matrix.mapRect(dst, src)) {
7404e41f4b71Sopenharmony_ci    console.info("matrix= dst "+JSON.stringify(dst));
7405e41f4b71Sopenharmony_ci}
7406e41f4b71Sopenharmony_ci```
7407e41f4b71Sopenharmony_ci
7408e41f4b71Sopenharmony_ci### setRectToRect<sup>12+</sup>
7409e41f4b71Sopenharmony_ci
7410e41f4b71Sopenharmony_cisetRectToRect(src: common2D.Rect, dst: common2D.Rect, scaleToFit: ScaleToFit): boolean
7411e41f4b71Sopenharmony_ci
7412e41f4b71Sopenharmony_ciSets this matrix to a transformation matrix that maps a source rectangle to a destination rectangle.
7413e41f4b71Sopenharmony_ci
7414e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7415e41f4b71Sopenharmony_ci
7416e41f4b71Sopenharmony_ci**Parameters**
7417e41f4b71Sopenharmony_ci
7418e41f4b71Sopenharmony_ci| Name         | Type   | Mandatory| Description                                                       |
7419e41f4b71Sopenharmony_ci| --------------- | ------- | ---- | ----------------------------------------------------------- |
7420e41f4b71Sopenharmony_ci| src | [common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes  | Source rectangle.|
7421e41f4b71Sopenharmony_ci| dst | [common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes  | Destination rectangle.|
7422e41f4b71Sopenharmony_ci| scaleToFit | [ScaleToFit](#scaletofit12) | Yes  | Mapping mode from the source rectangle to the target rectangle.|
7423e41f4b71Sopenharmony_ci
7424e41f4b71Sopenharmony_ci**Return value**
7425e41f4b71Sopenharmony_ci
7426e41f4b71Sopenharmony_ci| Type                 | Description          |
7427e41f4b71Sopenharmony_ci| --------------------- | -------------- |
7428e41f4b71Sopenharmony_ci| boolean | Result indicating whether the matrix can represent the mapping between rectangles. The value **true** means that the matrix can represent the mapping, and **false** means the opposite. In particular, if either the width or the height of the source rectangle is less than or equal to 0, the API returns **false** and sets the matrix to an identity matrix. If either the width or height of the destination rectangle is less than or equal to 0, the API returns **true** and sets the matrix to a matrix with all values 0, except for a perspective scaling coefficient of 1.|
7429e41f4b71Sopenharmony_ci
7430e41f4b71Sopenharmony_ci**Error codes**
7431e41f4b71Sopenharmony_ci
7432e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7433e41f4b71Sopenharmony_ci
7434e41f4b71Sopenharmony_ci| ID| Error Message|
7435e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
7436e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
7437e41f4b71Sopenharmony_ci
7438e41f4b71Sopenharmony_ci**Example**
7439e41f4b71Sopenharmony_ci
7440e41f4b71Sopenharmony_ci```ts
7441e41f4b71Sopenharmony_ciimport {drawing,common2D} from "@kit.ArkGraphics2D"
7442e41f4b71Sopenharmony_cilet src: common2D.Rect = { left: 100, top: 100, right: 300, bottom: 300 };
7443e41f4b71Sopenharmony_cilet dst: common2D.Rect = { left: 200, top: 200, right: 600, bottom: 600 };
7444e41f4b71Sopenharmony_cilet scaleToFit: drawing.ScaleToFit = drawing.ScaleToFit.FILL_SCALE_TO_FIT
7445e41f4b71Sopenharmony_cilet matrix = new drawing.Matrix();
7446e41f4b71Sopenharmony_ciif (matrix.setRectToRect(src, dst, scaleToFit)) {
7447e41f4b71Sopenharmony_ci    console.info("matrix"+matrix.getAll().toString());
7448e41f4b71Sopenharmony_ci}
7449e41f4b71Sopenharmony_ci```
7450e41f4b71Sopenharmony_ci
7451e41f4b71Sopenharmony_ci### setPolyToPoly<sup>12+</sup>
7452e41f4b71Sopenharmony_ci
7453e41f4b71Sopenharmony_cisetPolyToPoly(src: Array\<common2D.Point>, dst: Array\<common2D.Point>, count: number): boolean
7454e41f4b71Sopenharmony_ci
7455e41f4b71Sopenharmony_ciSets this matrix to a transformation matrix that maps the source point array to the destination point array.
7456e41f4b71Sopenharmony_ci
7457e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7458e41f4b71Sopenharmony_ci
7459e41f4b71Sopenharmony_ci**Parameters**
7460e41f4b71Sopenharmony_ci
7461e41f4b71Sopenharmony_ci| Name         | Type   | Mandatory| Description                                                       |
7462e41f4b71Sopenharmony_ci| --------------- | ------- | ---- | ----------------------------------------------------------- |
7463e41f4b71Sopenharmony_ci| src | Array\<[common2D.Point](js-apis-graphics-common2D.md#point)> | Yes  | Array of source points. The array length must be the same as the value of **count**.|
7464e41f4b71Sopenharmony_ci| dst | Array\<[common2D.Point](js-apis-graphics-common2D.md#point)> | Yes  | Array of destination points. The array length must be the same as the value of **count**.|
7465e41f4b71Sopenharmony_ci| count | number | Yes  | Number of points in each array. The value is an integer.|
7466e41f4b71Sopenharmony_ci
7467e41f4b71Sopenharmony_ci**Return value**
7468e41f4b71Sopenharmony_ci
7469e41f4b71Sopenharmony_ci| Type                 | Description          |
7470e41f4b71Sopenharmony_ci| --------------------- | -------------- |
7471e41f4b71Sopenharmony_ci| boolean | Result indicating whether the setting is successful. The value **true** means that the setting is successful, and **false** means the opposite.|
7472e41f4b71Sopenharmony_ci
7473e41f4b71Sopenharmony_ci**Error codes**
7474e41f4b71Sopenharmony_ci
7475e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7476e41f4b71Sopenharmony_ci
7477e41f4b71Sopenharmony_ci| ID| Error Message|
7478e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
7479e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7480e41f4b71Sopenharmony_ci
7481e41f4b71Sopenharmony_ci**Example**
7482e41f4b71Sopenharmony_ci
7483e41f4b71Sopenharmony_ci```ts
7484e41f4b71Sopenharmony_ciimport {drawing,common2D} from "@kit.ArkGraphics2D"
7485e41f4b71Sopenharmony_cilet srcPoints: Array<common2D.Point> = [ {x: 10, y: 20}, {x: 200, y: 150} ];
7486e41f4b71Sopenharmony_cilet dstPoints: Array<common2D.Point> = [{ x:0, y: 10 }, { x:300, y: 600 }];
7487e41f4b71Sopenharmony_cilet matrix = new drawing.Matrix();
7488e41f4b71Sopenharmony_ciif (matrix.setPolyToPoly(srcPoints, dstPoints, 2)) {
7489e41f4b71Sopenharmony_ci    console.info("matrix"+matrix.getAll().toString());
7490e41f4b71Sopenharmony_ci}
7491e41f4b71Sopenharmony_ci```
7492e41f4b71Sopenharmony_ci
7493e41f4b71Sopenharmony_ci## RoundRect<sup>12+</sup>
7494e41f4b71Sopenharmony_ci
7495e41f4b71Sopenharmony_ciImplements a rounded rectangle.
7496e41f4b71Sopenharmony_ci
7497e41f4b71Sopenharmony_ci### constructor<sup>12+</sup>
7498e41f4b71Sopenharmony_ci
7499e41f4b71Sopenharmony_ciconstructor(rect: common2D.Rect, xRadii: number, yRadii: number)
7500e41f4b71Sopenharmony_ci
7501e41f4b71Sopenharmony_ciA constructor used to create a **RoundRect** object. A rounded rectangle is created when both **xRadii** and **yRadii** are greater than 0. Otherwise, only a rectangle is created.
7502e41f4b71Sopenharmony_ci
7503e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7504e41f4b71Sopenharmony_ci
7505e41f4b71Sopenharmony_ci**Parameters**
7506e41f4b71Sopenharmony_ci
7507e41f4b71Sopenharmony_ci| Name        | Type                                      | Mandatory  | Description                 |
7508e41f4b71Sopenharmony_ci| ----------- | ---------------------------------------- | ---- | ------------------- |
7509e41f4b71Sopenharmony_ci| rect        | [common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes   | Rectangle that encloses the rounded rectangle to create.     |
7510e41f4b71Sopenharmony_ci| xRadii        | number                  | Yes   | Radius of the rounded corner on the X axis. The value is a floating point number. A negative number is invalid.    |
7511e41f4b71Sopenharmony_ci| yRadii        | number                  | Yes   | Radius of the rounded corner on the Y axis. The value is a floating point number. A negative number is invalid.    |
7512e41f4b71Sopenharmony_ci
7513e41f4b71Sopenharmony_ci**Error codes**
7514e41f4b71Sopenharmony_ci
7515e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7516e41f4b71Sopenharmony_ci
7517e41f4b71Sopenharmony_ci| ID| Error Message|
7518e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
7519e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7520e41f4b71Sopenharmony_ci
7521e41f4b71Sopenharmony_ci**Example**
7522e41f4b71Sopenharmony_ci
7523e41f4b71Sopenharmony_ci```ts
7524e41f4b71Sopenharmony_ciimport { common2D, drawing } from '@kit.ArkGraphics2D';
7525e41f4b71Sopenharmony_ci
7526e41f4b71Sopenharmony_cilet rect: common2D.Rect = {left : 100, top : 100, right : 500, bottom : 300};
7527e41f4b71Sopenharmony_cilet roundRect = new drawing.RoundRect(rect, 50, 50);
7528e41f4b71Sopenharmony_ci```
7529e41f4b71Sopenharmony_ci### setCorner<sup>12+</sup>
7530e41f4b71Sopenharmony_ci
7531e41f4b71Sopenharmony_cisetCorner(pos: CornerPos, x: number, y: number): void
7532e41f4b71Sopenharmony_ci
7533e41f4b71Sopenharmony_ciSets the radii of the specified rounded corner in this rounded rectangle.
7534e41f4b71Sopenharmony_ci
7535e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7536e41f4b71Sopenharmony_ci
7537e41f4b71Sopenharmony_ci**Parameters**
7538e41f4b71Sopenharmony_ci
7539e41f4b71Sopenharmony_ci| Name  | Type                                        | Mandatory| Description                           |
7540e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | ---- | ------------------------------- |
7541e41f4b71Sopenharmony_ci| pos | [CornerPos](#cornerpos12) | Yes  | Position of the rounded corner.                |
7542e41f4b71Sopenharmony_ci| x     | number                 | Yes  | Radius of the rounded corner on the X axis. The value is a floating point number.|
7543e41f4b71Sopenharmony_ci| y     | number      | Yes  | Radius of the rounded corner on the Y axis. The value is a floating point number.|
7544e41f4b71Sopenharmony_ci
7545e41f4b71Sopenharmony_ci**Error codes**
7546e41f4b71Sopenharmony_ci
7547e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7548e41f4b71Sopenharmony_ci
7549e41f4b71Sopenharmony_ci| ID| Error Message|
7550e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
7551e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
7552e41f4b71Sopenharmony_ci
7553e41f4b71Sopenharmony_ci**Example**
7554e41f4b71Sopenharmony_ci
7555e41f4b71Sopenharmony_ci```ts
7556e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
7557e41f4b71Sopenharmony_cilet roundRect : drawing.RoundRect = new drawing.RoundRect({left: 0, top: 0, right: 300, bottom: 300}, 50, 50);
7558e41f4b71Sopenharmony_ciroundRect.setCorner(drawing.CornerPos.TOP_LEFT_POS, 150, 150);
7559e41f4b71Sopenharmony_ci```
7560e41f4b71Sopenharmony_ci
7561e41f4b71Sopenharmony_ci### getCorner<sup>12+</sup>
7562e41f4b71Sopenharmony_ci
7563e41f4b71Sopenharmony_cigetCorner(pos: CornerPos): common2D.Point
7564e41f4b71Sopenharmony_ci
7565e41f4b71Sopenharmony_ciObtains the radii of the specified rounded corner in this rounded rectangle.
7566e41f4b71Sopenharmony_ci
7567e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7568e41f4b71Sopenharmony_ci
7569e41f4b71Sopenharmony_ci**Parameters**
7570e41f4b71Sopenharmony_ci
7571e41f4b71Sopenharmony_ci| Name  | Type                                        | Mandatory| Description                           |
7572e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | ---- | ------------------------------- |
7573e41f4b71Sopenharmony_ci| pos | [CornerPos](#cornerpos12) | Yes  | Position of the rounded corner.                |
7574e41f4b71Sopenharmony_ci
7575e41f4b71Sopenharmony_ci**Return value**
7576e41f4b71Sopenharmony_ci
7577e41f4b71Sopenharmony_ci| Type                 | Description          |
7578e41f4b71Sopenharmony_ci| --------------------- | -------------- |
7579e41f4b71Sopenharmony_ci| [common2D.Point](js-apis-graphics-common2D.md#point)  | Point. The horizontal coordinate indicates the radius of the rounded corner on the X axis, and the vertical coordinate indicates the radius on the Y axis.|
7580e41f4b71Sopenharmony_ci
7581e41f4b71Sopenharmony_ci**Error codes**
7582e41f4b71Sopenharmony_ci
7583e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7584e41f4b71Sopenharmony_ci
7585e41f4b71Sopenharmony_ci| ID| Error Message|
7586e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
7587e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
7588e41f4b71Sopenharmony_ci
7589e41f4b71Sopenharmony_ci**Example**
7590e41f4b71Sopenharmony_ci
7591e41f4b71Sopenharmony_ci```ts
7592e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
7593e41f4b71Sopenharmony_cilet roundRect : drawing.RoundRect = new drawing.RoundRect({left: 0, top: 0, right: 300, bottom: 300}, 50, 50);
7594e41f4b71Sopenharmony_cilet cornerRadius = roundRect.getCorner(drawing.CornerPos.BOTTOM_LEFT_POS);
7595e41f4b71Sopenharmony_ciconsole.info("getCorner---"+cornerRadius.x)
7596e41f4b71Sopenharmony_ciconsole.info("getCorner---"+cornerRadius.y)
7597e41f4b71Sopenharmony_ci```
7598e41f4b71Sopenharmony_ci
7599e41f4b71Sopenharmony_ci### offset<sup>12+</sup>
7600e41f4b71Sopenharmony_ci
7601e41f4b71Sopenharmony_cioffset(dx: number, dy: number): void
7602e41f4b71Sopenharmony_ci
7603e41f4b71Sopenharmony_ciTranslates this rounded rectangle by an offset along the X axis and Y axis.
7604e41f4b71Sopenharmony_ci
7605e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7606e41f4b71Sopenharmony_ci
7607e41f4b71Sopenharmony_ci**Parameters**
7608e41f4b71Sopenharmony_ci
7609e41f4b71Sopenharmony_ci| Name  | Type                                        | Mandatory| Description                           |
7610e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | ---- | ------------------------------- |
7611e41f4b71Sopenharmony_ci| dx | number | Yes  | Horizontal distance to translate. A positive number indicates a translation towards the positive direction of the X axis, and a negative number indicates a translation towards the negative direction of the X axis. The value is a floating point number.                |
7612e41f4b71Sopenharmony_ci| dy | number | Yes  | Vertical distance to translate. A positive number indicates a translation towards the positive direction of the Y axis, and a negative number indicates a translation towards the negative direction of the Y axis. The value is a floating point number.                |
7613e41f4b71Sopenharmony_ci
7614e41f4b71Sopenharmony_ci**Error codes**
7615e41f4b71Sopenharmony_ci
7616e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7617e41f4b71Sopenharmony_ci
7618e41f4b71Sopenharmony_ci| ID| Error Message|
7619e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
7620e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7621e41f4b71Sopenharmony_ci
7622e41f4b71Sopenharmony_ci**Example**
7623e41f4b71Sopenharmony_ci
7624e41f4b71Sopenharmony_ci```ts
7625e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
7626e41f4b71Sopenharmony_cilet roundRect : drawing.RoundRect = new drawing.RoundRect({left: 0, top: 0, right: 300, bottom: 300}, 50, 50);
7627e41f4b71Sopenharmony_ciroundRect.offset(100, 100);
7628e41f4b71Sopenharmony_ci```
7629e41f4b71Sopenharmony_ci
7630e41f4b71Sopenharmony_ci## Region<sup>12+</sup>
7631e41f4b71Sopenharmony_ci
7632e41f4b71Sopenharmony_ciDescribes a region, which is used to describe the region where the shape can be drawn.
7633e41f4b71Sopenharmony_ci
7634e41f4b71Sopenharmony_ci### isPointContained<sup>12+</sup>
7635e41f4b71Sopenharmony_ci
7636e41f4b71Sopenharmony_ciisPointContained(x: number, y: number) : boolean
7637e41f4b71Sopenharmony_ci
7638e41f4b71Sopenharmony_ciChecks whether a point is contained in this region.
7639e41f4b71Sopenharmony_ci
7640e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7641e41f4b71Sopenharmony_ci
7642e41f4b71Sopenharmony_ci**Parameters**
7643e41f4b71Sopenharmony_ci
7644e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                   |
7645e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------- |
7646e41f4b71Sopenharmony_ci| x      | number | Yes  | X coordinate of the point. The value must be an integer. If a decimal is passed in, the decimal part is rounded off.|
7647e41f4b71Sopenharmony_ci| y      | number | Yes  | Y coordinate of the point. The value must be an integer. If a decimal is passed in, the decimal part is rounded off.|
7648e41f4b71Sopenharmony_ci
7649e41f4b71Sopenharmony_ci**Return value**
7650e41f4b71Sopenharmony_ci
7651e41f4b71Sopenharmony_ci| Type   | Description          |
7652e41f4b71Sopenharmony_ci| ------- | -------------- |
7653e41f4b71Sopenharmony_ci| boolean | Result indicating whether the point is contained in the region. The value **true** means that the point is contained, and **false** means the opposite.|
7654e41f4b71Sopenharmony_ci
7655e41f4b71Sopenharmony_ci**Error codes**
7656e41f4b71Sopenharmony_ci
7657e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7658e41f4b71Sopenharmony_ci
7659e41f4b71Sopenharmony_ci| ID| Error Message|
7660e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
7661e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7662e41f4b71Sopenharmony_ci
7663e41f4b71Sopenharmony_ci**Example**
7664e41f4b71Sopenharmony_ci
7665e41f4b71Sopenharmony_ci```ts
7666e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
7667e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
7668e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
7669e41f4b71Sopenharmony_ci    const canvas = context.canvas;
7670e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
7671e41f4b71Sopenharmony_ci    pen.setColor({ alpha: 255, red: 255, green: 0, blue: 0 });
7672e41f4b71Sopenharmony_ci    pen.setStrokeWidth(10);
7673e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
7674e41f4b71Sopenharmony_ci    let region = new drawing.Region();
7675e41f4b71Sopenharmony_ci    region.setRect(100, 100, 400, 400);
7676e41f4b71Sopenharmony_ci    let flag: boolean = false;
7677e41f4b71Sopenharmony_ci    flag = region.isPointContained(200,200);
7678e41f4b71Sopenharmony_ci    console.info("region isPointContained : " + flag);
7679e41f4b71Sopenharmony_ci    canvas.drawPoint(200,200);
7680e41f4b71Sopenharmony_ci    canvas.drawRegion(region);
7681e41f4b71Sopenharmony_ci    canvas.detachPen();
7682e41f4b71Sopenharmony_ci  }
7683e41f4b71Sopenharmony_ci}
7684e41f4b71Sopenharmony_ci```
7685e41f4b71Sopenharmony_ci
7686e41f4b71Sopenharmony_ci### isRegionContained<sup>12+</sup>
7687e41f4b71Sopenharmony_ci
7688e41f4b71Sopenharmony_ciisRegionContained(other: Region) : boolean
7689e41f4b71Sopenharmony_ci
7690e41f4b71Sopenharmony_ciChecks whether another region is contained in this region.
7691e41f4b71Sopenharmony_ci
7692e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7693e41f4b71Sopenharmony_ci
7694e41f4b71Sopenharmony_ci**Parameters**
7695e41f4b71Sopenharmony_ci
7696e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                   |
7697e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------- |
7698e41f4b71Sopenharmony_ci| other      | [Region](#region12) | Yes  | **Region** object.|
7699e41f4b71Sopenharmony_ci
7700e41f4b71Sopenharmony_ci**Return value**
7701e41f4b71Sopenharmony_ci
7702e41f4b71Sopenharmony_ci| Type   | Description          |
7703e41f4b71Sopenharmony_ci| ------- | -------------- |
7704e41f4b71Sopenharmony_ci| boolean | Result indicating whether the other region is contained in the current region. The value **true** means that the other region is contained, and **false** means the opposite.|
7705e41f4b71Sopenharmony_ci
7706e41f4b71Sopenharmony_ci**Error codes**
7707e41f4b71Sopenharmony_ci
7708e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7709e41f4b71Sopenharmony_ci
7710e41f4b71Sopenharmony_ci| ID| Error Message|
7711e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
7712e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7713e41f4b71Sopenharmony_ci
7714e41f4b71Sopenharmony_ci**Example**
7715e41f4b71Sopenharmony_ci
7716e41f4b71Sopenharmony_ci```ts
7717e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
7718e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
7719e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
7720e41f4b71Sopenharmony_ci    const canvas = context.canvas;
7721e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
7722e41f4b71Sopenharmony_ci    pen.setColor({ alpha: 255, red: 255, green: 0, blue: 0 });
7723e41f4b71Sopenharmony_ci    pen.setStrokeWidth(10);
7724e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
7725e41f4b71Sopenharmony_ci    let region = new drawing.Region();
7726e41f4b71Sopenharmony_ci    let other = new drawing.Region();
7727e41f4b71Sopenharmony_ci    region.setRect(100, 100, 400, 400);
7728e41f4b71Sopenharmony_ci    other.setRect(150, 150, 250 ,250);
7729e41f4b71Sopenharmony_ci    let flag: boolean = false;
7730e41f4b71Sopenharmony_ci    flag = region.isRegionContained(other);
7731e41f4b71Sopenharmony_ci    console.info("region isRegionContained : " + flag);
7732e41f4b71Sopenharmony_ci    canvas.drawRegion(region);
7733e41f4b71Sopenharmony_ci    canvas.drawRegion(other);
7734e41f4b71Sopenharmony_ci    canvas.detachPen();
7735e41f4b71Sopenharmony_ci  }
7736e41f4b71Sopenharmony_ci}
7737e41f4b71Sopenharmony_ci```
7738e41f4b71Sopenharmony_ci
7739e41f4b71Sopenharmony_ci### op<sup>12+</sup>
7740e41f4b71Sopenharmony_ci
7741e41f4b71Sopenharmony_ciop(region: Region, regionOp: RegionOp) : boolean
7742e41f4b71Sopenharmony_ci
7743e41f4b71Sopenharmony_ciPerforms an operation on this region and another region, and stores the resulting region in this **Region** object.
7744e41f4b71Sopenharmony_ci
7745e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7746e41f4b71Sopenharmony_ci
7747e41f4b71Sopenharmony_ci**Parameters**
7748e41f4b71Sopenharmony_ci
7749e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                   |
7750e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------- |
7751e41f4b71Sopenharmony_ci| region      | [Region](#region12) | Yes  | **Region** object.|
7752e41f4b71Sopenharmony_ci| regionOp      | [RegionOp](#regionop12) | Yes  | Operation mode of the region.|
7753e41f4b71Sopenharmony_ci
7754e41f4b71Sopenharmony_ci**Return value**
7755e41f4b71Sopenharmony_ci
7756e41f4b71Sopenharmony_ci| Type   | Description          |
7757e41f4b71Sopenharmony_ci| ------- | -------------- |
7758e41f4b71Sopenharmony_ci| boolean | Result indicating whether the resulting region is stored in the current **Region** object. The value **true** means that the resulting region is stored in the current **Region** object, and **false** means the opposite.|
7759e41f4b71Sopenharmony_ci
7760e41f4b71Sopenharmony_ci**Error codes**
7761e41f4b71Sopenharmony_ci
7762e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7763e41f4b71Sopenharmony_ci
7764e41f4b71Sopenharmony_ci| ID| Error Message|
7765e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
7766e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7767e41f4b71Sopenharmony_ci
7768e41f4b71Sopenharmony_ci**Example**
7769e41f4b71Sopenharmony_ci
7770e41f4b71Sopenharmony_ci```ts
7771e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
7772e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
7773e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
7774e41f4b71Sopenharmony_ci    const canvas = context.canvas;
7775e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
7776e41f4b71Sopenharmony_ci    pen.setColor({ alpha: 255, red: 255, green: 0, blue: 0 });
7777e41f4b71Sopenharmony_ci    pen.setStrokeWidth(10);
7778e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
7779e41f4b71Sopenharmony_ci    let region = new drawing.Region();
7780e41f4b71Sopenharmony_ci    region.setRect(200, 200, 400, 400);
7781e41f4b71Sopenharmony_ci    let othregion = new drawing.Region();
7782e41f4b71Sopenharmony_ci    othregion.setRect(110, 110, 240, 240);
7783e41f4b71Sopenharmony_ci    let flag: boolean = false;
7784e41f4b71Sopenharmony_ci    flag = region.op(othregion,drawing.RegionOp.REPLACE);
7785e41f4b71Sopenharmony_ci    console.info("region op : " + flag);
7786e41f4b71Sopenharmony_ci    canvas.drawRegion(region);
7787e41f4b71Sopenharmony_ci    canvas.detachPen();
7788e41f4b71Sopenharmony_ci  }
7789e41f4b71Sopenharmony_ci}
7790e41f4b71Sopenharmony_ci```
7791e41f4b71Sopenharmony_ci
7792e41f4b71Sopenharmony_ci### quickReject<sup>12+</sup>
7793e41f4b71Sopenharmony_ci
7794e41f4b71Sopenharmony_ciquickReject(left: number, top: number, right: number, bottom: number) : boolean
7795e41f4b71Sopenharmony_ci
7796e41f4b71Sopenharmony_ciChecks whether a rectangle do not intersect with this region. Actually, this API determines whether the rectangle does not intersect with the bounding rectangle of the region, and therefore the result may not be accurate.
7797e41f4b71Sopenharmony_ci
7798e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7799e41f4b71Sopenharmony_ci
7800e41f4b71Sopenharmony_ci**Parameters**
7801e41f4b71Sopenharmony_ci
7802e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                   |
7803e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------- |
7804e41f4b71Sopenharmony_ci| left   | number | Yes  | Left position of the rectangle. The value must be an integer. If a decimal is passed in, the decimal part is rounded off.|
7805e41f4b71Sopenharmony_ci| top    | number | Yes  | Top position of the rectangle. The value must be an integer. If a decimal is passed in, the decimal part is rounded off.|
7806e41f4b71Sopenharmony_ci| right  | number | Yes  | Right position of the rectangle. The value must be an integer. If a decimal is passed in, the decimal part is rounded off.|
7807e41f4b71Sopenharmony_ci| bottom | number | Yes  | Bottom position of the rectangle. The value must be an integer. If a decimal is passed in, the decimal part is rounded off.|
7808e41f4b71Sopenharmony_ci
7809e41f4b71Sopenharmony_ci**Return value**
7810e41f4b71Sopenharmony_ci
7811e41f4b71Sopenharmony_ci| Type   | Description          |
7812e41f4b71Sopenharmony_ci| ------- | -------------- |
7813e41f4b71Sopenharmony_ci| boolean | Check result. The value **true** means that the two do not intersect, and **false** means the opposite.|
7814e41f4b71Sopenharmony_ci
7815e41f4b71Sopenharmony_ci**Error codes**
7816e41f4b71Sopenharmony_ci
7817e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7818e41f4b71Sopenharmony_ci
7819e41f4b71Sopenharmony_ci| ID| Error Message|
7820e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
7821e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7822e41f4b71Sopenharmony_ci
7823e41f4b71Sopenharmony_ci**Example**
7824e41f4b71Sopenharmony_ci
7825e41f4b71Sopenharmony_ci```ts
7826e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
7827e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
7828e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
7829e41f4b71Sopenharmony_ci    const canvas = context.canvas;
7830e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
7831e41f4b71Sopenharmony_ci    pen.setColor({ alpha: 255, red: 255, green: 0, blue: 0 });
7832e41f4b71Sopenharmony_ci    pen.setStrokeWidth(10);
7833e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
7834e41f4b71Sopenharmony_ci    let region = new drawing.Region();
7835e41f4b71Sopenharmony_ci    region.setRect(100, 100, 400, 400);
7836e41f4b71Sopenharmony_ci    let flag: boolean = false;
7837e41f4b71Sopenharmony_ci    flag = region.quickReject(50, 50, 70, 70);
7838e41f4b71Sopenharmony_ci    console.info("region quickReject : " + flag);
7839e41f4b71Sopenharmony_ci    canvas.drawRegion(region);
7840e41f4b71Sopenharmony_ci    canvas.detachPen();
7841e41f4b71Sopenharmony_ci  }
7842e41f4b71Sopenharmony_ci}
7843e41f4b71Sopenharmony_ci```
7844e41f4b71Sopenharmony_ci
7845e41f4b71Sopenharmony_ci### setPath<sup>12+</sup>
7846e41f4b71Sopenharmony_ci
7847e41f4b71Sopenharmony_cisetPath(path: Path, clip: Region) : boolean
7848e41f4b71Sopenharmony_ci
7849e41f4b71Sopenharmony_ciSets a region that matches the outline of a path within the cropping area.
7850e41f4b71Sopenharmony_ci
7851e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7852e41f4b71Sopenharmony_ci
7853e41f4b71Sopenharmony_ci**Parameters**
7854e41f4b71Sopenharmony_ci
7855e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                   |
7856e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------- |
7857e41f4b71Sopenharmony_ci| path      | [Path](#path) | Yes  | **Path** object.|
7858e41f4b71Sopenharmony_ci| clip      | [Region](#region12) | Yes  | **Region** object.|
7859e41f4b71Sopenharmony_ci
7860e41f4b71Sopenharmony_ci**Return value**
7861e41f4b71Sopenharmony_ci
7862e41f4b71Sopenharmony_ci| Type   | Description          |
7863e41f4b71Sopenharmony_ci| ------- | -------------- |
7864e41f4b71Sopenharmony_ci| boolean | Result of the setting operation. The value **true** means that the setting is successful, and **false** means the opposite.|
7865e41f4b71Sopenharmony_ci
7866e41f4b71Sopenharmony_ci**Error codes**
7867e41f4b71Sopenharmony_ci
7868e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7869e41f4b71Sopenharmony_ci
7870e41f4b71Sopenharmony_ci| ID| Error Message|
7871e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
7872e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7873e41f4b71Sopenharmony_ci
7874e41f4b71Sopenharmony_ci**Example**
7875e41f4b71Sopenharmony_ci
7876e41f4b71Sopenharmony_ci```ts
7877e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
7878e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
7879e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
7880e41f4b71Sopenharmony_ci    const canvas = context.canvas;
7881e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
7882e41f4b71Sopenharmony_ci    pen.setColor({ alpha: 255, red: 255, green: 0, blue: 0 });
7883e41f4b71Sopenharmony_ci    pen.setStrokeWidth(10);
7884e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
7885e41f4b71Sopenharmony_ci    let region = new drawing.Region();
7886e41f4b71Sopenharmony_ci    let path = new drawing.Path();
7887e41f4b71Sopenharmony_ci    region.setRect(100, 100, 400, 400);
7888e41f4b71Sopenharmony_ci    path.arcTo(50, 50, 300, 300, 0, 359);
7889e41f4b71Sopenharmony_ci    let flag: boolean = false;
7890e41f4b71Sopenharmony_ci    flag = region.setPath(path,region);
7891e41f4b71Sopenharmony_ci    console.info("region setPath : " + flag);
7892e41f4b71Sopenharmony_ci    canvas.drawRegion(region);
7893e41f4b71Sopenharmony_ci    canvas.detachPen();
7894e41f4b71Sopenharmony_ci  }
7895e41f4b71Sopenharmony_ci}
7896e41f4b71Sopenharmony_ci```
7897e41f4b71Sopenharmony_ci
7898e41f4b71Sopenharmony_ci### setRect<sup>12+</sup>
7899e41f4b71Sopenharmony_ci
7900e41f4b71Sopenharmony_cisetRect(left: number, top: number, right: number, bottom: number) : boolean
7901e41f4b71Sopenharmony_ci
7902e41f4b71Sopenharmony_ciSets a rectangle.
7903e41f4b71Sopenharmony_ci
7904e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7905e41f4b71Sopenharmony_ci
7906e41f4b71Sopenharmony_ci**Parameters**
7907e41f4b71Sopenharmony_ci
7908e41f4b71Sopenharmony_ci| Name| Type  | Mandatory| Description                   |
7909e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----------------------- |
7910e41f4b71Sopenharmony_ci| left   | number | Yes  | Left position of the rectangle. The value must be an integer. If a decimal is passed in, the decimal part is rounded off.|
7911e41f4b71Sopenharmony_ci| top    | number | Yes  | Top position of the rectangle. The value must be an integer. If a decimal is passed in, the decimal part is rounded off.|
7912e41f4b71Sopenharmony_ci| right  | number | Yes  | Right position of the rectangle. The value must be an integer. If a decimal is passed in, the decimal part is rounded off.|
7913e41f4b71Sopenharmony_ci| bottom | number | Yes  | Bottom position of the rectangle. The value must be an integer. If a decimal is passed in, the decimal part is rounded off.|
7914e41f4b71Sopenharmony_ci
7915e41f4b71Sopenharmony_ci**Return value**
7916e41f4b71Sopenharmony_ci
7917e41f4b71Sopenharmony_ci| Type   | Description          |
7918e41f4b71Sopenharmony_ci| ------- | -------------- |
7919e41f4b71Sopenharmony_ci| boolean | Result of the setting operation. The value **true** means that the setting is successful, and **false** means the opposite.|
7920e41f4b71Sopenharmony_ci
7921e41f4b71Sopenharmony_ci**Error codes**
7922e41f4b71Sopenharmony_ci
7923e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7924e41f4b71Sopenharmony_ci
7925e41f4b71Sopenharmony_ci| ID| Error Message|
7926e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
7927e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7928e41f4b71Sopenharmony_ci
7929e41f4b71Sopenharmony_ci**Example**
7930e41f4b71Sopenharmony_ci
7931e41f4b71Sopenharmony_ci```ts
7932e41f4b71Sopenharmony_ciimport { RenderNode } from '@kit.ArkUI';
7933e41f4b71Sopenharmony_ciclass DrawingRenderNode extends RenderNode {
7934e41f4b71Sopenharmony_ci  draw(context : DrawContext) {
7935e41f4b71Sopenharmony_ci    const canvas = context.canvas;
7936e41f4b71Sopenharmony_ci    const pen = new drawing.Pen();
7937e41f4b71Sopenharmony_ci    pen.setColor({ alpha: 255, red: 255, green: 0, blue: 0 });
7938e41f4b71Sopenharmony_ci    pen.setStrokeWidth(10);
7939e41f4b71Sopenharmony_ci    canvas.attachPen(pen);
7940e41f4b71Sopenharmony_ci    let region = new drawing.Region();
7941e41f4b71Sopenharmony_ci    let flag: boolean = false;
7942e41f4b71Sopenharmony_ci    flag = region.setRect(50, 50, 300, 300);
7943e41f4b71Sopenharmony_ci    console.info("region setRect : " + flag);
7944e41f4b71Sopenharmony_ci    canvas.drawRegion(region);
7945e41f4b71Sopenharmony_ci    canvas.detachPen();
7946e41f4b71Sopenharmony_ci  }
7947e41f4b71Sopenharmony_ci}
7948e41f4b71Sopenharmony_ci```
7949e41f4b71Sopenharmony_ci
7950e41f4b71Sopenharmony_ci## TileMode<sup>12+</sup>
7951e41f4b71Sopenharmony_ci
7952e41f4b71Sopenharmony_ciEnumerates the tile modes of the shader effect.
7953e41f4b71Sopenharmony_ci
7954e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7955e41f4b71Sopenharmony_ci
7956e41f4b71Sopenharmony_ci| Name                  | Value  | Description                          |
7957e41f4b71Sopenharmony_ci| ---------------------- | ---- | ------------------------------ |
7958e41f4b71Sopenharmony_ci| CLAMP     | 0    | Replicates the edge color if the shader effect draws outside of its original boundary.|
7959e41f4b71Sopenharmony_ci| REPEAT    | 1    | Repeats the shader effect in both horizontal and vertical directions.|
7960e41f4b71Sopenharmony_ci| MIRROR    | 2    | Repeats the shader effect in both horizontal and vertical directions, alternating mirror images.|
7961e41f4b71Sopenharmony_ci| DECAL     | 3    | Renders the shader effect only within the original boundary.|
7962e41f4b71Sopenharmony_ci
7963e41f4b71Sopenharmony_ci## ShaderEffect<sup>12+</sup>
7964e41f4b71Sopenharmony_ci
7965e41f4b71Sopenharmony_ciImplements the shader effect. After a shader effect is set for a pen or brush, the shader effect instead of the color attribute is used for drawing. In this case, the alpha value set for the pen or brush still takes effect.
7966e41f4b71Sopenharmony_ci
7967e41f4b71Sopenharmony_ci### createColorShader<sup>12+</sup>
7968e41f4b71Sopenharmony_ci
7969e41f4b71Sopenharmony_cistatic createColorShader(color: number): ShaderEffect
7970e41f4b71Sopenharmony_ci
7971e41f4b71Sopenharmony_ciCreates a **ShaderEffect** object with a single color.
7972e41f4b71Sopenharmony_ci
7973e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
7974e41f4b71Sopenharmony_ci
7975e41f4b71Sopenharmony_ci**Parameters**
7976e41f4b71Sopenharmony_ci
7977e41f4b71Sopenharmony_ci| Name| Type                                              | Mandatory| Description          |
7978e41f4b71Sopenharmony_ci| ------ | -------------------------------------------------- | ---- | -------------- |
7979e41f4b71Sopenharmony_ci| color   | number | Yes  | Color in the ARGB format. The value is a 32-bit unsigned integer.|
7980e41f4b71Sopenharmony_ci
7981e41f4b71Sopenharmony_ci**Return value**
7982e41f4b71Sopenharmony_ci
7983e41f4b71Sopenharmony_ci| Type   | Description                      |
7984e41f4b71Sopenharmony_ci| ------- | ------------------------- |
7985e41f4b71Sopenharmony_ci| [ShaderEffect](#shadereffect12) | **ShaderEffect** object with a single color.|
7986e41f4b71Sopenharmony_ci
7987e41f4b71Sopenharmony_ci**Error codes**
7988e41f4b71Sopenharmony_ci
7989e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7990e41f4b71Sopenharmony_ci
7991e41f4b71Sopenharmony_ci| ID| Error Message|
7992e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
7993e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7994e41f4b71Sopenharmony_ci
7995e41f4b71Sopenharmony_ci**Example**
7996e41f4b71Sopenharmony_ci
7997e41f4b71Sopenharmony_ci```ts
7998e41f4b71Sopenharmony_ciimport { drawing } from '@kit.ArkGraphics2D';
7999e41f4b71Sopenharmony_ci
8000e41f4b71Sopenharmony_cilet shaderEffect = drawing.ShaderEffect.createColorShader(0xFFFF0000);
8001e41f4b71Sopenharmony_ci```
8002e41f4b71Sopenharmony_ci
8003e41f4b71Sopenharmony_ci### createLinearGradient<sup>12+</sup>
8004e41f4b71Sopenharmony_ci
8005e41f4b71Sopenharmony_cistatic createLinearGradient(startPt: common2D.Point, endPt: common2D.Point, colors: Array
8006e41f4b71Sopenharmony_ci\<number>, mode: TileMode, pos?: Array\<number> | null, matrix?: Matrix | null): ShaderEffect
8007e41f4b71Sopenharmony_ci
8008e41f4b71Sopenharmony_ciCreates a **ShaderEffect** object that generates a linear gradient between two points.
8009e41f4b71Sopenharmony_ci
8010e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
8011e41f4b71Sopenharmony_ci
8012e41f4b71Sopenharmony_ci**Parameters**
8013e41f4b71Sopenharmony_ci
8014e41f4b71Sopenharmony_ci| Name| Type                                              | Mandatory| Description          |
8015e41f4b71Sopenharmony_ci| ------ | -------------------------------------------------- | ---- | -------------- |
8016e41f4b71Sopenharmony_ci| startPt  | [common2D.Point](js-apis-graphics-common2D.md#point)  | Yes  | Start point.|
8017e41f4b71Sopenharmony_ci| endPt   | [common2D.Point](js-apis-graphics-common2D.md#point)  | Yes  | End point.|
8018e41f4b71Sopenharmony_ci| colors | Array\<number> | Yes  | Array of colors to distribute between the two points. The values in the array are 32-bit (ARGB) unsigned integers.|
8019e41f4b71Sopenharmony_ci| mode  | [TileMode](#tilemode12) | Yes  | Tile mode of the shader effect.|
8020e41f4b71Sopenharmony_ci| pos | Array\<number> \|null| No  | Relative position of each color in the color array. The array length must be the same as that of **colors**. The first element in the array must be 0.0, the last element must be 1.0, and the middle elements must be between 0.0 and 1.0 and increase by index. The default value is null, indicating that colors are evenly distributed between the two points.|
8021e41f4b71Sopenharmony_ci| matrix | [Matrix](#matrix12) \| null | No  | **Matrix** object used to perform matrix transformation on the shader effect. The default value is null, indicating the identity matrix.|
8022e41f4b71Sopenharmony_ci
8023e41f4b71Sopenharmony_ci![LinearGradient](./figures/image_createLinearGradient.png)
8024e41f4b71Sopenharmony_ci
8025e41f4b71Sopenharmony_ciThe preceding figure shows the display effect when the **colors** array is set to red, green, and blue and the **pos** array is set to 0.0, 0.75, and 1.0. The triangle subscript is the relative position of a color between the start point and end point. Gradient colors are used between them.
8026e41f4b71Sopenharmony_ci
8027e41f4b71Sopenharmony_ci**Return value**
8028e41f4b71Sopenharmony_ci
8029e41f4b71Sopenharmony_ci| Type   | Description                      |
8030e41f4b71Sopenharmony_ci| ------- | ------------------------- |
8031e41f4b71Sopenharmony_ci| [ShaderEffect](#shadereffect12) | **ShaderEffect** object created.|
8032e41f4b71Sopenharmony_ci
8033e41f4b71Sopenharmony_ci**Error codes**
8034e41f4b71Sopenharmony_ci
8035e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
8036e41f4b71Sopenharmony_ci
8037e41f4b71Sopenharmony_ci| ID| Error Message|
8038e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
8039e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; 3. Parameter verification failed. |
8040e41f4b71Sopenharmony_ci
8041e41f4b71Sopenharmony_ci**Example**
8042e41f4b71Sopenharmony_ci
8043e41f4b71Sopenharmony_ci```ts
8044e41f4b71Sopenharmony_ciimport { common2D,drawing } from '@kit.ArkGraphics2D';
8045e41f4b71Sopenharmony_ci
8046e41f4b71Sopenharmony_cilet startPt: common2D.Point = { x: 100, y: 100 };
8047e41f4b71Sopenharmony_cilet endPt: common2D.Point = { x: 300, y: 300 };
8048e41f4b71Sopenharmony_cilet shaderEffect =drawing.ShaderEffect.createLinearGradient(startPt, endPt, [0xFF00FF00, 0xFFFF0000], drawing.TileMode.REPEAT);
8049e41f4b71Sopenharmony_ci```
8050e41f4b71Sopenharmony_ci
8051e41f4b71Sopenharmony_ci### createRadialGradient<sup>12+</sup>
8052e41f4b71Sopenharmony_ci
8053e41f4b71Sopenharmony_cistatic createRadialGradient(centerPt: common2D.Point, radius: number, colors: Array\<number>, mode: TileMode, pos?: Array\<number> | null, matrix?: Matrix | null): ShaderEffect;
8054e41f4b71Sopenharmony_ci
8055e41f4b71Sopenharmony_ciCreates a **ShaderEffect** object that generates a radial gradient based on the center and radius of a circle. The radial gradient transitions colors from the center to the ending shape in a radial manner.
8056e41f4b71Sopenharmony_ci
8057e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
8058e41f4b71Sopenharmony_ci
8059e41f4b71Sopenharmony_ci**Parameters**
8060e41f4b71Sopenharmony_ci
8061e41f4b71Sopenharmony_ci| Name| Type                                              | Mandatory| Description          |
8062e41f4b71Sopenharmony_ci| ------ | -------------------------------------------------- | ---- | -------------- |
8063e41f4b71Sopenharmony_ci| centerPt  | [common2D.Point](js-apis-graphics-common2D.md#point)  | Yes  | Center of the circle.|
8064e41f4b71Sopenharmony_ci| radius   | number  | Yes  | Radius of the gradient. A negative number is invalid. The value is a floating point number.|
8065e41f4b71Sopenharmony_ci| colors | Array\<number> | Yes  | Array of colors to distribute between the center and ending shape of the circle. The values in the array are 32-bit (ARGB) unsigned integers.|
8066e41f4b71Sopenharmony_ci| mode  | [TileMode](#tilemode12) | Yes  | Tile mode of the shader effect.|
8067e41f4b71Sopenharmony_ci| pos | Array\<number> \| null | No  | Relative position of each color in the color array. The array length must be the same as that of **colors**. The first element in the array must be 0.0, the last element must be 1.0, and the middle elements must be between 0.0 and 1.0 and increase by index. The default value is null, indicating that colors are evenly distributed between the center and ending shape of the circle.|
8068e41f4b71Sopenharmony_ci| matrix | [Matrix](#matrix12) \| null | No  | **Matrix** object used to perform matrix transformation on the shader effect. The default value is null, indicating the identity matrix.|
8069e41f4b71Sopenharmony_ci
8070e41f4b71Sopenharmony_ci![RadialGradient](./figures/image_createRadialGradient.png)
8071e41f4b71Sopenharmony_ci
8072e41f4b71Sopenharmony_ciThe preceding figure shows the display effect when the **colors** array is set to red, green, and blue and the **pos** array is set to 0.0, 0.75, and 1.0. The triangle subscript is the relative position of the color between the center and ending shape of the circle. Gradient colors are used between them.
8073e41f4b71Sopenharmony_ci
8074e41f4b71Sopenharmony_ci**Return value**
8075e41f4b71Sopenharmony_ci
8076e41f4b71Sopenharmony_ci| Type   | Description                      |
8077e41f4b71Sopenharmony_ci| ------- | ------------------------- |
8078e41f4b71Sopenharmony_ci| [ShaderEffect](#shadereffect12) | **ShaderEffect** object created.|
8079e41f4b71Sopenharmony_ci
8080e41f4b71Sopenharmony_ci**Error codes**
8081e41f4b71Sopenharmony_ci
8082e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
8083e41f4b71Sopenharmony_ci
8084e41f4b71Sopenharmony_ci| ID| Error Message|
8085e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
8086e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; 3. Parameter verification failed. |
8087e41f4b71Sopenharmony_ci
8088e41f4b71Sopenharmony_ci**Example**
8089e41f4b71Sopenharmony_ci
8090e41f4b71Sopenharmony_ci```ts
8091e41f4b71Sopenharmony_ciimport { common2D,drawing } from '@kit.ArkGraphics2D';
8092e41f4b71Sopenharmony_ci
8093e41f4b71Sopenharmony_cilet centerPt: common2D.Point = { x: 100, y: 100 };
8094e41f4b71Sopenharmony_cilet shaderEffect = drawing.ShaderEffect.createRadialGradient(centerPt, 100, [0xFF00FF00, 0xFFFF0000], drawing.TileMode.REPEAT);
8095e41f4b71Sopenharmony_ci```
8096e41f4b71Sopenharmony_ci
8097e41f4b71Sopenharmony_ci### createSweepGradient<sup>12+</sup>
8098e41f4b71Sopenharmony_ci
8099e41f4b71Sopenharmony_cistatic createSweepGradient(centerPt: common2D.Point, colors: Array\<number>,
8100e41f4b71Sopenharmony_ci  mode: TileMode, startAngle: number, endAngle: number, pos?: Array\<number> | null,
8101e41f4b71Sopenharmony_ci  matrix?: Matrix | null): ShaderEffect;
8102e41f4b71Sopenharmony_ci
8103e41f4b71Sopenharmony_ciCreates a **ShaderEffect** object that generates a sweep gradient based on the center. A sweep gradient paints a gradient of colors in a clockwise or counterclockwise direction based on a given circle center.
8104e41f4b71Sopenharmony_ci
8105e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
8106e41f4b71Sopenharmony_ci
8107e41f4b71Sopenharmony_ci**Parameters**
8108e41f4b71Sopenharmony_ci
8109e41f4b71Sopenharmony_ci| Name| Type                                              | Mandatory| Description          |
8110e41f4b71Sopenharmony_ci| ------ | -------------------------------------------------- | ---- | -------------- |
8111e41f4b71Sopenharmony_ci| centerPt  | [common2D.Point](js-apis-graphics-common2D.md#point)  | Yes  | Center of the circle.|
8112e41f4b71Sopenharmony_ci| colors | Array\<number> | Yes  | Array of colors to distribute between the start angle and end angle. The values in the array are 32-bit (ARGB) unsigned integers.|
8113e41f4b71Sopenharmony_ci| mode  | [TileMode](#tilemode12) | Yes  | Tile mode of the shader effect.|
8114e41f4b71Sopenharmony_ci| startAngle | number | Yes  | Start angle of the sweep gradient, in degrees. The value 0 indicates the positive direction of the X axis. A positive number indicates an offset towards the positive direction, and a negative number indicates an offset towards the negative direction. The value is a floating point number.|
8115e41f4b71Sopenharmony_ci| endAngle | number | Yes  | End angle of the sweep gradient, in degrees. The value 0 indicates the positive direction of the X axis. A positive number indicates an offset towards the positive direction, and a negative number indicates an offset towards the negative direction. A value less than the start angle is invalid. The value is a floating point number.|
8116e41f4b71Sopenharmony_ci| pos | Array\<number> \| null | No  | Relative position of each color in the color array. The array length must be the same as that of **colors**. The first element in the array must be 0.0, the last element must be 1.0, and the middle elements must be between 0.0 and 1.0 and increase by index. The default value is null, indicating that the colors are evenly distributed between the start angle and end angle.|
8117e41f4b71Sopenharmony_ci| matrix | [Matrix](#matrix12) \| null | No  |**Matrix** object used to perform matrix transformation on the shader effect. The default value is null, indicating the identity matrix.|
8118e41f4b71Sopenharmony_ci
8119e41f4b71Sopenharmony_ci![SweepGradient](./figures/image_createSweepGradient.png)
8120e41f4b71Sopenharmony_ci
8121e41f4b71Sopenharmony_ciThe preceding figure shows the display effect when the **colors** array is set to red, green, and blue, the **pos** array is set to 0.0, 0.75, and 1.0, **startAngle** is set to 0 degrees, and **endAngle** is set to 180 degrees. In the figure, **0.0** corresponds to the position of 0 degrees, **0.75** corresponds to the position of 135 degrees, and **1.0** corresponds to the position of 180 degrees. Gradient colors are used between them.
8122e41f4b71Sopenharmony_ci
8123e41f4b71Sopenharmony_ci**Return value**
8124e41f4b71Sopenharmony_ci
8125e41f4b71Sopenharmony_ci| Type   | Description                      |
8126e41f4b71Sopenharmony_ci| ------- | ------------------------- |
8127e41f4b71Sopenharmony_ci| [ShaderEffect](#shadereffect12) | **ShaderEffect** object created.|
8128e41f4b71Sopenharmony_ci
8129e41f4b71Sopenharmony_ci**Error codes**
8130e41f4b71Sopenharmony_ci
8131e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
8132e41f4b71Sopenharmony_ci
8133e41f4b71Sopenharmony_ci| ID| Error Message|
8134e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
8135e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; 3. Parameter verification failed. |
8136e41f4b71Sopenharmony_ci
8137e41f4b71Sopenharmony_ci**Example**
8138e41f4b71Sopenharmony_ci
8139e41f4b71Sopenharmony_ci```ts
8140e41f4b71Sopenharmony_ciimport { common2D,drawing } from '@kit.ArkGraphics2D';
8141e41f4b71Sopenharmony_ci
8142e41f4b71Sopenharmony_cilet centerPt: common2D.Point = { x: 100, y: 100 };
8143e41f4b71Sopenharmony_cilet shaderEffect = drawing.ShaderEffect.createSweepGradient(centerPt, [0xFF00FF00, 0xFFFF0000], drawing.TileMode.REPEAT, 100, 200);
8144e41f4b71Sopenharmony_ci```
8145e41f4b71Sopenharmony_ci
8146e41f4b71Sopenharmony_ci### createConicalGradient<sup>12+</sup>
8147e41f4b71Sopenharmony_ci
8148e41f4b71Sopenharmony_cistatic createConicalGradient(startPt: common2D.Point, startRadius: number, endPt: common2D.Point, endRadius: number, colors: Array\<number>, mode: TileMode, 
8149e41f4b71Sopenharmony_cipos?: Array\<number> | null, matrix?: Matrix | null): ShaderEffect;
8150e41f4b71Sopenharmony_ci
8151e41f4b71Sopenharmony_ciCreates a **ShaderEffect** object that generates a conical gradient between two given circles.
8152e41f4b71Sopenharmony_ci
8153e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
8154e41f4b71Sopenharmony_ci
8155e41f4b71Sopenharmony_ci**Parameters**
8156e41f4b71Sopenharmony_ci
8157e41f4b71Sopenharmony_ci| Name| Type                                              | Mandatory| Description          |
8158e41f4b71Sopenharmony_ci| ------ | -------------------------------------------------- | ---- | -------------- |
8159e41f4b71Sopenharmony_ci| startPt  | [common2D.Point](js-apis-graphics-common2D.md#point)  | Yes  |Center of the start circle of the gradient.|
8160e41f4b71Sopenharmony_ci| startRadius | number | Yes  | Radius of the start circle of the gradient. A negative number is invalid. The value is a floating point number.|
8161e41f4b71Sopenharmony_ci| endPt  | [common2D.Point](js-apis-graphics-common2D.md#point)  | Yes  | Center of the end circle of the gradient.|
8162e41f4b71Sopenharmony_ci| endRadius | number | Yes  | Radius of the end circle of the gradient. A negative value is invalid. The value is a floating point number.|
8163e41f4b71Sopenharmony_ci| colors | Array\<number> | Yes  | Array of colors to distribute between the start circle and end circle. The values in the array are 32-bit (ARGB) unsigned integers.|
8164e41f4b71Sopenharmony_ci| mode  | [TileMode](#tilemode12) | Yes  | Tile mode of the shader effect.|
8165e41f4b71Sopenharmony_ci| pos | Array\<number> \| null | No  | Relative position of each color in the color array. The array length must be the same as that of **colors**. The first element in the array must be 0.0, the last element must be 1.0, and the middle elements must be between 0.0 and 1.0 and increase by index. The default value is null, indicating that colors are evenly distributed between the two circles.|
8166e41f4b71Sopenharmony_ci| matrix | [Matrix](#matrix12) \| null | No  | **Matrix** object used to perform matrix transformation on the shader effect. The default value is null, indicating the identity matrix.|
8167e41f4b71Sopenharmony_ci
8168e41f4b71Sopenharmony_ci![ConicalGradient](./figures/image_createConicalGradient.png)
8169e41f4b71Sopenharmony_ci
8170e41f4b71Sopenharmony_ciThe preceding figure shows the display effect when the **colors** array is set to red, green, and blue and the **pos** array is set to 0.0, 0.5, and 1.0. The left part shows the drawing result when the start circle is not in the end circle, and the right part shows the drawing result when the start circle is in the end circle.
8171e41f4b71Sopenharmony_ci
8172e41f4b71Sopenharmony_ci**Return value**
8173e41f4b71Sopenharmony_ci
8174e41f4b71Sopenharmony_ci| Type   | Description                      |
8175e41f4b71Sopenharmony_ci| ------- | ------------------------- |
8176e41f4b71Sopenharmony_ci| [ShaderEffect](#shadereffect12) | **ShaderEffect** object created.|
8177e41f4b71Sopenharmony_ci
8178e41f4b71Sopenharmony_ci**Error codes**
8179e41f4b71Sopenharmony_ci
8180e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
8181e41f4b71Sopenharmony_ci
8182e41f4b71Sopenharmony_ci| ID| Error Message|
8183e41f4b71Sopenharmony_ci| ------- | --------------------------------------------|
8184e41f4b71Sopenharmony_ci| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; 3. Parameter verification failed. |
8185e41f4b71Sopenharmony_ci
8186e41f4b71Sopenharmony_ci**Example**
8187e41f4b71Sopenharmony_ci
8188e41f4b71Sopenharmony_ci```ts
8189e41f4b71Sopenharmony_ciimport { common2D,drawing } from '@kit.ArkGraphics2D';
8190e41f4b71Sopenharmony_ci
8191e41f4b71Sopenharmony_cilet startPt: common2D.Point = { x: 100, y: 100 };
8192e41f4b71Sopenharmony_cilet endPt: common2D.Point = {x: 200, y: 200};
8193e41f4b71Sopenharmony_cilet shaderEffect = drawing.ShaderEffect.createConicalGradient(startPt, 100, endPt, 50, [0xFF00FF00, 0xFFFF0000], drawing.TileMode.REPEAT);
8194e41f4b71Sopenharmony_ci```
8195e41f4b71Sopenharmony_ci
8196e41f4b71Sopenharmony_ci## RegionOp<sup>12+</sup>
8197e41f4b71Sopenharmony_ci
8198e41f4b71Sopenharmony_ciEnumerates the operations for combining two regions.
8199e41f4b71Sopenharmony_ci
8200e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
8201e41f4b71Sopenharmony_ci
8202e41f4b71Sopenharmony_ci| Name                  | Value  | Description                          | Diagram  |
8203e41f4b71Sopenharmony_ci| --------------------- | ---- | ------------------------------ | -------- |
8204e41f4b71Sopenharmony_ci| DIFFERENCE         | 0    | Difference operation. | ![CLEAR](./figures/image_RegionOp_Difference.png)|
8205e41f4b71Sopenharmony_ci| INTERSECT          | 1    | Intersect operation.| ![INTERSECT](./figures/image_RegionOp_Intersect.png)|
8206e41f4b71Sopenharmony_ci| UNION              | 2    | Union operation.  | ![UNION](./figures/image_RegionOpe_Union.png)|
8207e41f4b71Sopenharmony_ci| XOR                | 3    | XOR operation.  | ![XOR](./figures/image_RegionOp_Xor.png)|
8208e41f4b71Sopenharmony_ci| REVERSE_DIFFERENCE | 4    | Reverse difference operation.  | ![REVERSE_DIFFERENCE](./figures/image_RegionOp_Reverse_difference.png)|
8209e41f4b71Sopenharmony_ci| REPLACE            | 5    | Replace operation.  | ![REPLACE](./figures/image_RegionOp_Replace.png)|
8210e41f4b71Sopenharmony_ci
8211e41f4b71Sopenharmony_ci> **NOTE**
8212e41f4b71Sopenharmony_ci>
8213e41f4b71Sopenharmony_ci> The schematic diagram shows the result obtained by combining a red region with a blue region at different operation mode. The green region is the region obtained.
8214e41f4b71Sopenharmony_ci
8215e41f4b71Sopenharmony_ci## CornerPos<sup>12+</sup>
8216e41f4b71Sopenharmony_ci
8217e41f4b71Sopenharmony_ciEnumerates the corner positions of a rounded rectangle.
8218e41f4b71Sopenharmony_ci
8219e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Graphics.Drawing
8220e41f4b71Sopenharmony_ci
8221e41f4b71Sopenharmony_ci| Name                  | Value  | Description                          |
8222e41f4b71Sopenharmony_ci| --------------------- | ---- | ------------------------------ | 
8223e41f4b71Sopenharmony_ci| TOP_LEFT_POS          | 0    | Top left corner of the rounded rectangle. |
8224e41f4b71Sopenharmony_ci| TOP_RIGHT_POS         | 1    | Top right corner of the rounded rectangle.|
8225e41f4b71Sopenharmony_ci| BOTTOM_RIGHT_POS      | 2    | Bottom right corner of the rounded rectangle.  |
8226e41f4b71Sopenharmony_ci| BOTTOM_LEFT_POS       | 3    | Bottom left corner of the rounded rectangle.  |
8227