1# @ohos.graphics.drawing (Drawing)
2
3The Drawing module provides basic drawing capabilities, such as drawing rectangles, circles, points, straight lines, custom paths, and fonts.
4
5> **NOTE**
6>
7> - 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.
8>
9> - This module uses the physical pixel unit, px.
10>
11> - The module operates under a single-threaded model. The caller needs to manage thread safety and context state transitions.
12
13## Modules to Import
14
15```ts
16import { drawing } from '@kit.ArkGraphics2D';
17```
18
19## BlendMode
20
21Enumerates 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.
22
23For brevity, the following abbreviations are used:
24
25**s**: source. **d**: destination. **sa**: source alpha. **da**: destination alpha.
26
27The following abbreviations are used in the calculation result:
28
29**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.
30
31The table below shows the effect of each blend mode, where the yellow rectangle is the source and the blue circle is the destination.
32
33**System capability**: SystemCapability.Graphics.Drawing
34
35| Name       | Value  | Description                                                        | Diagram  |
36| ----------- | ---- | ------------------------------------------------------------ | -------- |
37| CLEAR       | 0    | Clear mode. r = 0.                                           | ![CLEAR](./figures/image_BlendMode_Clear.png) |
38| 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) |
39| 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) |
40| SRC_OVER    | 3    | r = s + (1 - sa) * d                                         | ![SRC_OVER](./figures/image_BlendMode_SrcOver.png) |
41| DST_OVER    | 4    | r = d + (1 - da) * s                                         | ![DST_OVER](./figures/image_BlendMode_DstOver.png) |
42| SRC_IN      | 5    | r = s * da                                                   | ![SRC_IN](./figures/image_BlendMode_SrcIn.png) |
43| DST_IN      | 6    | r = d * sa                                                   | ![DST_IN](./figures/image_BlendMode_DstIn.png) |
44| SRC_OUT     | 7    | r = s * (1 - da)                                             | ![SRC_OUT](./figures/image_BlendMode_SrcOut.png) |
45| DST_OUT     | 8    | r = d * (1 - sa)                                             | ![DST_OUT](./figures/image_BlendMode_DstOut.png) |
46| SRC_ATOP    | 9    | r = s * da + d * (1 - sa)                                    | ![SRC_ATOP](./figures/image_BlendMode_SrcATop.png) |
47| DST_ATOP    | 10   | r = d * sa + s * (1 - da)                                    | ![DST_ATOP](./figures/image_BlendMode_DstATop.png) |
48| XOR         | 11   | r = s * (1 - da) + d * (1 - sa)                              | ![XOR](./figures/image_BlendMode_Xor.png) |
49| PLUS        | 12   | r = min(s + d, 1)                                            | ![PLUS](./figures/image_BlendMode_Plus.png) |
50| MODULATE    | 13   | r = s * d                                                    | ![MODULATE](./figures/image_BlendMode_Modulate.png) |
51| SCREEN      | 14   | Screen mode. r = s + d - s * d                                  | ![SCREEN](./figures/image_BlendMode_Screen.png) |
52| OVERLAY     | 15   | Overlay mode.                                                    | ![OVERLAY](./figures/image_BlendMode_Overlay.png) |
53| DARKEN      | 16   | Darken mode. rc = s + d - max(s * da, d * sa), ra = s + (1 - sa) * d | ![DARKEN](./figures/image_BlendMode_Darken.png) |
54| LIGHTEN     | 17   | Lighten mode. rc = rc = s + d - min(s * da, d * sa), ra = s + (1 - sa) * d | ![LIGHTEN](./figures/image_BlendMode_Lighten.png) |
55| COLOR_DODGE | 18   | Color dodge mode.                                                | ![COLOR_DODGE](./figures/image_BlendMode_ColorDodge.png) |
56| COLOR_BURN  | 19   | Color burn mode.                                                | ![COLOR_BURN](./figures/image_BlendMode_ColorBurn.png) |
57| HARD_LIGHT  | 20   | Hard light mode.                                                    | ![HARD_LIGHT](./figures/image_BlendMode_HardLight.png) |
58| SOFT_LIGHT  | 21   | Soft light mode.                                                    | ![SOFT_LIGHT](./figures/image_BlendMode_SoftLight.png) |
59| DIFFERENCE  | 22   | Difference mode. rc = s + d - 2 * (min(s * da, d * sa)), ra = s + (1 - sa) * d | ![DIFFERENCE](./figures/image_BlendMode_Difference.png) |
60| EXCLUSION   | 23   | Exclusion mode. rc = s + d - two(s * d), ra = s + (1 - sa) * d     | ![EXCLUSION](./figures/image_BlendMode_Exclusion.png) |
61| MULTIPLY    | 24   | Multiply mode. r = s * (1 - da) + d * (1 - sa) + s * d            | ![MULTIPLY](./figures/image_BlendMode_Multiply.png) |
62| HUE         | 25   | Hue mode.                                                    | ![HUE](./figures/image_BlendMode_Hue.png) |
63| SATURATION  | 26   | Saturation mode.                                                  | ![SATURATION](./figures/image_BlendMode_Saturation.png) |
64| COLOR       | 27   | Color mode.                                                    | ![COLOR](./figures/image_BlendMode_Color.png) |
65| LUMINOSITY  | 28   | Luminosity mode.                                                    | ![LUMINOSITY](./figures/image_BlendMode_Luminosity.png) |
66
67## PathMeasureMatrixFlags<sup>12+</sup>
68
69Enumerates the types of matrix information obtained during path measurement.
70
71**System capability**: SystemCapability.Graphics.Drawing
72
73| Name       | Value  | Description                                                        |
74| ----------- | ---- | ------------------------------------------------------------ |
75| GET_POSITION_MATRIX        | 0    | Matrix corresponding to the position information.                                           |
76| GET_TANGENT_MATRIX          | 1    | Matrix corresponding to the tangent information.|
77| GET_POSITION_AND_TANGENT_MATRIX    | 2     | Matrix corresponding to the position and tangent information.|
78
79## SrcRectConstraint<sup>12+</sup>
80
81Enumerates the constraint types of the source rectangle.
82
83**System capability**: SystemCapability.Graphics.Drawing
84
85| Name       | Value  | Description                                                        |
86| ----------- | ---- | ------------------------------------------------------------ |
87| STRICT         | 0    | The sampling range is strictly confined to the source rectangle, resulting in a slow sampling speed.                                           |
88| FAST           | 1    | The sampling range is not limited to the source rectangle and can extend beyond it, allowing for a high sampling speed.|
89
90## ShadowFlag<sup>12+</sup>
91
92Enumerates the flags used to control shadow drawing to create various shadow effects.
93
94**System capability**: SystemCapability.Graphics.Drawing
95
96| Name                        | Value   | Description                |
97| -------------------------- | ---- | ------------------ |
98| NONE      | 0    | None of the flags are enabled.       |
99| TRANSPARENT_OCCLUDER | 1    | The occluder is transparent.        |
100| GEOMETRIC_ONLY    | 2    | Only the geometric shadow effect is used.       |
101| ALL           | 3    | All the flags are enabled.|
102
103## PathOp<sup>12+</sup>
104
105Enumerates the operation modes available for a path.
106
107**System capability**: SystemCapability.Graphics.Drawing
108
109| Name                  | Value  | Description                          |
110| ---------------------- | ---- | ------------------------------ |
111| DIFFERENCE     | 0    | Difference operation.|
112| INTERSECT    | 1    | Intersection operation.|
113| UNION    | 2    | Union operation.|
114| XOR     | 3    | XOR operation.|
115| REVERSE_DIFFERENCE     | 4    | Reverse difference operation.|
116
117## Path
118
119A compound geometric path consisting of line segments, arcs, quadratic Bezier curves, and cubic Bezier curves.
120
121### constructor<sup>12+</sup>
122
123constructor()
124
125Constructs a path.
126
127**System capability**: SystemCapability.Graphics.Drawing
128
129**Example**
130
131```ts
132import { drawing } from '@kit.ArkGraphics2D';
133let path: drawing.Path = new drawing.Path();
134```
135
136### constructor<sup>12+</sup>
137
138constructor(path: Path)
139
140Constructs a copy of an existing path.
141
142**System capability**: SystemCapability.Graphics.Drawing
143
144**Parameters**
145
146| Name  | Type                                        | Mandatory| Description                           |
147| -------- | -------------------------------------------- | ---- | ------------------------------- |
148| path | [Path](#path) | Yes  | Path to copy.                |
149
150**Example**
151
152```ts
153import { drawing } from '@kit.ArkGraphics2D';
154let path: drawing.Path = new drawing.Path();
155path.moveTo(0, 0);
156path.lineTo(0, 700);
157path.lineTo(700, 0);
158path.close();
159let path1: drawing.Path =  new drawing.Path(path);
160```
161
162### moveTo
163
164moveTo(x: number, y: number) : void
165
166Sets the start point of this path.
167
168**System capability**: SystemCapability.Graphics.Drawing
169
170**Parameters**
171
172| Name| Type  | Mandatory| Description                   |
173| ------ | ------ | ---- | ----------------------- |
174| x      | number | Yes  | X coordinate of the start point. The value is a floating point number.|
175| y      | number | Yes  | Y coordinate of the start point. The value is a floating point number.|
176
177**Error codes**
178
179For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
180
181| ID| Error Message|
182| ------- | --------------------------------------------|
183| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
184
185**Example**
186
187```ts
188import { drawing } from '@kit.ArkGraphics2D';
189let path = new drawing.Path();
190path.moveTo(10,10);
191```
192
193### lineTo
194
195lineTo(x: number, y: number) : void
196
197Draws 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.
198
199**System capability**: SystemCapability.Graphics.Drawing
200
201**Parameters**
202
203| Name| Type  | Mandatory| Description                   |
204| ------ | ------ | ---- | ----------------------- |
205| x      | number | Yes  | X coordinate of the target point. The value is a floating point number.|
206| y      | number | Yes  | Y coordinate of the target point. The value is a floating point number.|
207
208**Error codes**
209
210For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
211
212| ID| Error Message|
213| ------- | --------------------------------------------|
214| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
215
216**Example**
217
218```ts
219import { drawing } from '@kit.ArkGraphics2D';
220let path = new drawing.Path();
221path.moveTo(10,10);
222path.lineTo(10, 15);
223```
224
225### arcTo
226
227arcTo(x1: number, y1: number, x2: number, y2: number, startDeg: number, sweepDeg: number): void
228
229Draws 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.
230
231**System capability**: SystemCapability.Graphics.Drawing
232
233**Parameters**
234
235| Name  | Type  | Mandatory| Description                      |
236| -------- | ------ | ---- | -------------------------- |
237| x1       | number | Yes  | X coordinate of the upper left corner of the rectangle. The value is a floating point number.|
238| y1       | number | Yes  | Y coordinate of the upper left corner of the rectangle. The value is a floating point number.|
239| x2       | number | Yes  | X coordinate of the lower right corner of the rectangle. The value is a floating point number.|
240| y2       | number | Yes  | Y coordinate of the lower right corner of the rectangle. The value is a floating point number.|
241| startDeg | number | Yes  | Start angle, in degrees. The value is a floating point number.|
242| sweepDeg | number | Yes  | Sweep degree. The value is a floating point number.|
243
244**Error codes**
245
246For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
247
248| ID| Error Message|
249| ------- | --------------------------------------------|
250| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
251
252**Example**
253
254```ts
255import { drawing } from '@kit.ArkGraphics2D';
256let path = new drawing.Path();
257path.moveTo(10,10);
258path.arcTo(10, 15, 10, 10, 10, 10);
259```
260
261### quadTo
262
263quadTo(ctrlX: number, ctrlY: number, endX: number, endY: number): void
264
265Draws 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.
266
267**System capability**: SystemCapability.Graphics.Drawing
268
269**Parameters**
270
271| Name| Type  | Mandatory| Description                 |
272| ------ | ------ | ---- | --------------------- |
273| ctrlX  | number | Yes  | X coordinate of the control point. The value is a floating point number.|
274| ctrlY  | number | Yes  | Y coordinate of the control point. The value is a floating point number.|
275| endX   | number | Yes  | X coordinate of the target point. The value is a floating point number.|
276| endY   | number | Yes  | Y coordinate of the target point. The value is a floating point number.|
277
278**Error codes**
279
280For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
281
282| ID| Error Message|
283| ------- | --------------------------------------------|
284| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
285
286**Example**
287
288```ts
289import { drawing } from '@kit.ArkGraphics2D';
290let path = new drawing.Path();
291path.moveTo(10,10);
292path.quadTo(10, 15, 10, 10);
293```
294
295### conicTo<sup>12+</sup>
296
297conicTo(ctrlX: number, ctrlY: number, endX: number, endY: number, weight: number): void
298
299Draws 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.
300
301**System capability**: SystemCapability.Graphics.Drawing
302
303**Parameters**
304
305| Name| Type  | Mandatory| Description                 |
306| ------ | ------ | ---- | --------------------- |
307| ctrlX  | number | Yes  | X coordinate of the control point. The value is a floating point number.|
308| ctrlY  | number | Yes  | Y coordinate of the control point. The value is a floating point number.|
309| endX   | number | Yes  | X coordinate of the target point. The value is a floating point number.|
310| endY   | number | Yes  | Y coordinate of the target point. The value is a floating point number.|
311| 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.|
312
313**Error codes**
314
315For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
316
317| ID| Error Message|
318| ------- | --------------------------------------------|
319| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
320
321**Example**
322
323```ts
324import { drawing } from '@kit.ArkGraphics2D';
325
326const path = new drawing.Path();
327path.conicTo(200, 400, 100, 200, 0);
328```
329
330### cubicTo
331
332cubicTo(ctrlX1: number, ctrlY1: number, ctrlX2: number, ctrlY2: number, endX: number, endY: number): void
333
334Draws 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.
335
336**System capability**: SystemCapability.Graphics.Drawing
337
338**Parameters**
339
340| Name| Type  | Mandatory| Description                       |
341| ------ | ------ | ---- | --------------------------- |
342| ctrlX1 | number | Yes  | X coordinate of the first control point. The value is a floating point number.|
343| ctrlY1 | number | Yes  | Y coordinate of the first control point. The value is a floating point number.|
344| ctrlX2 | number | Yes  | X coordinate of the second control point. The value is a floating point number.|
345| ctrlY2 | number | Yes  | Y coordinate of the second control point. The value is a floating point number.|
346| endX   | number | Yes  | X coordinate of the target point. The value is a floating point number.|
347| endY   | number | Yes  | Y coordinate of the target point. The value is a floating point number.|
348
349**Error codes**
350
351For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
352
353| ID| Error Message|
354| ------- | --------------------------------------------|
355| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
356
357**Example**
358
359```ts
360import { drawing } from '@kit.ArkGraphics2D';
361let path = new drawing.Path();
362path.moveTo(10,10);
363path.cubicTo(10, 10, 10, 10, 15, 15);
364```
365
366### rMoveTo<sup>12+</sup>
367
368rMoveTo(dx : number, dy : number): void
369
370Sets the start position relative to the last point of this path. If the path is empty, the start point (0, 0) is used.
371
372**System capability**: SystemCapability.Graphics.Drawing
373
374**Parameters**
375
376| Name| Type  | Mandatory| Description                   |
377| ------ | ------ | ---- | ----------------------- |
378| 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.|
379| 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.|
380
381**Error codes**
382
383For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
384
385| ID| Error Message|
386| ------- | --------------------------------------------|
387| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
388
389**Example**
390
391```ts
392import { drawing } from '@kit.ArkGraphics2D';
393
394const path = new drawing.Path();
395path.rMoveTo(10, 10);
396```
397
398### rLineTo<sup>12+</sup>
399
400rLineTo(dx : number, dy : number): void
401
402Draws 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.
403
404**System capability**: SystemCapability.Graphics.Drawing
405
406**Parameters**
407
408| Name| Type  | Mandatory| Description                   |
409| ------ | ------ | ---- | ----------------------- |
410| 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.|
411| 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.|
412
413**Error codes**
414
415For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
416
417| ID| Error Message|
418| ------- | --------------------------------------------|
419| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
420
421**Example**
422
423```ts
424import { drawing } from '@kit.ArkGraphics2D';
425
426const path = new drawing.Path();
427path.rLineTo(400, 200);
428```
429
430### rQuadTo<sup>12+</sup>
431
432rQuadTo(dx1: number, dy1: number, dx2: number, dy2: number): void
433
434Draws 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.
435
436**System capability**: SystemCapability.Graphics.Drawing
437
438**Parameters**
439
440| Name| Type  | Mandatory| Description                 |
441| ------ | ------ | ---- | --------------------- |
442| 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.|
443| 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.|
444| 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.|
445| 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.|
446
447**Error codes**
448
449For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
450
451| ID| Error Message|
452| ------- | --------------------------------------------|
453| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
454
455**Example**
456
457```ts
458import { drawing } from '@kit.ArkGraphics2D';
459
460const path = new drawing.Path();
461path.rQuadTo(100, 0, 0, 200);
462```
463
464### rConicTo<sup>12+</sup>
465
466rConicTo(ctrlX: number, ctrlY: number, endX: number, endY: number, weight: number): void
467
468Draws 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.
469
470**System capability**: SystemCapability.Graphics.Drawing
471
472**Parameters**
473
474| Name| Type  | Mandatory| Description                 |
475| ------ | ------ | ---- | --------------------- |
476| 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.|
477| 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.|
478| 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.|
479| 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.|
480| 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.|
481
482**Error codes**
483
484For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
485
486| ID| Error Message|
487| ------- | --------------------------------------------|
488| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
489
490**Example**
491
492```ts
493import { drawing } from '@kit.ArkGraphics2D';
494
495const path = new drawing.Path();
496path.rConicTo(200, 400, 100, 200, 0);
497```
498
499### rCubicTo<sup>12+</sup>
500
501rCubicTo(ctrlX1: number, ctrlY1: number, ctrlX2: number, ctrlY2: number, endX: number, endY: number): void
502
503Draws 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.
504
505**System capability**: SystemCapability.Graphics.Drawing
506
507**Parameters**
508
509| Name| Type  | Mandatory| Description                       |
510| ------ | ------ | ---- | --------------------------- |
511| 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.|
512| 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.|
513| 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.|
514| 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.|
515| 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.|
516| 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.|
517
518**Error codes**
519
520For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
521
522| ID| Error Message|
523| ------- | --------------------------------------------|
524| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
525
526**Example**
527
528```ts
529import { drawing } from '@kit.ArkGraphics2D';
530
531const path = new drawing.Path();
532path.rCubicTo(200, 0, 0, 200, -20, 0);
533```
534
535### addArc<sup>12+</sup>
536
537addArc(rect: common2D.Rect, startAngle: number, sweepAngle: number): void
538
539Adds an arc to this path.
540When **startAngle** and **sweepAngle** meet the following conditions, an oval instead of an arc is added:
5411. The result of **startAngle** modulo 90 is close to 0.
5422. The value of **sweepAngle** is not in the range of (-360, 360).
543In other cases, this API adds an arc by applying the result of **sweepAngle** modulo 360 to the path.
544
545**System capability**: SystemCapability.Graphics.Drawing
546
547**Parameters**
548
549| Name        | Type                                      | Mandatory  | Description                 |
550| ----------- | ---------------------------------------- | ---- | ------------------- |
551| rect        | [common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes   | Rectangular boundary that encapsulates the oval including the arc.     |
552| 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.|
553| 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.|
554
555**Error codes**
556
557For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
558
559| ID| Error Message|
560| ------- | --------------------------------------------|
561| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
562
563**Example**
564
565```ts
566import { common2D, drawing } from '@kit.ArkGraphics2D';
567
568let path = new drawing.Path();
569const rect: common2D.Rect = {left:100, top:100, right:500, bottom:500};
570path.addArc(rect, 90, 180);
571```
572
573### addCircle<sup>12+</sup>
574
575addCircle(x: number, y: number, radius: number, pathDirection?: PathDirection): void
576
577Adds a circle to this path in the specified direction. The start point of the circle is (x + radius, y).
578
579**System capability**: SystemCapability.Graphics.Drawing
580
581**Parameters**
582
583| Name        | Type                                      | Mandatory  | Description                 |
584| ----------- | ---------------------------------------- | ---- | ------------------- |
585| x   | number | Yes  | X coordinate of the center of the circle. The value is a floating point number.|
586| y   | number | Yes  | Y coordinate of the center of the circle. The value is a floating point number.|
587| 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.|
588| pathDirection   | [PathDirection](#pathdirection12)  | No  | Direction of the path. The default direction is clockwise.|
589
590**Error codes**
591
592For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
593
594| ID| Error Message|
595| ------- | --------------------------------------------|
596| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
597
598**Example**
599
600```ts
601
602import { drawing } from '@kit.ArkGraphics2D';
603
604let path = new drawing.Path();
605path.addCircle(100, 200, 50, drawing.PathDirection.CLOCKWISE);
606```
607
608### addOval<sup>12+</sup>
609
610addOval(rect: common2D.Rect, start: number, pathDirection?: PathDirection): void
611
612Adds an oval to this path in the specified direction, where the **common2D.Rect** object specifies the outer tangent rectangle of the oval.
613
614**System capability**: SystemCapability.Graphics.Drawing
615
616**Parameters**
617
618| Name        | Type                                      | Mandatory  | Description                 |
619| ----------- | ---------------------------------------- | ---- | ------------------- |
620| rect        | [common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes   | Rectangular boundary of the oval.     |
621| 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.|
622| pathDirection   | [PathDirection](#pathdirection12)  | No  | Direction of the path. The default direction is clockwise.|
623
624**Error codes**
625
626For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
627
628| ID| Error Message|
629| ------- | --------------------------------------------|
630| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.|
631
632**Example**
633
634```ts
635import { common2D, drawing } from '@kit.ArkGraphics2D';
636
637let path = new drawing.Path();
638const rect: common2D.Rect = {left:100, top:100, right:500, bottom:500};
639path.addOval(rect, 5, drawing.PathDirection.CLOCKWISE);
640```
641
642### addRect<sup>12+</sup>
643
644addRect(rect: common2D.Rect, pathDirection?: PathDirection): void
645
646Adds a rectangle to this path in the specified direction. The start point is the upper left corner of the rectangle.
647
648**System capability**: SystemCapability.Graphics.Drawing
649
650**Parameters**
651
652| Name        | Type                                      | Mandatory  | Description                 |
653| ----------- | ---------------------------------------- | ---- | ------------------- |
654| rect        | [common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes   | Rectangle.     |
655| pathDirection   | [PathDirection](#pathdirection12)  | No  | Direction of the path. The default direction is clockwise.|
656
657**Error codes**
658
659For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
660
661| ID| Error Message|
662| ------- | --------------------------------------------|
663| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.|
664
665**Example**
666
667```ts
668import { common2D, drawing } from '@kit.ArkGraphics2D';
669
670let path = new drawing.Path();
671const rect: common2D.Rect = {left:100, top:100, right:500, bottom:500};
672path.addRect(rect, drawing.PathDirection.CLOCKWISE);
673```
674
675### addRoundRect<sup>12+</sup>
676
677addRoundRect(roundRect: RoundRect, pathDirection?: PathDirection): void
678
679Adds 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.
680
681**System capability**: SystemCapability.Graphics.Drawing
682
683**Parameters**
684
685| Name        | Type                                      | Mandatory  | Description                 |
686| ----------- | ---------------------------------------- | ---- | ------------------- |
687| roundRect        | [RoundRect](#roundrect12) | Yes   | Rounded rectangle.     |
688| pathDirection   | [PathDirection](#pathdirection12)  | No  | Direction of the path. The default direction is clockwise.|
689
690**Error codes**
691
692For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
693
694| ID| Error Message|
695| ------- | --------------------------------------------|
696| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.|
697
698**Example**
699
700```ts
701import { common2D, drawing } from '@kit.ArkGraphics2D';
702
703let path = new drawing.Path();
704const rect: common2D.Rect = {left:100, top:100, right:500, bottom:500};
705let roundRect = new drawing.RoundRect(rect, 50, 50);
706path.addRoundRect(roundRect, drawing.PathDirection.CLOCKWISE);
707```
708
709### addPath<sup>12+</sup>
710
711addPath(path: Path, matrix?: Matrix | null): void
712
713Transforms the points in a path by a matrix and stores the resulting path in the current **Path** object.
714
715**System capability**: SystemCapability.Graphics.Drawing
716
717**Parameters**
718
719| Name        | Type                                      | Mandatory  | Description                 |
720| ----------- | ---------------------------------------- | ---- | ------------------- |
721| path        | [Path](#path) | Yes   | Source **Path** object.     |
722| matrix   | [Matrix](#matrix12)\|null  | No  | **Matrix** object. The default value is an identity matrix.|
723
724**Error codes**
725
726For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
727
728| ID| Error Message|
729| ------- | --------------------------------------------|
730| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
731
732**Example**
733
734```ts
735import { common2D, drawing } from '@kit.ArkGraphics2D';
736
737let path = new drawing.Path();
738let matrix = new drawing.Matrix();
739const rect: common2D.Rect = {left:100, top:100, right:500, bottom:500};
740let roundRect = new drawing.RoundRect(rect, 50, 50);
741path.addRoundRect(roundRect, drawing.PathDirection.CLOCKWISE);
742let dstPath = new drawing.Path();
743dstPath.addPath(path, matrix);
744```
745
746### transform<sup>12+</sup>
747
748transform(matrix: Matrix): void
749
750Transforms the points in this path by a matrix.
751
752**System capability**: SystemCapability.Graphics.Drawing
753
754**Parameters**
755
756| Name        | Type                                      | Mandatory  | Description                 |
757| ----------- | ---------------------------------------- | ---- | ------------------- |
758| matrix   | [Matrix](#matrix12)  | Yes  | **Matrix** object.|
759
760**Error codes**
761
762For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
763
764| ID| Error Message|
765| ------- | --------------------------------------------|
766| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
767
768**Example**
769
770```ts
771import { common2D, drawing } from '@kit.ArkGraphics2D';
772
773let path = new drawing.Path();
774let matrix = new drawing.Matrix();
775matrix.setScale(1.5, 1.5, 10, 10);
776const rect: common2D.Rect = {left:100, top:100, right:500, bottom:500};
777let roundRect = new drawing.RoundRect(rect, 50, 50);
778path.addRoundRect(roundRect, drawing.PathDirection.CLOCKWISE);
779path.transform(matrix);
780```
781
782### contains<sup>12+</sup>
783
784contains(x: number, y: number): boolean
785
786Checks whether a coordinate point is included in this path. For details, see [PathFillType](#pathfilltype12).
787
788**System capability**: SystemCapability.Graphics.Drawing
789
790**Parameters**
791
792| Name| Type  | Mandatory| Description                   |
793| ------ | ------ | ---- | ----------------------- |
794| x      | number | Yes  | X coordinate. The value is a floating point number.|
795| y      | number | Yes  | Y coordinate. The value is a floating point number.|
796
797**Return value**
798
799| Type   | Description          |
800| ------- | -------------- |
801| 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.|
802
803**Error codes**
804
805For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
806
807| ID| Error Message|
808| ------- | --------------------------------------------|
809| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
810
811**Example**
812
813```ts
814import { common2D, drawing } from '@kit.ArkGraphics2D';
815
816const path = new drawing.Path();
817let rect : common2D.Rect = {left: 50, top: 50, right: 250, bottom: 250};
818path.addRect(rect, drawing.PathDirection.CLOCKWISE);
819console.info("test contains: " + path.contains(0, 0));
820console.info("test contains: " + path.contains(60, 60));
821```
822
823### setFillType<sup>12+</sup>
824
825setFillType(pathFillType: PathFillType): void
826
827Sets 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.
828
829**System capability**: SystemCapability.Graphics.Drawing
830
831**Parameters**
832
833| Name        | Type                                      | Mandatory  | Description                 |
834| ----------- | ---------------------------------------- | ---- | ------------------- |
835| pathFillType   | [PathFillType](#pathfilltype12)  | Yes  | Fill type of the path.|
836
837**Error codes**
838
839For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
840
841| ID| Error Message|
842| ------- | --------------------------------------------|
843| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.|
844
845**Example**
846
847```ts
848import { drawing } from '@kit.ArkGraphics2D';
849
850const path = new drawing.Path();
851path.setFillType(drawing.PathFillType.WINDING);
852```
853
854### getBounds<sup>12+</sup>
855
856getBounds(): common2D.Rect
857
858Obtains the minimum bounding rectangle that encloses this path.
859
860**System capability**: SystemCapability.Graphics.Drawing
861
862**Return value**
863
864| Type                                              | Description                  |
865| -------------------------------------------------- | ---------------------- |
866| [common2D.Rect](js-apis-graphics-common2D.md#rect) | Minimum bounding rectangle.|
867
868**Example**
869
870```ts
871import { common2D, drawing } from '@kit.ArkGraphics2D';
872
873const path = new drawing.Path();
874path.lineTo(50, 40)
875let rect : common2D.Rect = {left: 0, top: 0, right: 0, bottom: 0};
876rect = path.getBounds();
877console.info("test rect.left: " + rect.left);
878console.info("test rect.top: " + rect.top);
879console.info("test rect.right: " + rect.right);
880console.info("test rect.bottom: " + rect.bottom);
881```
882
883### addPolygon<sup>12+</sup>
884
885addPolygon(points: Array\<common2D.Point>, close: boolean): void
886
887Adds a polygon to this path.
888
889**System capability**: SystemCapability.Graphics.Drawing
890
891**Parameters**
892
893| Name| Type  | Mandatory| Description                   |
894| ------ | ------ | ---- | ----------------------- |
895| points | Array\<[common2D.Point](js-apis-graphics-common2D.md#point)>   | Yes  | Array that holds the vertex coordinates of the polygon.|
896| 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.|
897
898**Error codes**
899
900For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
901
902| ID| Error Message|
903| ------- | --------------------------------------------|
904| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
905
906**Example**
907
908```ts
909import { common2D, drawing } from '@kit.ArkGraphics2D';
910
911let pointsArray = new Array<common2D.Point>();
912const point1: common2D.Point = { x: 200, y: 200 };
913const point2: common2D.Point = { x: 400, y: 200 };
914const point3: common2D.Point = { x: 100, y: 400 };
915const point4: common2D.Point = { x: 300, y: 400 };
916pointsArray.push(point1);
917pointsArray.push(point2);
918pointsArray.push(point3);
919pointsArray.push(point4);
920const path = new drawing.Path();
921path.addPolygon(pointsArray, false);
922```
923
924### offset<sup>12+</sup>
925
926offset(dx: number, dy: number): Path
927
928Offsets this path by specified distances along the X axis and Y axis and stores the resulting path in the **Path** object returned.
929
930**System capability**: SystemCapability.Graphics.Drawing
931
932**Parameters**
933
934| Name| Type  | Mandatory| Description                   |
935| ------ | ------ | ---- | ----------------------- |
936| 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.|
937| 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.|
938
939**Return value**
940
941| Type  | Description               |
942| ------ | ------------------ |
943| [Path](#path) | New path generated.|
944
945**Error codes**
946
947For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
948
949| ID| Error Message|
950| ------- | --------------------------------------------|
951| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
952
953**Example**
954
955```ts
956import { drawing } from '@kit.ArkGraphics2D';
957
958const path = new drawing.Path();
959path.moveTo(200, 200);
960path.lineTo(300, 300);
961const dst = path.offset(200, 200);
962```
963
964### op<sup>12+</sup>
965
966op(path: Path, pathOp: PathOp): boolean
967
968Combines this path with the passed-in path based on the specified operation mode.
969
970**System capability**: SystemCapability.Graphics.Drawing
971
972**Parameters**
973
974| Name| Type  | Mandatory| Description                   |
975| ------ | ------ | ---- | ----------------------- |
976| path    | [Path](#path) | Yes  | Path object, which will be combined with the current path.|
977| pathOp  | [PathOp](#pathop12)   | Yes   | Operation mode.   |
978
979**Return value**
980
981| Type  | Description               |
982| ------ | ------------------ |
983| boolean | Result of the path combination result. The value **true** means that the path combination is successful, and **false** means the opposite.|
984
985**Error codes**
986
987For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
988
989| ID| Error Message|
990| ------- | --------------------------------------------|
991| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
992
993**Example**
994
995```ts
996import { drawing } from '@kit.ArkGraphics2D';
997
998const path = new drawing.Path();
999const path2 = new drawing.Path();
1000path.addCircle(100, 200, 100, drawing.PathDirection.CLOCKWISE);
1001console.info("get pathOp: ", path2.op(path, drawing.PathOp.DIFFERENCE));
1002```
1003
1004### close
1005
1006close(): void
1007
1008Draws a line segment from the current point to the start point of this path.
1009
1010**System capability**: SystemCapability.Graphics.Drawing
1011
1012**Example**
1013
1014```ts
1015import { drawing } from '@kit.ArkGraphics2D';
1016let path = new drawing.Path();
1017path.moveTo(10,10);
1018path.cubicTo(10, 10, 10, 10, 15, 15);
1019path.close();
1020```
1021
1022### reset
1023
1024reset(): void
1025
1026Resets the path data.
1027
1028**System capability**: SystemCapability.Graphics.Drawing
1029
1030**Example**
1031
1032```ts
1033import { drawing } from '@kit.ArkGraphics2D';
1034let path = new drawing.Path();
1035path.moveTo(10,10);
1036path.cubicTo(10, 10, 10, 10, 15, 15);
1037path.reset();
1038```
1039
1040### getLength<sup>12+</sup>
1041
1042getLength(forceClosed: boolean): number
1043
1044Obtains the path length.
1045
1046**System capability**: SystemCapability.Graphics.Drawing
1047
1048**Parameters**
1049
1050| Name| Type | Mandatory| Description    |
1051| ----- | ------ | ---- | --------- |
1052| 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.|
1053
1054**Return value**
1055
1056| Type | Description|
1057| ------ | ---- |
1058| number | Path length.|
1059
1060**Example**
1061
1062```ts
1063import { drawing } from '@kit.ArkGraphics2D'
1064let path = new drawing.Path();
1065path.arcTo(20, 20, 180, 180, 180, 90);
1066let len = path.getLength(false);
1067console.info("path length = " + len);
1068```
1069
1070### getPositionAndTangent<sup>12+</sup>
1071
1072getPositionAndTangent(forceClosed: boolean, distance: number, position: common2D.Point, tangent: common2D.Point): boolean
1073
1074Obtains the coordinates and tangent at a distance from the start point of this path.
1075
1076**System capability**: SystemCapability.Graphics.Drawing
1077
1078**Parameters**
1079
1080| Name  | Type                                        | Mandatory| Description                           |
1081| -------- | -------------------------------------------- | ---- | ------------------------------- |
1082| 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.                |
1083| 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.              |
1084| position | [common2D.Point](js-apis-graphics-common2D.md#point) | Yes  | Coordinates obtained.                 |
1085| 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.                |
1086
1087**Return value**
1088
1089| Type                 | Description          |
1090| --------------------- | -------------- |
1091| 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.|
1092
1093**Error codes**
1094
1095For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1096
1097| ID| Error Message|
1098| ------- | --------------------------------------------|
1099| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
1100
1101**Example**
1102
1103```ts
1104import { common2D, drawing } from '@kit.ArkGraphics2D';
1105let path: drawing.Path = new drawing.Path();
1106path.moveTo(0, 0);
1107path.lineTo(0, 700);
1108path.lineTo(700, 0);
1109let position: common2D.Point = { x: 0.0, y: 0.0 };
1110let tangent: common2D.Point = { x: 0.0, y: 0.0 };
1111if (path.getPositionAndTangent(false, 0.1, position, tangent)) {
1112  console.info("getPositionAndTangent-----position:  "+ position.x);
1113  console.info("getPositionAndTangent-----position:  "+ position.y);
1114  console.info("getPositionAndTangent-----tangent:  "+ tangent.x);
1115  console.info("getPositionAndTangent-----tangent:  "+ tangent.y);
1116}
1117```
1118
1119### isClosed<sup>12+</sup>
1120
1121isClosed(): boolean
1122
1123Checks whether a path is closed.
1124
1125**System capability**: SystemCapability.Graphics.Drawing
1126
1127**Return value**
1128
1129| Type                 | Description          |
1130| --------------------- | -------------- |
1131| boolean | Result indicating whether the path is closed. The value **true** means that the path is closed, and **false** means the opposite.|
1132
1133**Example**
1134
1135```ts
1136import { drawing } from '@kit.ArkGraphics2D';
1137let path: drawing.Path = new drawing.Path();
1138path.moveTo(0, 0);
1139path.lineTo(0, 700);
1140if (path.isClosed()) {
1141  console.info("path is closed.");
1142} else {
1143  console.info("path is not closed.");
1144}
1145```
1146
1147### getMatrix<sup>12+</sup>
1148
1149getMatrix(forceClosed: boolean, distance: number, matrix: Matrix, flags: PathMeasureMatrixFlags): boolean
1150
1151Obtains a transformation matrix at a distance from the start point of this path.
1152
1153**System capability**: SystemCapability.Graphics.Drawing
1154
1155**Parameters**
1156
1157| Name  | Type                                        | Mandatory| Description                           |
1158| -------- | -------------------------------------------- | ---- | ------------------------------- |
1159| 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.                 |
1160| 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.                 |
1161| matrix | [Matrix](#matrix12) | Yes  | **Matrix** object used to store the matrix obtained.                 |
1162| flags | [PathMeasureMatrixFlags](#pathmeasurematrixflags12) | Yes  | Type of the matrix information obtained.                 |
1163
1164**Return value**
1165
1166| Type                 | Description          |
1167| --------------------- | -------------- |
1168| boolean | Result indicating whether a transformation matrix is obtained. The value **true** means that a transformation matrix is obtained, and **false** means the opposite.|
1169
1170**Error codes**
1171
1172For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1173
1174| ID| Error Message|
1175| ------- | --------------------------------------------|
1176| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. |
1177
1178**Example**
1179
1180```ts
1181import { drawing } from '@kit.ArkGraphics2D';
1182let path: drawing.Path = new drawing.Path();
1183let matrix = new drawing.Matrix();
1184if(path.getMatrix(false, 10, matrix, drawing.PathMeasureMatrixFlags.GET_TANGENT_MATRIX)) {
1185  console.info("path.getMatrix return true");
1186} else {
1187  console.info("path.getMatrix return false");
1188}
1189```
1190
1191### buildFromSvgString<sup>12+</sup>
1192
1193buildFromSvgString(str: string): boolean
1194
1195Parses the path represented by an SVG string.
1196
1197**System capability**: SystemCapability.Graphics.Drawing
1198
1199**Parameters**
1200
1201| Name  | Type                                        | Mandatory| Description                           |
1202| -------- | -------------------------------------------- | ---- | ------------------------------- |
1203| str | string | Yes  | String in SVG format, which is used to describe the path.                |
1204
1205**Return value**
1206
1207| Type                 | Description          |
1208| --------------------- | -------------- |
1209| boolean | Result indicating whether the SVG string is parsed. The value **true** means that the parsing is successful, and **false** means the opposite.|
1210
1211**Error codes**
1212
1213For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1214
1215| ID| Error Message|
1216| ------- | --------------------------------------------|
1217| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. |
1218
1219**Example**
1220
1221```ts
1222import { drawing } from '@kit.ArkGraphics2D';
1223let path: drawing.Path = new drawing.Path();
1224let svgStr: string =  "M150 100 L75 300 L225 300 Z";
1225if(path.buildFromSvgString(svgStr)) {
1226  console.info("buildFromSvgString return true");
1227} else {
1228  console.info("buildFromSvgString return false");
1229}
1230```
1231
1232## Canvas
1233
1234A carrier that carries the drawn content and drawing status.
1235
1236> **NOTE**
1237>
1238> 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.
1239
1240### constructor
1241
1242constructor(pixelmap: image.PixelMap)
1243
1244A constructor used to create a **Canvas** object.
1245
1246**System capability**: SystemCapability.Graphics.Drawing
1247
1248**Parameters**
1249
1250| Name  | Type                                        | Mandatory| Description          |
1251| -------- | -------------------------------------------- | ---- | -------------- |
1252| pixelmap | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | Yes  | Pixel map used to create the object.|
1253
1254**Error codes**
1255
1256For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1257
1258| ID| Error Message|
1259| ------- | --------------------------------------------|
1260| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
1261
1262**Example**
1263
1264```ts
1265import { drawing } from '@kit.ArkGraphics2D';
1266import { image } from '@kit.ImageKit';
1267const color = new ArrayBuffer(96);
1268let opts : image.InitializationOptions = {
1269  editable: true,
1270  pixelFormat: 3,
1271  size: {
1272    height: 4,
1273    width: 6
1274  }
1275}
1276image.createPixelMap(color, opts).then((pixelMap) => {
1277  const canvas = new drawing.Canvas(pixelMap);
1278})
1279```
1280
1281### drawRect
1282
1283drawRect(rect: common2D.Rect): void
1284
1285Draws a rectangle. By default, black is used for filling.
1286
1287**System capability**: SystemCapability.Graphics.Drawing
1288
1289**Parameters**
1290
1291| Name| Type                                              | Mandatory| Description          |
1292| ------ | -------------------------------------------------- | ---- | -------------- |
1293| rect   | [common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes  | Rectangle to draw.|
1294
1295**Error codes**
1296
1297For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1298
1299| ID| Error Message|
1300| ------- | --------------------------------------------|
1301| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
1302
1303**Example**
1304
1305```ts
1306import { RenderNode } from '@kit.ArkUI';
1307import { common2D, drawing } from '@kit.ArkGraphics2D';
1308class DrawingRenderNode extends RenderNode {
1309  draw(context : DrawContext) {
1310    const canvas = context.canvas;
1311    const pen = new drawing.Pen();
1312    pen.setStrokeWidth(5);
1313    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
1314    canvas.attachPen(pen);
1315    canvas.drawRect({ left : 0, right : 10, top : 0, bottom : 10 });
1316    canvas.detachPen();
1317  }
1318}
1319```
1320
1321### drawRect<sup>12+</sup>
1322
1323drawRect(left: number, top: number, right: number, bottom: number): void
1324
1325Draws a rectangle. By default, black is used for filling. This API provides better performance than [drawRect](#drawrect) and is recommended.
1326
1327**System capability**: SystemCapability.Graphics.Drawing
1328
1329**Parameters**
1330
1331| Name| Type   | Mandatory| Description          |
1332| ------ | ------ | ---- | -------------- |
1333| left   | number | Yes  | X coordinate of the upper left corner of the rectangle. The value is a floating point number.|
1334| top    | number | Yes  | Y coordinate of the upper left corner of the rectangle. The value is a floating point number.|
1335| right  | number | Yes  | X coordinate of the lower right corner of the rectangle. The value is a floating point number.|
1336| bottom | number | Yes  | Y coordinate of the lower right corner of the rectangle. The value is a floating point number.|
1337
1338**Error codes**
1339
1340For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1341
1342| ID| Error Message|
1343| ------- | --------------------------------------------|
1344| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
1345
1346**Example**
1347
1348```ts
1349import { RenderNode } from '@kit.ArkUI';
1350import { drawing } from '@kit.ArkGraphics2D';
1351class DrawingRenderNode extends RenderNode {
1352
1353  draw(context : DrawContext) {
1354    const canvas = context.canvas;
1355    const pen = new drawing.Pen();
1356    pen.setStrokeWidth(5);
1357    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
1358    canvas.attachPen(pen);
1359    canvas.drawRect(0, 0, 10, 10);
1360    canvas.detachPen();
1361  }
1362}
1363```
1364
1365### drawRoundRect<sup>12+</sup>
1366
1367drawRoundRect(roundRect: RoundRect): void
1368
1369Draws a rounded rectangle.
1370
1371**System capability**: SystemCapability.Graphics.Drawing
1372
1373**Parameters**
1374
1375| Name    | Type                   | Mandatory| Description      |
1376| ---------- | ----------------------- | ---- | ------------ |
1377| roundRect  | [RoundRect](#roundrect12) | Yes  | Rounded rectangle.|
1378
1379**Error codes**
1380
1381For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1382
1383| ID| Error Message|
1384| ------- | --------------------------------------------|
1385| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
1386
1387**Example**
1388
1389```ts
1390import { RenderNode } from '@kit.ArkUI';
1391import { common2D, drawing } from '@kit.ArkGraphics2D';
1392class DrawingRenderNode extends RenderNode {
1393  draw(context : DrawContext) {
1394    const canvas = context.canvas;
1395    let rect: common2D.Rect = { left : 100, top : 100, right : 400, bottom : 500 };
1396    let roundRect = new drawing.RoundRect(rect, 10, 10);
1397    canvas.drawRoundRect(roundRect);
1398  }
1399}
1400```
1401
1402### drawNestedRoundRect<sup>12+</sup>
1403
1404drawNestedRoundRect(outer: RoundRect, inner: RoundRect): void
1405
1406Draws two nested rounded rectangles. The outer rectangle boundary must contain the inner rectangle boundary. Otherwise, there is no drawing effect.
1407
1408**System capability**: SystemCapability.Graphics.Drawing
1409
1410**Parameters**
1411
1412| Name | Type                   | Mandatory| Description      |
1413| ------ | ----------------------- | ---- | ------------ |
1414| outer  | [RoundRect](#roundrect12) | Yes  | Outer rounded rectangle.|
1415| inner  | [RoundRect](#roundrect12) | Yes  | Inner rounded rectangle.|
1416
1417**Error codes**
1418
1419For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1420
1421| ID| Error Message|
1422| ------- | --------------------------------------------|
1423| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
1424
1425**Example**
1426
1427```ts
1428import { RenderNode } from '@kit.ArkUI';
1429import { common2D, drawing } from '@kit.ArkGraphics2D';
1430class DrawingRenderNode extends RenderNode {
1431  draw(context : DrawContext) {
1432    const canvas = context.canvas;
1433    let inRect: common2D.Rect = { left : 200, top : 200, right : 400, bottom : 500 };
1434    let outRect: common2D.Rect = { left : 100, top : 100, right : 400, bottom : 500 };
1435    let outRoundRect = new drawing.RoundRect(outRect, 10, 10);
1436    let inRoundRect = new drawing.RoundRect(inRect, 10, 10);
1437    canvas.drawNestedRoundRect(outRoundRect, inRoundRect);
1438    canvas.drawRoundRect(outRoundRect);
1439  }
1440}
1441```
1442
1443### drawBackground<sup>12+</sup>
1444
1445drawBackground(brush: Brush): void
1446
1447Uses a brush to fill the drawable area of the canvas.
1448
1449**System capability**: SystemCapability.Graphics.Drawing
1450
1451**Parameters**
1452
1453| Name| Type           | Mandatory| Description      |
1454| ------ | --------------- | ---- | ---------- |
1455| brush  | [Brush](#brush) | Yes  | **Brush** object.|
1456
1457**Error codes**
1458
1459For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1460
1461| ID| Error Message|
1462| ------- | --------------------------------------------|
1463| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
1464
1465**Example**
1466
1467```ts
1468import { RenderNode } from '@kit.ArkUI';
1469import { common2D, drawing } from '@kit.ArkGraphics2D';
1470class DrawingRenderNode extends RenderNode {
1471  draw(context : DrawContext) {
1472    const canvas = context.canvas;
1473    const brush = new drawing.Brush();
1474    const color : common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
1475    brush.setColor(color);
1476    canvas.drawBackground(brush);
1477  }
1478}
1479```
1480
1481### drawShadow<sup>12+</sup>
1482
1483drawShadow(path: Path, planeParams: common2D.Point3d, devLightPos: common2D.Point3d, lightRadius: number, ambientColor: common2D.Color, spotColor: common2D.Color, flag: ShadowFlag) : void
1484
1485Draws a spot shadow and uses a given path to outline the ambient shadow.
1486
1487**System capability**: SystemCapability.Graphics.Drawing
1488
1489**Parameters**
1490
1491| Name         | Type                                      | Mandatory  | Description        |
1492| ------------ | ---------------------------------------- | ---- | ---------- |
1493| path | [Path](#path)                | Yes   | **Path** object, which is used to outline the shadow.|
1494| planeParams  | [common2D.Point3d](js-apis-graphics-common2D.md#point3d12) | Yes   | 3D vector, which is used to calculate the offset in the Z axis.|
1495| devLightPos  | [common2D.Point3d](js-apis-graphics-common2D.md#point3d12) | Yes   | Position of the light relative to the canvas.|
1496| lightRadius   | number           | Yes   | Radius of the light. The value is a floating point number.     |
1497| ambientColor  | [common2D.Color](js-apis-graphics-common2D.md#color) | Yes   | Color of the ambient shadow.|
1498| spotColor  | [common2D.Color](js-apis-graphics-common2D.md#color) | Yes   | Color of the spot shadow.|
1499| flag         | [ShadowFlag](#shadowflag12)                  | Yes   | Shadow flag.   |
1500
1501**Error codes**
1502
1503For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1504
1505| ID| Error Message|
1506| ------- | --------------------------------------------|
1507| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
1508
1509**Example**
1510
1511```ts
1512import { RenderNode } from '@kit.ArkUI';
1513import { common2D, drawing } from '@kit.ArkGraphics2D';
1514class DrawingRenderNode extends RenderNode {
1515  draw(context : DrawContext) {
1516    const canvas = context.canvas;
1517    const path = new drawing.Path();
1518    path.addCircle(100, 200, 100, drawing.PathDirection.CLOCKWISE);
1519    let pen = new drawing.Pen();
1520    pen.setAntiAlias(true);
1521    let pen_color : common2D.Color = { alpha: 0xFF, red: 0xFF, green: 0x00, blue: 0x00 };
1522    pen.setColor(pen_color);
1523    pen.setStrokeWidth(10.0);
1524    canvas.attachPen(pen);
1525    let brush = new drawing.Brush();
1526    let brush_color : common2D.Color = { alpha: 0xFF, red: 0x00, green: 0xFF, blue: 0x00 };
1527    brush.setColor(brush_color);
1528    canvas.attachBrush(brush);
1529    let point1 : common2D.Point3d = {x: 100, y: 80, z:80};
1530    let point2 : common2D.Point3d = {x: 200, y: 10, z:40};
1531    let color1 : common2D.Color = {alpha: 0xFF, red:0, green:0, blue:0xFF};
1532    let color2 : common2D.Color = {alpha: 0xFF, red:0xFF, green:0, blue:0};
1533    let shadowFlag : drawing.ShadowFlag = drawing.ShadowFlag.ALL;
1534    canvas.drawShadow(path, point1, point2, 30, color1, color2, shadowFlag);
1535  }
1536}
1537```
1538
1539### drawShadow<sup>13+</sup>
1540
1541drawShadow(path: Path, planeParams: common2D.Point3d, devLightPos: common2D.Point3d, lightRadius: number, ambientColor: number, spotColor: number, flag: ShadowFlag) : void
1542
1543Draws a spot shadow and uses a given path to outline the ambient shadow.
1544
1545**System capability**: SystemCapability.Graphics.Drawing
1546
1547**Parameters**
1548
1549| Name         | Type                                      | Mandatory  | Description        |
1550| ------------ | ---------------------------------------- | ---- | ---------- |
1551| path | [Path](#path)                | Yes   | **Path** object, which is used to outline the shadow.|
1552| planeParams  | [common2D.Point3d](js-apis-graphics-common2D.md#point3d12) | Yes   | 3D vector, which is used to calculate the offset in the Z axis.|
1553| devLightPos  | [common2D.Point3d](js-apis-graphics-common2D.md#point3d12) | Yes   | Position of the light relative to the canvas.|
1554| lightRadius   | number           | Yes   | Radius of the light. The value is a floating point number.     |
1555| ambientColor  |number | Yes   | Ambient shadow color, represented by a 32-bit unsigned integer in hexadecimal ARGB format.|
1556| spotColor  |number | Yes   | Spot shadow color, represented by a 32-bit unsigned integer in hexadecimal ARGB format.|
1557| flag         | [ShadowFlag](#shadowflag12)                  | Yes   | Shadow flag.   |
1558
1559**Error codes**
1560
1561For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1562
1563| ID| Error Message|
1564| ------- | --------------------------------------------|
1565| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
1566
1567**Example**
1568
1569```ts
1570import { RenderNode } from '@kit.ArkUI';
1571import { common2D, drawing } from '@kit.ArkGraphics2D';
1572class DrawingRenderNode extends RenderNode {
1573  draw(context : DrawContext) {
1574    const canvas = context.canvas;
1575    const path = new drawing.Path();
1576    path.addCircle(300, 600, 100, drawing.PathDirection.CLOCKWISE);
1577    let point1 : common2D.Point3d = {x: 100, y: 80, z:80};
1578    let point2 : common2D.Point3d = {x: 200, y: 10, z:40};
1579    let shadowFlag : drawing.ShadowFlag = drawing.ShadowFlag.ALL;
1580    canvas.drawShadow(path, point1, point2, 30, 0xFF0000FF, 0xFFFF0000, shadowFlag);
1581  }
1582}
1583```
1584
1585### getLocalClipBounds<sup>12+</sup>
1586
1587getLocalClipBounds(): common2D.Rect
1588
1589Obtains the bounds of the cropping region of the canvas.
1590
1591**System capability**: SystemCapability.Graphics.Drawing
1592
1593**Return value**
1594
1595| Type                                      | Description      |
1596| ---------------------------------------- | -------- |
1597| [common2D.Rect](js-apis-graphics-common2D.md#rect) | Bounds of the cropping region.|
1598
1599**Example**
1600
1601```ts
1602import { RenderNode } from '@kit.ArkUI';
1603import { common2D, drawing } from '@kit.ArkGraphics2D';
1604class DrawingRenderNode extends RenderNode {
1605  draw(context : DrawContext) {
1606    const canvas = context.canvas;
1607    let clipRect: common2D.Rect = {
1608      left : 150, top : 150, right : 300, bottom : 400
1609    };
1610    canvas.clipRect(clipRect,drawing.ClipOp.DIFFERENCE, true);
1611    console.info("test rect.left: " + clipRect.left);
1612    console.info("test rect.top: " + clipRect.top);
1613    console.info("test rect.right: " + clipRect.right);
1614    console.info("test rect.bottom: " + clipRect.bottom);
1615    canvas.getLocalClipBounds();
1616  }
1617}
1618```
1619
1620### getTotalMatrix<sup>12+</sup>
1621
1622getTotalMatrix(): Matrix
1623
1624Obtains the canvas matrix.
1625
1626**System capability**: SystemCapability.Graphics.Drawing
1627
1628**Return value**
1629
1630| Type               | Description      |
1631| ----------------- | -------- |
1632| [Matrix](#matrix12) |Canvas matrix.|
1633
1634**Example**
1635
1636```ts
1637import { RenderNode } from '@kit.ArkUI';
1638import { drawing } from '@kit.ArkGraphics2D';
1639class DrawingRenderNode extends RenderNode {
1640  draw(context : DrawContext) {
1641    const canvas = context.canvas;
1642    let matrix = new drawing.Matrix();
1643    matrix.setMatrix([5, 0, 0, 0, 1, 1, 0, 0, 1]);
1644    canvas.setMatrix(matrix);
1645    let matrixResult =canvas.getTotalMatrix();
1646  }
1647}
1648```
1649
1650### drawCircle
1651
1652drawCircle(x: number, y: number, radius: number): void
1653
1654Draws a circle. If the radius is less than or equal to zero, nothing is drawn. By default, black is used for filling.
1655
1656**System capability**: SystemCapability.Graphics.Drawing
1657
1658**Parameters**
1659
1660| Name| Type  | Mandatory| Description               |
1661| ------ | ------ | ---- | ------------------- |
1662| x      | number | Yes  | X coordinate of the center of the circle. The value is a floating point number.|
1663| y      | number | Yes  | Y coordinate of the center of the circle. The value is a floating point number.|
1664| radius | number | Yes  | Radius of the circle. The value is a floating point number greater than 0.|
1665
1666**Error codes**
1667
1668For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1669
1670| ID| Error Message|
1671| ------- | --------------------------------------------|
1672| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
1673
1674**Example**
1675
1676```ts
1677import { RenderNode } from '@kit.ArkUI';
1678import { drawing } from '@kit.ArkGraphics2D';
1679class DrawingRenderNode extends RenderNode {
1680  draw(context : DrawContext) {
1681    const canvas = context.canvas;
1682    const pen = new drawing.Pen();
1683    pen.setStrokeWidth(5);
1684    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
1685    canvas.attachPen(pen);
1686    canvas.drawCircle(10, 10, 2);
1687    canvas.detachPen();
1688  }
1689}
1690```
1691
1692### drawImage
1693
1694drawImage(pixelmap: image.PixelMap, left: number, top: number, samplingOptions?: SamplingOptions): void
1695
1696Draws an image. The coordinates of the upper left corner of the image are (left, top).
1697
1698**System capability**: SystemCapability.Graphics.Drawing
1699
1700**Parameters**
1701
1702| Name  | Type                                        | Mandatory| Description                           |
1703| -------- | -------------------------------------------- | ---- | ------------------------------- |
1704| pixelmap | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | Yes  | Pixel map of the image.                 |
1705| left     | number                                       | Yes  | X coordinate of the upper left corner of the image. The value is a floating point number.|
1706| top      | number                                       | Yes  | Y coordinate of the upper left corner of the image. The value is a floating point number.|
1707| samplingOptions<sup>12+</sup>  | [SamplingOptions](#samplingoptions12)  | No | Sampling options. By default, the **SamplingOptions** object created using the no-argument constructor is used.|
1708
1709**Error codes**
1710
1711For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1712
1713| ID| Error Message|
1714| ------- | --------------------------------------------|
1715| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
1716
1717**Example**
1718
1719```ts
1720import { RenderNode } from '@kit.ArkUI';
1721import { image } from '@kit.ImageKit';
1722import { drawing } from '@kit.ArkGraphics2D';
1723class DrawingRenderNode extends RenderNode {
1724  pixelMap: image.PixelMap | null = null;
1725
1726  async draw(context : DrawContext) {
1727    const canvas = context.canvas;
1728    let options = new drawing.SamplingOptions(drawing.FilterMode.FILTER_MODE_NEAREST);
1729    if (this.pixelMap != null) {
1730      canvas.drawImage(this.pixelMap, 0, 0, options);
1731    }
1732  }
1733}
1734```
1735
1736### drawImageRect<sup>12+</sup>
1737
1738drawImageRect(pixelmap: image.PixelMap, dstRect: common2D.Rect, samplingOptions?: SamplingOptions): void
1739
1740Draws an image onto a specified area of the canvas.
1741
1742**System capability**: SystemCapability.Graphics.Drawing
1743
1744**Parameters**
1745
1746| Name  | Type                                        | Mandatory| Description                           |
1747| -------- | -------------------------------------------- | ---- | ------------------------------- |
1748| pixelmap | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | Yes  | Pixel map of the image.                |
1749| 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.|
1750| samplingOptions     | [SamplingOptions](#samplingoptions12)                           | No  | Sampling options. By default, the **SamplingOptions** object created using the no-argument constructor is used.|
1751
1752**Error codes**
1753
1754For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1755
1756| ID| Error Message|
1757| ------- | --------------------------------------------|
1758| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
1759
1760**Example**
1761
1762```ts
1763import { RenderNode } from '@kit.ArkUI';
1764import { image } from '@kit.ImageKit';
1765import { common2D, drawing } from '@kit.ArkGraphics2D';
1766class DrawingRenderNode extends RenderNode {
1767pixelMap: image.PixelMap | null = null;
1768  draw(context : DrawContext) {
1769    const canvas = context.canvas;
1770    let pen = new drawing.Pen();
1771    canvas.attachPen(pen);
1772    let rect: common2D.Rect = { left: 0, top: 0, right: 200, bottom: 200 };
1773    canvas.drawImageRect(this.pixelMap, rect);
1774    canvas.detachPen();
1775  }
1776}
1777```
1778
1779### drawImageRectWithSrc<sup>12+</sup>
1780
1781drawImageRectWithSrc(pixelmap: image.PixelMap, srcRect: common2D.Rect, dstRect: common2D.Rect, samplingOptions?: SamplingOptions, constraint?: SrcRectConstraint): void
1782
1783Draws a portion of an image onto a specified area of the canvas.
1784
1785**System capability**: SystemCapability.Graphics.Drawing
1786
1787**Parameters**
1788
1789| Name  | Type                                        | Mandatory| Description                           |
1790| -------- | -------------------------------------------- | ---- | ------------------------------- |
1791| pixelmap | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | Yes  | Pixel map of the image.                |
1792| srcRect     | [common2D.Rect](js-apis-graphics-common2D.md#rect)                               | Yes  | **Rectangle** object, which specifies the portion of the image to draw.|
1793| 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.|
1794| samplingOptions     | [SamplingOptions](#samplingoptions12)                           | No  | Sampling options. By default, the **SamplingOptions** object created using the no-argument constructor is used.|
1795| constraint     | [SrcRectConstraint](#srcrectconstraint12)                        | No  | Constraint type of the source rectangle. The default value is **STRICT**.|
1796
1797**Error codes**
1798
1799For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1800
1801| ID| Error Message|
1802| ------- | --------------------------------------------|
1803| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
1804
1805**Example**
1806
1807```ts
1808import { RenderNode } from '@kit.ArkUI';
1809import { image } from '@kit.ImageKit';
1810import { common2D, drawing } from '@kit.ArkGraphics2D';
1811class DrawingRenderNode extends RenderNode {
1812pixelMap: image.PixelMap | null = null;
1813  draw(context : DrawContext) {
1814    const canvas = context.canvas;
1815    let pen = new drawing.Pen();
1816    canvas.attachPen(pen);
1817    let srcRect: common2D.Rect = { left: 0, top: 0, right: 100, bottom: 100 };
1818    let dstRect: common2D.Rect = { left: 100, top: 100, right: 200, bottom: 200 };
1819    canvas.drawImageRectWithSrc(this.pixelMap, srcRect, dstRect);
1820    canvas.detachPen();
1821  }
1822}
1823```
1824
1825### drawColor
1826
1827drawColor(color: common2D.Color, blendMode?: BlendMode): void
1828
1829Draws the background color.
1830
1831**System capability**: SystemCapability.Graphics.Drawing
1832
1833**Parameters**
1834
1835| Name   | Type                                                | Mandatory| Description                            |
1836| --------- | ---------------------------------------------------- | ---- | -------------------------------- |
1837| 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.                  |
1838| blendMode | [BlendMode](#blendmode)                              | No  | Blend mode. The default mode is **SRC_OVER**.|
1839
1840**Error codes**
1841
1842For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1843
1844| ID| Error Message|
1845| ------- | --------------------------------------------|
1846| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
1847
1848**Example**
1849
1850```ts
1851import { RenderNode } from '@kit.ArkUI';
1852import { common2D, drawing } from '@kit.ArkGraphics2D';
1853class DrawingRenderNode extends RenderNode {
1854  draw(context : DrawContext) {
1855    const canvas = context.canvas;
1856    let color: common2D.Color = {
1857      alpha : 255,
1858      red: 0,
1859      green: 10,
1860      blue: 10
1861    }
1862    canvas.drawColor(color, drawing.BlendMode.CLEAR);
1863  }
1864}
1865```
1866
1867### drawColor<sup>12+</sup>
1868
1869drawColor(alpha: number, red: number, green: number, blue: number, blendMode?: BlendMode): void
1870
1871Draws the background color. This API provides better performance than [drawColor](#drawcolor) and is recommended.
1872
1873**System capability**: SystemCapability.Graphics.Drawing
1874
1875**Parameters**
1876
1877| Name    | Type                   | Mandatory| Description                                              |
1878| --------- | ----------------------- | ---- | ------------------------------------------------- |
1879| 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.|
1880| 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.  |
1881| 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.  |
1882| 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.  |
1883| blendMode | [BlendMode](#blendmode) | No  | Blend mode. The default mode is **SRC_OVER**.                  |
1884
1885**Error codes**
1886
1887For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1888
1889| ID| Error Message|
1890| ------- | --------------------------------------------|
1891| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
1892
1893**Example**
1894
1895```ts
1896import { RenderNode } from '@kit.ArkUI';
1897import { drawing } from '@kit.ArkGraphics2D';
1898class DrawingRenderNode extends RenderNode {
1899  draw(context : DrawContext) {
1900    const canvas = context.canvas;
1901    canvas.drawColor(255, 0, 10, 10, drawing.BlendMode.CLEAR);
1902  }
1903}
1904```
1905
1906### drawPixelMapMesh<sup>12+</sup>
1907
1908drawPixelMapMesh(pixelmap: image.PixelMap, meshWidth: number, meshHeight: number, vertices: Array\<number>, vertOffset: number, colors: Array\<number>, colorOffset: number): void
1909
1910Draws a pixel map based on a mesh, where mesh vertices are evenly distributed across the pixel map.
1911
1912**System capability**: SystemCapability.Graphics.Drawing
1913
1914**Parameters**
1915
1916| Name     | Type           | Mandatory| Description                           |
1917| ----------- | -------------  | ---- | ------------------------------- |
1918| pixelmap    | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | Yes  | Pixel map to draw.|
1919| meshWidth   | number         | Yes  | Number of columns in the mesh. The value is an integer greater than 0.|
1920| meshHeight  | number         | Yes  | Number of rows in the mesh. The value is an integer greater than 0.|
1921| 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.|
1922| vertOffset  | number         | Yes  | Number of vert elements to skip before drawing. The value is an integer greater than or equal to 0.|
1923| 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.|
1924| colorOffset | number         | Yes  | Number of color elements to skip before drawing. The value is an integer greater than or equal to 0.|
1925
1926**Error codes**
1927
1928For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1929
1930| ID| Error Message|
1931| ------- | --------------------------------------------|
1932| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
1933
1934**Example**
1935
1936```ts
1937import { RenderNode } from '@kit.ArkUI';
1938import { image } from '@kit.ImageKit';
1939import { drawing } from '@kit.ArkGraphics2D';
1940class DrawingRenderNode extends RenderNode {
1941  pixelMap: image.PixelMap | null = null;
1942
1943  async draw(context : DrawContext) {
1944    const canvas = context.canvas;
1945    if (this.pixelMap != null) {
1946      const brush = new drawing.Brush(); // Only brush is supported. There is no drawing effect when pen is used.
1947      canvas.attachBrush(brush);
1948      let verts : Array<number> = [0, 0, 50, 0, 410, 0, 0, 180, 50, 180, 410, 180, 0, 360, 50, 360, 410, 360]; // 18
1949      canvas.drawPixelMapMesh(this.pixelMap, 2, 2, verts, 0, null, 0);
1950      canvas.detachBrush();
1951    }
1952  }
1953}
1954```
1955
1956### clear<sup>12+</sup>
1957
1958clear(color: common2D.Color): void
1959
1960Clears the canvas with a given color.
1961
1962**System capability**: SystemCapability.Graphics.Drawing
1963
1964**Parameters**
1965
1966| Name   | Type                                                | Mandatory| Description                            |
1967| --------- | ---------------------------------------------------- | ---- | -------------------------------- |
1968| 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.     |
1969
1970**Error codes**
1971
1972For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1973
1974| ID| Error Message|
1975| ------- | --------------------------------------------|
1976| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
1977
1978**Example**
1979
1980```ts
1981import { RenderNode } from '@kit.ArkUI';
1982import { common2D, drawing } from '@kit.ArkGraphics2D';
1983class DrawingRenderNode extends RenderNode {
1984  draw(context : DrawContext) {
1985    const canvas = context.canvas;
1986    let color: common2D.Color = {alpha: 255, red: 255, green: 0, blue: 0};
1987    canvas.clear(color);
1988  }
1989}
1990```
1991
1992### clear<sup>13+</sup>
1993
1994clear(number): void
1995
1996Clears the canvas with a given color.
1997
1998**System capability**: SystemCapability.Graphics.Drawing
1999
2000**Parameters**
2001
2002| Name   | Type                                                | Mandatory| Description                            |
2003| --------- | ---------------------------------------------------- | ---- | -------------------------------- |
2004| color     | number| Yes  | Color, represented by a 32-bit unsigned integer in hexadecimal ARGB format. |
2005
2006**Error codes**
2007
2008For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2009
2010| ID| Error Message|
2011| ------- | --------------------------------------------|
2012| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2013
2014**Example**
2015
2016```ts
2017import { RenderNode } from '@kit.ArkUI';
2018import { drawing } from '@kit.ArkGraphics2D';
2019class DrawingRenderNode extends RenderNode {
2020  draw(context : DrawContext) {
2021    const canvas = context.canvas;
2022    let color: number = 0xffff0000;
2023    canvas.clear(color);
2024  }
2025}
2026```
2027
2028### getWidth<sup>12+</sup>
2029
2030getWidth(): number
2031
2032Obtains the canvas width.
2033
2034**System capability**: SystemCapability.Graphics.Drawing
2035
2036**Return value**
2037
2038| Type  | Mandatory| Description          |
2039| ------ | ---- | -------------- |
2040| number | Yes  | Canvas width. The value is a floating point number.|
2041
2042**Example**
2043
2044```ts
2045import { RenderNode } from '@kit.ArkUI';
2046import { drawing } from '@kit.ArkGraphics2D';
2047class DrawingRenderNode extends RenderNode {
2048  draw(context : DrawContext) {
2049    const canvas = context.canvas;
2050    let width = canvas.getWidth();
2051    console.info('get canvas width:' + width);
2052  }
2053}
2054```
2055
2056### getHeight<sup>12+</sup>
2057
2058getHeight(): number
2059
2060Obtains the canvas height.
2061
2062**System capability**: SystemCapability.Graphics.Drawing
2063
2064**Return value**
2065
2066| Type  | Mandatory| Description          |
2067| ------ | ---- | -------------- |
2068| number | Yes  | Canvas height. The value is a floating point number.|
2069
2070**Example**
2071
2072```ts
2073import { RenderNode } from '@kit.ArkUI';
2074import { drawing } from '@kit.ArkGraphics2D';
2075class DrawingRenderNode extends RenderNode {
2076  draw(context : DrawContext) {
2077    const canvas = context.canvas;
2078    let height = canvas.getHeight();
2079    console.log('get canvas height:' + height);
2080  }
2081}
2082```
2083
2084### drawOval<sup>12+</sup>
2085
2086drawOval(oval: common2D.Rect): void
2087
2088Draws an oval on the canvas. The shape and position of the oval are defined by the rectangle parameters that specify the oval boundary.
2089
2090**System capability**: SystemCapability.Graphics.Drawing
2091
2092**Parameters**
2093
2094| Name| Type                                              | Mandatory| Description          |
2095| ------ | -------------------------------------------------- | ---- | -------------- |
2096| oval   | [common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes  | Rectangle. The oval inscribed within the rectangle is the oval to draw.|
2097
2098**Error codes**
2099
2100For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2101
2102| ID| Error Message|
2103| ------- | --------------------------------------------|
2104| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2105
2106**Example**
2107
2108```ts
2109import { RenderNode } from '@kit.ArkUI';
2110import { common2D, drawing } from '@kit.ArkGraphics2D';
2111class DrawingRenderNode extends RenderNode {
2112  draw(context : DrawContext) {
2113    const canvas = context.canvas;
2114    const pen = new drawing.Pen();
2115    pen.setStrokeWidth(5);
2116    const color : common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
2117    pen.setColor(color);
2118    canvas.attachPen(pen);
2119    const rect: common2D.Rect = {left:100, top:50, right:400, bottom:500};
2120    canvas.drawOval(rect);
2121    canvas.detachPen();
2122  }
2123}
2124```
2125
2126### drawArc<sup>12+</sup>
2127
2128drawArc(arc: common2D.Rect, startAngle: number, sweepAngle: number): void
2129
2130Draws an arc on the canvas, with the start angle and sweep angle specified.
2131
2132**System capability**: SystemCapability.Graphics.Drawing
2133
2134**Parameters**
2135
2136| Name| Type                                              | Mandatory| Description          |
2137| ------ | -------------------------------------------------- | ---- | -------------- |
2138| arc   | [common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes  | Rectangular boundary that encapsulates the oval including the arc.|
2139| 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.|
2140| 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.|
2141
2142**Error codes**
2143
2144For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2145
2146| ID| Error Message|
2147| ------- | --------------------------------------------|
2148| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2149
2150**Example**
2151
2152```ts
2153import { RenderNode } from '@kit.ArkUI';
2154import { common2D, drawing } from '@kit.ArkGraphics2D';
2155class DrawingRenderNode extends RenderNode {
2156  draw(context : DrawContext) {
2157    const canvas = context.canvas;
2158    const pen = new drawing.Pen();
2159    pen.setStrokeWidth(5);
2160    const color : common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
2161    pen.setColor(color);
2162    canvas.attachPen(pen);
2163    const rect: common2D.Rect = {left:100, top:50, right:400, bottom:200};
2164    canvas.drawArc(rect, 90, 180);
2165    canvas.detachPen();
2166  }
2167}
2168```
2169
2170### drawPoint
2171
2172drawPoint(x: number, y: number): void
2173
2174Draws a point.
2175
2176**System capability**: SystemCapability.Graphics.Drawing
2177
2178**Parameters**
2179
2180| Name| Type  | Mandatory| Description               |
2181| ------ | ------ | ---- | ------------------- |
2182| x      | number | Yes  | X coordinate of the point. The value is a floating point number.|
2183| y      | number | Yes  | Y coordinate of the point. The value is a floating point number.|
2184
2185**Error codes**
2186
2187For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2188
2189| ID| Error Message|
2190| ------- | --------------------------------------------|
2191| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2192
2193**Example**
2194
2195```ts
2196import { RenderNode } from '@kit.ArkUI';
2197import { drawing } from '@kit.ArkGraphics2D';
2198class DrawingRenderNode extends RenderNode {
2199  draw(context : DrawContext) {
2200    const canvas = context.canvas;
2201    const pen = new drawing.Pen();
2202    pen.setStrokeWidth(5);
2203    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2204    canvas.attachPen(pen);
2205    canvas.drawPoint(10, 10);
2206    canvas.detachPen();
2207  }
2208}
2209```
2210
2211### drawPoints<sup>12+</sup>
2212
2213drawPoints(points: Array\<common2D.Point>, mode?: PointMode): void
2214
2215Draws a group of points, line segments, or polygons on the canvas, with the specified drawing mode. An array is used to hold these points.
2216
2217**System capability**: SystemCapability.Graphics.Drawing
2218
2219**Parameters**
2220
2221| Name | Type                                      | Mandatory  | Description       |
2222| ---- | ---------------------------------------- | ---- | --------- |
2223| points  | Array\<[common2D.Point](js-apis-graphics-common2D.md#point)> | Yes   | Array that holds the points to draw. The length cannot be 0.  |
2224| mode | [PointMode](#pointmode12)                  | No   | Mode in which the points are drawn. The default value is **drawing.PointMode.POINTS**.|
2225
2226**Error codes**
2227
2228For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2229
2230| ID| Error Message|
2231| ------- | --------------------------------------------|
2232| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.|
2233
2234**Example**
2235
2236```ts
2237import { RenderNode } from '@kit.ArkUI';
2238import { common2D, drawing } from '@kit.ArkGraphics2D';
2239class DrawingRenderNode extends RenderNode {
2240  draw(context : DrawContext) {
2241    const canvas = context.canvas;
2242    const pen = new drawing.Pen();
2243    pen.setStrokeWidth(30);
2244    const color : common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
2245    pen.setColor(color);
2246    canvas.attachPen(pen);
2247    canvas.drawPoints([{x: 100, y: 200}, {x: 150, y: 230}, {x: 200, y: 300}], drawing.PointMode.POINTS);
2248    canvas.detachPen();
2249  }
2250}
2251```
2252
2253### drawPath
2254
2255drawPath(path: Path): void
2256
2257Draws a custom path, which contains a set of path outlines. Each path outline can be open or closed.
2258
2259**System capability**: SystemCapability.Graphics.Drawing
2260
2261**Parameters**
2262
2263| Name| Type         | Mandatory| Description              |
2264| ------ | ------------- | ---- | ------------------ |
2265| path   | [Path](#path) | Yes  | **Path** object to draw.|
2266
2267**Error codes**
2268
2269For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2270
2271| ID| Error Message|
2272| ------- | --------------------------------------------|
2273| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2274
2275**Example**
2276
2277```ts
2278import { RenderNode } from '@kit.ArkUI';
2279import { drawing } from '@kit.ArkGraphics2D';
2280class DrawingRenderNode extends RenderNode {
2281  draw(context : DrawContext) {
2282    const canvas = context.canvas;
2283    const pen = new drawing.Pen();
2284    pen.setStrokeWidth(5);
2285    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2286    let path = new drawing.Path();
2287    path.moveTo(10,10);
2288    path.cubicTo(10, 10, 10, 10, 15, 15);
2289    path.close();
2290    canvas.attachPen(pen);
2291    canvas.drawPath(path);
2292    canvas.detachPen();
2293  }
2294}
2295```
2296
2297### drawLine
2298
2299drawLine(x0: number, y0: number, x1: number, y1: number): void
2300
2301Draws 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.
2302
2303**System capability**: SystemCapability.Graphics.Drawing
2304
2305**Parameters**
2306
2307| Name| Type  | Mandatory| Description                   |
2308| ------ | ------ | ---- | ----------------------- |
2309| x0     | number | Yes  | X coordinate of the start point of the line segment. The value is a floating point number.|
2310| y0     | number | Yes  | Y coordinate of the start point of the line segment. The value is a floating point number.|
2311| x1     | number | Yes  | X coordinate of the end point of the line segment. The value is a floating point number.|
2312| y1     | number | Yes  | Y coordinate of the end point of the line segment. The value is a floating point number.|
2313
2314**Error codes**
2315
2316For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2317
2318| ID| Error Message|
2319| ------- | --------------------------------------------|
2320| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2321
2322**Example**
2323
2324```ts
2325import { RenderNode } from '@kit.ArkUI';
2326import { drawing } from '@kit.ArkGraphics2D';
2327class DrawingRenderNode extends RenderNode {
2328  draw(context : DrawContext) {
2329    const canvas = context.canvas;
2330    const pen = new drawing.Pen();
2331    pen.setStrokeWidth(5);
2332    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2333    canvas.attachPen(pen);
2334    canvas.drawLine(0, 0, 20, 20);
2335    canvas.detachPen();
2336  }
2337}
2338```
2339
2340### drawTextBlob
2341
2342drawTextBlob(blob: TextBlob, x: number, y: number): void
2343
2344Draws a text blob. If the typeface used to construct **blob** does not support a character, that character will not be drawn.
2345
2346**System capability**: SystemCapability.Graphics.Drawing
2347
2348**Parameters**
2349
2350| Name| Type                 | Mandatory| Description                                      |
2351| ------ | --------------------- | ---- | ------------------------------------------ |
2352| blob   | [TextBlob](#textblob) | Yes  | **TextBlob** object.                            |
2353| 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.|
2354| 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.|
2355
2356![image_Text_Blob.png](figures/image_Text_Blob.png)
2357
2358**Error codes**
2359
2360For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2361
2362| ID| Error Message|
2363| ------- | --------------------------------------------|
2364| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2365
2366**Example**
2367
2368```ts
2369import { RenderNode } from '@kit.ArkUI';
2370import { drawing } from '@kit.ArkGraphics2D';
2371class DrawingRenderNode extends RenderNode {
2372  draw(context : DrawContext) {
2373    const canvas = context.canvas;
2374    const brush = new drawing.Brush();
2375    brush.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2376    const font = new drawing.Font();
2377    font.setSize(20);
2378    const textBlob = drawing.TextBlob.makeFromString("Hello, drawing", font, drawing.TextEncoding.TEXT_ENCODING_UTF8);
2379    canvas.attachBrush(brush);
2380    canvas.drawTextBlob(textBlob, 20, 20);
2381    canvas.detachBrush();
2382  }
2383}
2384```
2385
2386### drawSingleCharacter<sup>12+</sup>
2387
2388drawSingleCharacter(text: string, font: Font, x: number, y: number): void
2389
2390Draws 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.
2391
2392**System capability**: SystemCapability.Graphics.Drawing
2393
2394**Parameters**
2395
2396| Name| Type               | Mandatory| Description       |
2397| ------ | ------------------- | ---- | ----------- |
2398| text   | string | Yes  | Single character to draw. The length of the string must be 1. |
2399| font   | [Font](#font) | Yes  | **Font** object. |
2400| 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.|
2401| 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.|
2402
2403![image_Text_Blob.png](figures/image_Text_Blob.png)
2404
2405**Error codes**
2406
2407For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2408
2409| ID| Error Message|
2410| ------- | --------------------------------------------|
2411| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
2412
2413**Example**
2414
2415```ts
2416import { RenderNode } from '@kit.ArkUI';
2417import { drawing } from '@kit.ArkGraphics2D';
2418
2419class DrawingRenderNode extends RenderNode {
2420  draw(context : DrawContext) {
2421    const canvas = context.canvas;
2422    const brush = new drawing.Brush();
2423    brush.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2424    const font = new drawing.Font();
2425    font.setSize(20);
2426    canvas.attachBrush(brush);
2427    canvas.drawSingleCharacter ("Hello", font, 100, 100);
2428    canvas.drawSingleCharacter ("drawing", font, 120, 100);
2429    canvas.detachBrush();
2430  }
2431}
2432```
2433
2434### drawRegion<sup>12+</sup>
2435
2436drawRegion(region: Region): void
2437
2438Draws a region.
2439
2440**System capability**: SystemCapability.Graphics.Drawing
2441
2442**Parameters**
2443
2444| Name| Type               | Mandatory| Description       |
2445| ------ | ------------------- | ---- | ----------- |
2446| region   | [Region](#region12) | Yes  | Region to draw. |
2447
2448**Error codes**
2449
2450For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2451
2452| ID| Error Message|
2453| ------- | --------------------------------------------|
2454| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2455
2456**Example**
2457
2458```ts
2459import { RenderNode } from '@kit.ArkUI';
2460class DrawingRenderNode extends RenderNode {
2461  draw(context : DrawContext) {
2462    const canvas = context.canvas;
2463    const pen = new drawing.Pen();
2464    let region = new drawing.Region();
2465    pen.setStrokeWidth(10);
2466    pen.setColor({ alpha: 255, red: 255, green: 0, blue: 0 });
2467    canvas.attachPen(pen);
2468    region.setRect(100, 100, 400, 400);
2469    canvas.drawRegion(region);
2470    canvas.detachPen();
2471  }
2472}
2473```
2474
2475### attachPen
2476
2477attachPen(pen: Pen): void
2478
2479Attaches a pen to a canvas so that the canvas can use the style and color of the pen to outline a shape.
2480
2481> **NOTE**
2482>
2483> 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.
2484
2485**System capability**: SystemCapability.Graphics.Drawing
2486
2487**Parameters**
2488
2489| Name| Type       | Mandatory| Description      |
2490| ------ | ----------- | ---- | ---------- |
2491| pen    | [Pen](#pen) | Yes  | **Pen** object.|
2492
2493**Error codes**
2494
2495For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2496
2497| ID| Error Message|
2498| ------- | --------------------------------------------|
2499| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2500
2501**Example**
2502
2503```ts
2504import { RenderNode } from '@kit.ArkUI';
2505import { drawing } from '@kit.ArkGraphics2D';
2506class DrawingRenderNode extends RenderNode {
2507  draw(context : DrawContext) {
2508    const canvas = context.canvas;
2509    const pen = new drawing.Pen();
2510    pen.setStrokeWidth(5);
2511    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2512    canvas.attachPen(pen);
2513    canvas.drawRect({ left : 0, right : 10, top : 0, bottom : 10 });
2514    canvas.detachPen();
2515  }
2516}
2517```
2518
2519### attachBrush
2520
2521attachBrush(brush: Brush): void
2522
2523Attaches a brush to a canvas so that the canvas can use the style and color of the brush to fill in a shape.
2524
2525> **NOTE**
2526>
2527> 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.
2528
2529**System capability**: SystemCapability.Graphics.Drawing
2530
2531**Parameters**
2532
2533| Name| Type           | Mandatory| Description      |
2534| ------ | --------------- | ---- | ---------- |
2535| brush  | [Brush](#brush) | Yes  | **Brush** object.|
2536
2537**Error codes**
2538
2539For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2540
2541| ID| Error Message|
2542| ------- | --------------------------------------------|
2543| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2544
2545**Example**
2546
2547```ts
2548import { RenderNode } from '@kit.ArkUI';
2549import { drawing } from '@kit.ArkGraphics2D';
2550class DrawingRenderNode extends RenderNode {
2551  draw(context : DrawContext) {
2552    const canvas = context.canvas;
2553    const brush = new drawing.Brush();
2554    brush.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2555    canvas.attachBrush(brush);
2556    canvas.drawRect({ left : 0, right : 10, top : 0, bottom : 10 });
2557    canvas.detachBrush();
2558  }
2559}
2560```
2561
2562### detachPen
2563
2564detachPen(): void
2565
2566Detaches the pen from a canvas so that the canvas can no longer use the style and color of the pen to outline a shape.
2567
2568**System capability**: SystemCapability.Graphics.Drawing
2569
2570**Example**
2571
2572```ts
2573import { RenderNode } from '@kit.ArkUI';
2574import { drawing } from '@kit.ArkGraphics2D';
2575class DrawingRenderNode extends RenderNode {
2576  draw(context : DrawContext) {
2577    const canvas = context.canvas;
2578    const pen = new drawing.Pen();
2579    pen.setStrokeWidth(5);
2580    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2581    canvas.attachPen(pen);
2582    canvas.drawRect({ left : 0, right : 10, top : 0, bottom : 10 });
2583    canvas.detachPen();
2584  }
2585}
2586```
2587
2588### detachBrush
2589
2590detachBrush(): void
2591
2592Detaches 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.
2593
2594**System capability**: SystemCapability.Graphics.Drawing
2595
2596**Example**
2597
2598```ts
2599import { RenderNode } from '@kit.ArkUI';
2600import { drawing } from '@kit.ArkGraphics2D';
2601class DrawingRenderNode extends RenderNode {
2602  draw(context : DrawContext) {
2603    const canvas = context.canvas;
2604    const brush = new drawing.Brush();
2605    brush.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2606    canvas.attachBrush(brush);
2607    canvas.drawRect({ left : 0, right : 10, top : 0, bottom : 10 });
2608    canvas.detachBrush();
2609  }
2610}
2611```
2612
2613### clipPath<sup>12+</sup>
2614
2615clipPath(path: Path, clipOp?: ClipOp, doAntiAlias?: boolean): void
2616
2617Clips a path.
2618
2619**System capability**: SystemCapability.Graphics.Drawing
2620
2621**Parameters**
2622
2623| Name      | Type              | Mandatory| Description                               |
2624| ------------ | ----------------- | ---- | ------------------------------------|
2625| path         | [Path](#path)     | Yes  | **Path** object.                                                |
2626| clipOp       | [ClipOp](#clipop12) | No  | Clip mode. The default value is **INTERSECT**.                                    |
2627| 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**.|
2628
2629**Error codes**
2630
2631For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2632
2633| ID| Error Message|
2634| ------- | --------------------------------------------|
2635| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2636
2637**Example**
2638
2639```ts
2640import { RenderNode } from '@kit.ArkUI';
2641import { common2D, drawing } from '@kit.ArkGraphics2D';
2642class DrawingRenderNode extends RenderNode {
2643  draw(context : DrawContext) {
2644    const canvas = context.canvas;
2645    const pen = new drawing.Pen();
2646    pen.setStrokeWidth(5);
2647    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2648    let path = new drawing.Path();
2649    path.moveTo(10, 10);
2650    path.cubicTo(10, 10, 10, 10, 15, 15);
2651    path.close();
2652    canvas.attachPen(pen);
2653    canvas.clipPath(path, drawing.ClipOp.DIFFERENCE, true);
2654    canvas.detachPen();
2655  }
2656}
2657```
2658
2659### clipRect<sup>12+</sup>
2660
2661clipRect(rect: common2D.Rect, clipOp?: ClipOp, doAntiAlias?: boolean): void
2662
2663Clips a rectangle.
2664
2665**System capability**: SystemCapability.Graphics.Drawing
2666
2667**Parameters**
2668
2669| Name        | Type                                      | Mandatory  | Description                 |
2670| ----------- | ---------------------------------------- | ---- | ------------------- |
2671| rect        | [common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes   | Rectangle.     |
2672| clipOp      | [ClipOp](#clipop12)                  | No   | Clip mode. The default value is **INTERSECT**.    |
2673| 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**.|
2674
2675**Error codes**
2676
2677For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2678
2679| ID| Error Message|
2680| ------- | --------------------------------------------|
2681| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2682
2683**Example**
2684
2685```ts
2686import { RenderNode } from '@kit.ArkUI';
2687import { common2D, drawing } from '@kit.ArkGraphics2D';
2688class DrawingRenderNode extends RenderNode {
2689  draw(context : DrawContext) {
2690    const canvas = context.canvas;
2691    const pen = new drawing.Pen();
2692    pen.setStrokeWidth(5);
2693    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2694    canvas.attachPen(pen);
2695    canvas.clipRect({left : 10, right : 500, top : 300, bottom : 900}, drawing.ClipOp.DIFFERENCE, true);
2696    canvas.detachPen();
2697  }
2698}
2699```
2700
2701### save<sup>12+</sup>
2702
2703save(): number
2704
2705Saves the current canvas status (canvas matrix) to the top of the stack.
2706
2707**System capability**: SystemCapability.Graphics.Drawing
2708
2709**Return value**
2710
2711| Type  | Description               |
2712| ------ | ------------------ |
2713| number | Number of canvas statuses. The value is a positive integer.|
2714
2715**Example**
2716
2717```ts
2718import { RenderNode } from '@kit.ArkUI';
2719import { common2D, drawing } from '@kit.ArkGraphics2D';
2720class DrawingRenderNode extends RenderNode {
2721  draw(context : DrawContext) {
2722    const canvas = context.canvas;
2723    let rect: common2D.Rect = {left: 10, right: 200, top: 100, bottom: 300};
2724    canvas.drawRect(rect);
2725    let saveCount = canvas.save();
2726  }
2727}
2728```
2729
2730### saveLayer<sup>12+</sup>
2731
2732saveLayer(rect?: common2D.Rect | null, brush?: Brush | null): number
2733
2734Saves 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.
2735
2736**System capability**: SystemCapability.Graphics.Drawing
2737
2738**Parameters**
2739
2740| Name | Type    | Mandatory  | Description        |
2741| ---- | ------ | ---- | ----------------- |
2742| 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.|
2743| 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.|
2744
2745**Return value**
2746
2747| Type  | Description               |
2748| ------ | ------------------ |
2749| number | Number of canvas statuses that have been saved. The value is a positive integer.|
2750
2751**Error codes**
2752
2753For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2754
2755| ID| Error Message|
2756| ------- | --------------------------------------------|
2757| 401 | Parameter error. Possible causes: Mandatory parameters are left unspecified. |
2758
2759**Example**
2760
2761```ts
2762import { RenderNode } from '@kit.ArkUI';
2763import { common2D, drawing } from '@kit.ArkGraphics2D';
2764class DrawingRenderNode extends RenderNode {
2765  draw(context : DrawContext) {
2766    const canvas = context.canvas;
2767    canvas.saveLayer(null, null);
2768    const brushRect = new drawing.Brush();
2769    const colorRect: common2D.Color = {alpha: 255, red: 255, green: 255, blue: 0};
2770    brushRect.setColor(colorRect);
2771    canvas.attachBrush(brushRect);
2772    const rect: common2D.Rect = {left:100, top:100, right:500, bottom:500};
2773    canvas.drawRect(rect);
2774
2775    const brush = new drawing.Brush();
2776    brush.setBlendMode(drawing.BlendMode.DST_OUT);
2777    canvas.saveLayer(rect, brush);
2778
2779    const brushCircle = new drawing.Brush();
2780    const colorCircle: common2D.Color = {alpha: 255, red: 0, green: 0, blue: 255};
2781    brushCircle.setColor(colorCircle);
2782    canvas.attachBrush(brushCircle);
2783    canvas.drawCircle(500, 500, 200);
2784    canvas.restore();
2785    canvas.restore();
2786    canvas.detachBrush();
2787  }
2788}
2789```
2790
2791### scale<sup>12+</sup>
2792
2793scale(sx: number, sy: number): void
2794
2795Scales the canvas.
2796
2797**System capability**: SystemCapability.Graphics.Drawing
2798
2799**Parameters**
2800
2801| Name | Type    | Mandatory  | Description        |
2802| ---- | ------ | ---- | ----------------- |
2803| sx   | number | Yes  | Scale ratio on the X axis. The value is a floating point number.|
2804| sy   | number | Yes  | Scale ratio on the Y axis. The value is a floating point number.|
2805
2806**Error codes**
2807
2808For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2809
2810| ID| Error Message|
2811| ------- | --------------------------------------------|
2812| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2813
2814**Example**
2815
2816```ts
2817import { RenderNode } from '@kit.ArkUI';
2818import { common2D, drawing } from '@kit.ArkGraphics2D';
2819class DrawingRenderNode extends RenderNode {
2820  draw(context : DrawContext) {
2821    const canvas = context.canvas;
2822    const pen = new drawing.Pen();
2823    pen.setStrokeWidth(5);
2824    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2825    canvas.attachPen(pen);
2826    canvas.scale(2, 0.5);
2827    canvas.drawRect({left : 10, right : 500, top : 300, bottom : 900});
2828    canvas.detachPen();
2829  }
2830}
2831```
2832
2833### skew<sup>12+</sup>
2834
2835skew(sx: number, sy: number) : void
2836
2837Skews the canvas in both the horizontal and vertical directions.
2838
2839**System capability**: SystemCapability.Graphics.Drawing
2840
2841**Parameters**
2842
2843| Name | Type    | Mandatory  | Description        |
2844| ---- | ------ | ---- | ----------------- |
2845| sx   | number | Yes  | Amount of tilt on the X axis. The value is a floating point number.   |
2846| sy   | number | Yes  | Amount of tilt on the Y axis. The value is a floating point number.   |
2847
2848**Error codes**
2849
2850For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2851
2852| ID| Error Message|
2853| ------- | --------------------------------------------|
2854| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2855
2856**Example**
2857
2858```ts
2859import { RenderNode } from '@kit.ArkUI';
2860import { common2D, drawing } from '@kit.ArkGraphics2D';
2861class DrawingRenderNode extends RenderNode {
2862  draw(context : DrawContext) {
2863    const canvas = context.canvas;
2864    const pen = new drawing.Pen();
2865    pen.setStrokeWidth(5);
2866    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2867    canvas.attachPen(pen);
2868    canvas.skew(0.1, 0.1);
2869    canvas.drawRect({left : 10, right : 500, top : 300, bottom : 900});
2870    canvas.detachPen();
2871  }
2872}
2873```
2874
2875### rotate<sup>12+</sup>
2876
2877rotate(degrees: number, sx: number, sy: number) : void
2878
2879Rotates the canvas by a certain angle.
2880
2881**System capability**: SystemCapability.Graphics.Drawing
2882
2883**Parameters**
2884
2885| Name | Type    | Mandatory  | Description        |
2886| ---- | ------ | ------ | ------------------------ |
2887| 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. |
2888| sx            | number | Yes   | X coordinate of the rotation center. The value is a floating point number.|
2889| sy            | number | Yes   | Y coordinate of the rotation center. The value is a floating point number.|
2890
2891**Error codes**
2892
2893For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2894
2895| ID| Error Message|
2896| ------- | --------------------------------------------|
2897| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2898
2899**Example**
2900
2901```ts
2902import { RenderNode } from '@kit.ArkUI';
2903import { common2D, drawing } from '@kit.ArkGraphics2D';
2904class DrawingRenderNode extends RenderNode {
2905  draw(context : DrawContext) {
2906    const canvas = context.canvas;
2907    const pen = new drawing.Pen();
2908    pen.setStrokeWidth(5);
2909    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2910    canvas.attachPen(pen);
2911    canvas.rotate(30, 100, 100);
2912    canvas.drawRect({left : 10, right : 500, top : 300, bottom : 900});
2913    canvas.detachPen();
2914  }
2915}
2916```
2917
2918### translate<sup>12+</sup>
2919
2920translate(dx: number, dy: number): void
2921
2922Translates the canvas by a given distance.
2923
2924**System capability**: SystemCapability.Graphics.Drawing
2925
2926**Parameters**
2927
2928| Name| Type  | Mandatory| Description               |
2929| ----- | ------ | ---- | ------------------- |
2930| dx    | number | Yes  | Distance to translate on the X axis. The value is a floating point number.  |
2931| dy    | number | Yes  | Distance to translate on the Y axis. The value is a floating point number.  |
2932
2933**Error codes**
2934
2935For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2936
2937| ID| Error Message|
2938| ------- | --------------------------------------------|
2939| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
2940
2941**Example**
2942
2943```ts
2944import { RenderNode } from '@kit.ArkUI';
2945import { common2D, drawing } from '@kit.ArkGraphics2D';
2946class DrawingRenderNode extends RenderNode {
2947  draw(context : DrawContext) {
2948    const canvas = context.canvas;
2949    const pen = new drawing.Pen();
2950    pen.setStrokeWidth(5);
2951    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2952    canvas.attachPen(pen);
2953    canvas.translate(10, 10);
2954    canvas.drawRect({left : 10, right : 500, top : 300, bottom : 900});
2955    canvas.detachPen();
2956  }
2957}
2958```
2959
2960### getSaveCount<sup>12+</sup>
2961
2962getSaveCount(): number
2963
2964Obtains the number of canvas statuses (canvas matrices) saved in the stack.
2965
2966**System capability**: SystemCapability.Graphics.Drawing
2967
2968**Return value**
2969
2970| Type   | Description                                |
2971| ------ | ------------------------------------ |
2972| number | Number of canvas statuses that have been saved. The value is a positive integer.|
2973
2974**Example**
2975
2976```ts
2977import { RenderNode } from '@kit.ArkUI';
2978import { common2D, drawing } from '@kit.ArkGraphics2D';
2979class DrawingRenderNode extends RenderNode {
2980  draw(context : DrawContext) {
2981    const canvas = context.canvas;
2982    const pen = new drawing.Pen();
2983    pen.setStrokeWidth(5);
2984    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
2985    canvas.attachPen(pen);
2986    canvas.drawRect({left: 10, right: 200, top: 100, bottom: 300});
2987    canvas.save();
2988    canvas.drawRect({left : 10, right : 500, top : 300, bottom : 900});
2989    canvas.getSaveCount();
2990    canvas.detachPen();
2991  }
2992}
2993```
2994
2995### restoreToCount<sup>12+</sup>
2996
2997restoreToCount(count: number): void
2998
2999Restores to a given number of canvas statuses (canvas matrices).
3000
3001**System capability**: SystemCapability.Graphics.Drawing
3002
3003**Parameters**
3004
3005| Name  | Type    | Mandatory  | Description                   |
3006| ----- | ------ | ---- | ----------------------------- |
3007| 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.|
3008
3009**Error codes**
3010
3011For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3012
3013| ID| Error Message|
3014| ------- | --------------------------------------------|
3015| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
3016
3017**Example**
3018
3019```ts
3020import { RenderNode } from '@kit.ArkUI';
3021import { common2D, drawing } from '@kit.ArkGraphics2D';
3022class DrawingRenderNode extends RenderNode {
3023  draw(context : DrawContext) {
3024    const canvas = context.canvas;
3025    const pen = new drawing.Pen();
3026    pen.setStrokeWidth(5);
3027    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
3028    canvas.attachPen(pen);
3029    canvas.drawRect({left: 10, right: 200, top: 100, bottom: 300});
3030    canvas.save();
3031    canvas.drawRect({left: 10, right: 200, top: 100, bottom: 500});
3032    canvas.save();
3033    canvas.drawRect({left: 100, right: 300, top: 100, bottom: 500});
3034    canvas.save();
3035    canvas.restoreToCount(2);
3036    canvas.drawRect({left : 10, right : 500, top : 300, bottom : 900});
3037    canvas.detachPen();
3038  }
3039}
3040```
3041
3042### restore<sup>12+</sup>
3043
3044restore(): void
3045
3046Restores the canvas status (canvas matrix) saved on the top of the stack.
3047
3048**System capability**: SystemCapability.Graphics.Drawing
3049
3050**Example**
3051
3052```ts
3053import { RenderNode } from '@kit.ArkUI';
3054import { common2D, drawing } from '@kit.ArkGraphics2D';
3055class DrawingRenderNode extends RenderNode {
3056  draw(context : DrawContext) {
3057    const canvas = context.canvas;
3058    const pen = new drawing.Pen();
3059    pen.setStrokeWidth(5);
3060    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
3061    canvas.attachPen(pen);
3062    canvas.restore();
3063    canvas.detachPen();
3064  }
3065}
3066```
3067
3068### concatMatrix<sup>12+</sup>
3069
3070concatMatrix(matrix: Matrix): void
3071
3072Preconcats the existing matrix of the canvas with the passed-in matrix. The drawing operation triggered before this API is called is not affected.
3073
3074**System capability**: SystemCapability.Graphics.Drawing
3075
3076**Parameters**
3077
3078| Name   | Type               | Mandatory  | Description   |
3079| ------ | ----------------- | ---- | ----- |
3080| matrix | [Matrix](#matrix12) | Yes   | **Matrix** object.|
3081
3082**Error codes**
3083
3084For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3085
3086| ID| Error Message|
3087| ------- | --------------------------------------------|
3088| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
3089
3090**Example**
3091
3092```ts
3093import { RenderNode } from '@kit.ArkUI';
3094import { drawing } from '@kit.ArkGraphics2D';
3095class DrawingRenderNode extends RenderNode {
3096  draw(context : DrawContext) {
3097    const canvas = context.canvas;
3098    let matrix = new drawing.Matrix();
3099    matrix.setMatrix([5, 0, 0, 0, 1, 2, 0, 0, 1]);
3100    canvas.concatMatrix(matrix);
3101  }
3102}
3103```
3104
3105### setMatrix<sup>12+</sup>
3106
3107setMatrix(matrix: Matrix): void
3108
3109Sets a matrix for the canvas.
3110
3111**System capability**: SystemCapability.Graphics.Drawing
3112
3113**Parameters**
3114
3115| Name   | Type               | Mandatory  | Description   |
3116| ------ | ----------------- | ---- | ----- |
3117| matrix | [Matrix](#matrix12) | Yes   | **Matrix** object.|
3118
3119**Error codes**
3120
3121For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3122
3123| ID| Error Message|
3124| ------- | --------------------------------------------|
3125| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
3126
3127**Example**
3128
3129```ts
3130import { RenderNode } from '@kit.ArkUI';
3131import { drawing } from '@kit.ArkGraphics2D';
3132class DrawingRenderNode extends RenderNode {
3133  draw(context : DrawContext) {
3134    const canvas = context.canvas;
3135    let matrix = new drawing.Matrix()
3136    matrix.setMatrix([5, 0, 0, 0, 1, 1, 0, 0, 1]);
3137    canvas.setMatrix(matrix);
3138  }
3139}
3140```
3141
3142### isClipEmpty<sup>12+</sup>
3143
3144isClipEmpty(): boolean
3145
3146Checks whether the region that can be drawn is empty after clipping.
3147
3148**System capability**: SystemCapability.Graphics.Drawing
3149
3150**Return value**
3151
3152| Type                 | Description          |
3153| --------------------- | -------------- |
3154| boolean | Chek result. The value **true** means that the region is empty, and **false** means the opposite.|
3155
3156**Example**
3157
3158```ts
3159import { RenderNode } from '@kit.ArkUI';
3160import { drawing } from '@kit.ArkGraphics2D';
3161class DrawingRenderNode extends RenderNode {
3162  draw(context : DrawContext) {
3163    const canvas = context.canvas;
3164    if (canvas.isClipEmpty()) {
3165      console.info("canvas.isClipEmpty() returned true");
3166    } else {
3167      console.info("canvas.isClipEmpty() returned false");
3168    }
3169  }
3170}
3171```
3172
3173### clipRegion<sup>12+</sup>
3174
3175clipRegion(region: Region, clipOp?: ClipOp): void
3176
3177Clips a region on the canvas.
3178
3179**System capability**: SystemCapability.Graphics.Drawing
3180
3181**Parameters**
3182
3183| Name         | Type   | Mandatory| Description                                                       |
3184| --------------- | ------- | ---- | ----------------------------------------------------------- |
3185| region | [Region](#region12) | Yes  | **Region** object, which indicates the range to clip.|
3186| clipOp | [ClipOp](#clipop12)   | No  | Clipping mode. The default value is **INTERSECT**.|
3187
3188**Error codes**
3189
3190For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3191
3192| ID| Error Message|
3193| ------- | --------------------------------------------|
3194| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
3195
3196**Example**
3197
3198```ts
3199import { RenderNode } from '@kit.ArkUI';
3200import { drawing } from '@kit.ArkGraphics2D';
3201class DrawingRenderNode extends RenderNode {
3202  draw(context : DrawContext) {
3203    const canvas = context.canvas;
3204    let region : drawing.Region = new drawing.Region();
3205    region.setRect(0, 0, 500, 500);
3206    canvas.clipRegion(region);
3207  }
3208}
3209```
3210
3211### clipRoundRect<sup>12+</sup>
3212
3213clipRoundRect(roundRect: RoundRect, clipOp?: ClipOp, doAntiAlias?: boolean): void
3214
3215Clips a rounded rectangle on the canvas.
3216
3217**System capability**: SystemCapability.Graphics.Drawing
3218
3219**Parameters**
3220
3221| Name         | Type   | Mandatory| Description                                                       |
3222| --------------- | ------- | ---- | ----------------------------------------------------------- |
3223| roundRect | [RoundRect](#roundrect12) | Yes  | **RoundRect** object, which indicates the range to clip.|
3224| clipOp | [ClipOp](#clipop12)   | No  | Clipping mode. The default value is **INTERSECT**.|
3225| 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**.|
3226
3227**Error codes**
3228
3229For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3230
3231| ID| Error Message|
3232| ------- | --------------------------------------------|
3233| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
3234
3235**Example**
3236
3237```ts
3238import { RenderNode } from '@kit.ArkUI';
3239import { common2D, drawing } from '@kit.ArkGraphics2D';
3240class DrawingRenderNode extends RenderNode {
3241  draw(context : DrawContext) {
3242    const canvas = context.canvas;
3243    let rect: common2D.Rect = { left: 10, top: 100, right: 200, bottom: 300 };
3244    let roundRect = new drawing.RoundRect(rect, 10, 10);
3245    canvas.clipRoundRect(roundRect);
3246  }
3247}
3248```
3249
3250### resetMatrix<sup>12+</sup>
3251
3252resetMatrix(): void
3253
3254Resets the matrix of this canvas to an identity matrix.
3255
3256**System capability**: SystemCapability.Graphics.Drawing
3257
3258**Example**
3259
3260```ts
3261import { RenderNode } from '@kit.ArkUI';
3262import { drawing } from '@kit.ArkGraphics2D';
3263class DrawingRenderNode extends RenderNode {
3264  draw(context : DrawContext) {
3265    const canvas = context.canvas;
3266    canvas.scale(4, 6);
3267    canvas.resetMatrix();
3268  }
3269}
3270```
3271
3272## ImageFilter<sup>12+</sup>
3273
3274Implements an image filter.
3275
3276### createBlurImageFilter<sup>12+</sup>
3277
3278static createBlurImageFilter(sigmaX: number, sigmaY: number, tileMode: TileMode, imageFilter?: ImageFilter | null ): ImageFilter
3279
3280Creates an image filter with a given blur effect.
3281
3282**System capability**: SystemCapability.Graphics.Drawing
3283
3284**Parameters**
3285
3286| Name         | Type   | Mandatory| Description                                                       |
3287| --------------- | ------- | ---- | ----------------------------------------------------------- |
3288| sigmaX | number | Yes  | Standard deviation of the Gaussian blur along the X axis. The value must be a floating point number greater than 0.|
3289| sigmaY | number | Yes  | Standard deviation of the Gaussian blur along the Y axis. The value must be a floating point number greater than 0.|
3290| tileMode | [TileMode](#tilemode12)| Yes  | Tile mode to apply to the edges.|
3291| 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.|
3292
3293**Return value**
3294
3295| Type                 | Description          |
3296| --------------------- | -------------- |
3297| [ImageFilter](#imagefilter12) | Image filter created.|
3298
3299**Error codes**
3300
3301For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3302
3303| ID| Error Message|
3304| ------- | --------------------------------------------|
3305| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
3306
3307**Example**
3308
3309```ts
3310import { drawing } from '@kit.ArkGraphics2D';
3311let imgFilter = drawing.ImageFilter.createBlurImageFilter(5, 10, drawing.TileMode.CLAMP);
3312```
3313
3314### createFromColorFilter<sup>12+</sup>
3315
3316static createFromColorFilter(colorFilter: ColorFilter, imageFilter?: ImageFilter | null): ImageFilter
3317
3318Creates an image filter object with a given color filter effect.
3319
3320**System capability**: SystemCapability.Graphics.Drawing
3321
3322**Parameters**
3323
3324| Name         | Type   | Mandatory| Description                                                       |
3325| --------------- | ------- | ---- | ----------------------------------------------------------- |
3326| colorFilter | [ColorFilter](#colorfilter) | Yes  | Color filter.|
3327| 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.|
3328
3329**Return value**
3330
3331| Type                 | Description          |
3332| --------------------- | -------------- |
3333| [ImageFilter](#imagefilter12) | Image filter created.|
3334
3335**Error codes**
3336
3337For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3338
3339| ID| Error Message|
3340| ------- | --------------------------------------------|
3341| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
3342
3343**Example**
3344
3345```ts
3346import { drawing } from '@kit.ArkGraphics2D';
3347let imgFilter = drawing.ImageFilter.createBlurImageFilter(5, 10, drawing.TileMode.CLAMP);
3348let clolorfilter = drawing.ColorFilter.createSRGBGammaToLinear();
3349let imgFilter1 = drawing.ImageFilter.createFromColorFilter(clolorfilter, imgFilter);
3350```
3351
3352## TextBlobRunBuffer
3353
3354Describes a series of consecutive glyphs with the same attributes in a text blob.
3355
3356**System capability**: SystemCapability.Graphics.Drawing
3357
3358| Name     | Type  | Readable| Writable| Description                     |
3359| --------- | ------ | ---- | ---- | ------------------------- |
3360| 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.|
3361| positionX | number | Yes  | Yes  | X coordinate of the start point of the text blob. The value is a floating point number.|
3362| positionY | number | Yes  | Yes  | Y coordinate of the start point of the text blob. The value is a floating point number.|
3363
3364## TextEncoding
3365
3366Enumerates the text encoding types.
3367
3368**System capability**: SystemCapability.Graphics.Drawing
3369
3370| Name                  | Value  | Description                          |
3371| ---------------------- | ---- | ------------------------------ |
3372| TEXT_ENCODING_UTF8     | 0    | One byte is used to indicate UTF-8 or ASCII characters. |
3373| TEXT_ENCODING_UTF16    | 1    | Two bytes are used to indicate most Unicode characters.|
3374| TEXT_ENCODING_UTF32    | 2    | Four bytes are used to indicate all Unicode characters.  |
3375| TEXT_ENCODING_GLYPH_ID | 3    | Two bytes are used to indicate the glyph index.  |
3376
3377## ClipOp<sup>12+</sup>
3378Enumerates the canvas clipping modes.
3379
3380
3381**System capability**: SystemCapability.Graphics.Drawing
3382
3383| Name                | Value   | Description          | Diagram  |
3384| ------------------ | ---- | ---------------- | -------- |
3385| DIFFERENCE | 0    | Clips a specified area. That is, the difference set is obtained.| ![DIFFERENCE](./figures/image_ClipOp_Difference.png) |
3386| INTERSECT  | 1    | Retains a specified area. That is, the intersection is obtained.| ![INTERSECT](./figures/image_ClipOp_Intersect.png) |
3387
3388> **NOTE**
3389>
3390> 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.
3391
3392## FilterMode<sup>12+</sup>
3393
3394Enumerates the filter modes.
3395
3396**System capability**: SystemCapability.Graphics.Drawing
3397
3398| Name                 | Value   | Description     |
3399| ------------------- | ---- | ------- |
3400| FILTER_MODE_NEAREST | 0    | Nearest filter mode.|
3401| FILTER_MODE_LINEAR  | 1    | Linear filter mode.|
3402
3403## PathDirection<sup>12+</sup>
3404
3405Enumerates the directions of a closed contour.
3406
3407**System capability**: SystemCapability.Graphics.Drawing
3408
3409| Name                 | Value   | Description     |
3410| ------------------- | ---- | ------- |
3411| CLOCKWISE   | 0    | Adds a closed contour clockwise.|
3412| COUNTER_CLOCKWISE  | 1    | Adds a closed contour counterclockwise.|
3413
3414## PathFillType<sup>12+</sup>
3415
3416Enumerates the fill types of a path.
3417
3418**System capability**: SystemCapability.Graphics.Drawing
3419
3420| Name                 | Value   | Description     |
3421| ------------------- | ---- | ------- |
3422| 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.|
3423| 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.|
3424| INVERSE_WINDING  | 2    | Same as **WINDING**, but draws outside of the path, rather than inside.|
3425| INVERSE_EVEN_ODD  | 3    | Same as **EVEN_ODD**, but draws outside of the path, rather than inside.|
3426
3427> **NOTE**
3428> ![WINDING&EVEN_ODD](./figures/image_PathFillType_Winding_Even_Odd.png)
3429> 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.
3430
3431## PointMode<sup>12+</sup>
3432
3433Enumerates the modes for drawing multiple points in an array.
3434
3435**System capability**: SystemCapability.Graphics.Drawing
3436
3437| Name                | Value   | Description           |
3438| ------------------ | ---- | ------------- |
3439| POINTS  | 0    | Draws each point separately.     |
3440| LINES   | 1    | Draws every two points as a line segment.   |
3441| POLYGON | 2    | Draws an array of points as an open polygon.|
3442
3443## FontEdging<sup>12+</sup>
3444
3445Enumerates the font edging types.
3446
3447**System capability**: SystemCapability.Graphics.Drawing
3448
3449| Name                 | Value   | Description     |
3450| ------------------- | ---- | ------- |
3451| ALIAS | 0    | No anti-aliasing processing is used.|
3452| ANTI_ALIAS  | 1    | Uses anti-aliasing to smooth the jagged edges.|
3453| SUBPIXEL_ANTI_ALIAS  | 2    | Uses sub-pixel anti-aliasing to provide a smoother effect for jagged edges.|
3454
3455## FontHinting<sup>12+</sup>
3456
3457Enumerates the font hinting types.
3458
3459**System capability**: SystemCapability.Graphics.Drawing
3460
3461| Name                 | Value   | Description     |
3462| ------------------- | ---- | ------- |
3463| NONE    | 0    | No font hinting is used.|
3464| SLIGHT  | 1    | Slight font hinting is used to improve contrast.|
3465| NORMAL  | 2    | Normal font hinting is used to improve contrast.|
3466| FULL    | 3    | Full font hinting is used to improve contrast.|
3467
3468## TextBlob
3469
3470Defines a block consisting of one or more characters with the same font.
3471
3472### makeFromPosText<sup>12+</sup>
3473
3474static makeFromPosText(text: string, len: number, points: common2D.Point[], font: Font): TextBlob
3475
3476Creates 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.
3477
3478**System capability**: SystemCapability.Graphics.Drawing
3479
3480**Parameters**
3481
3482| Name  | Type                         | Mandatory| Description                                  |
3483| -------- | ----------------------------- | ---- | -------------------------------------- |
3484| text     | string             | Yes  | Content to be used for drawing the text blob.                  |
3485| len      | number             | Yes  | Number of fonts. The value is an integer and is obtained from [countText](#counttext12).|
3486| 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**.|
3487| font     | [Font](#font)      | Yes  | **Font** object.|
3488
3489**Return value**
3490
3491| Type                 | Description          |
3492| --------------------- | -------------- |
3493| [TextBlob](#textblob) | **TextBlob** object.|
3494
3495
3496**Error codes**
3497
3498For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3499
3500| ID| Error Message|
3501| ------- | --------------------------------------------|
3502| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types. |
3503
3504**Example**
3505
3506```ts
3507import { RenderNode } from '@kit.ArkUI';
3508import { drawing,common2D} from '@kit.ArkGraphics2D';
3509
3510class DrawingRenderNode extends RenderNode {
3511  draw(context : DrawContext) {
3512    const canvas = context.canvas;
3513    let text : string = 'makeFromPosText';
3514    let font : drawing.Font = new drawing.Font();
3515    font.setSize(100);
3516    let length = font.countText(text);
3517    let points : common2D.Point[] = [];
3518    for (let i = 0; i !== length; ++i) {
3519      points.push({ x: i * 35, y: i * 35 });
3520    }
3521    let textblob : drawing.TextBlob =drawing.TextBlob.makeFromPosText(text, points.length, points, font);
3522    canvas.drawTextBlob(textblob, 100, 100);
3523  }
3524}
3525```
3526
3527### uniqueID<sup>12+</sup>
3528
3529uniqueID(): number
3530
3531Obtains the unique identifier of a text blob. The identifier is a non-zero value.
3532
3533**System capability**: SystemCapability.Graphics.Drawing
3534
3535**Return value**
3536
3537| Type                 | Description          |
3538| --------------------- | -------------- |
3539| number | Unique identifier of the text blob.|
3540
3541**Example**
3542
3543```ts
3544import {drawing} from "@kit.ArkGraphics2D"
3545let text : string = 'TextBlobUniqueId';
3546let font : drawing.Font = new drawing.Font();
3547font.setSize(100);
3548let textBlob = drawing.TextBlob.makeFromString(text, font, 0);
3549let id = textBlob.uniqueID();
3550console.info("uniqueID---------------" +id);
3551```
3552
3553### makeFromString
3554
3555static makeFromString(text: string, font: Font, encoding?: TextEncoding): TextBlob
3556
3557Converts a value of the string type into a **TextBlob** object.
3558
3559**System capability**: SystemCapability.Graphics.Drawing
3560
3561**Parameters**
3562
3563| Name  | Type                         | Mandatory| Description                                  |
3564| -------- | ----------------------------- | ---- | -------------------------------------- |
3565| text     | string                        | Yes  | Content to be used for drawing the text blob.                  |
3566| font     | [Font](#font)                 | Yes  | **Font** object.          |
3567| encoding | [TextEncoding](#textencoding) | No  | Encoding type. The default value is **TEXT_ENCODING_UTF8**.|
3568
3569**Return value**
3570
3571| Type                 | Description          |
3572| --------------------- | -------------- |
3573| [TextBlob](#textblob) | **TextBlob** object.|
3574
3575**Error codes**
3576
3577For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3578
3579| ID| Error Message|
3580| ------- | --------------------------------------------|
3581| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
3582
3583**Example**
3584
3585```ts
3586import { RenderNode } from '@kit.ArkUI';
3587import { drawing } from '@kit.ArkGraphics2D';
3588class DrawingRenderNode extends RenderNode {
3589  draw(context : DrawContext) {
3590    const canvas = context.canvas;
3591    const brush = new drawing.Brush();
3592    brush.setColor({alpha: 255, red: 255, green: 0, blue: 0});
3593    const font = new drawing.Font();
3594    font.setSize(20);
3595    const textBlob = drawing.TextBlob.makeFromString("drawing", font, drawing.TextEncoding.TEXT_ENCODING_UTF8);
3596    canvas.attachBrush(brush);
3597    canvas.drawTextBlob(textBlob, 20, 20);
3598    canvas.detachBrush();
3599  }
3600}
3601```
3602
3603### makeFromRunBuffer
3604
3605static makeFromRunBuffer(pos: Array\<TextBlobRunBuffer>, font: Font, bounds?: common2D.Rect): TextBlob
3606
3607Creates a **Textblob** object based on the RunBuffer information.
3608
3609**System capability**: SystemCapability.Graphics.Drawing
3610
3611**Parameters**
3612
3613| Name| Type                                              | Mandatory| Description                          |
3614| ------ | -------------------------------------------------- | ---- | ------------------------------ |
3615| pos    | Array\<[TextBlobRunBuffer](#textblobrunbuffer)>    | Yes  | **TextBlobRunBuffer** array.       |
3616| font   | [Font](#font)                                      | Yes  | **Font** object.  |
3617| bounds | [common2D.Rect](js-apis-graphics-common2D.md#rect) | No  | Bounding box. If this parameter is not set, there is no bounding box.|
3618
3619**Return value**
3620
3621| Type                 | Description          |
3622| --------------------- | -------------- |
3623| [TextBlob](#textblob) | **TextBlob** object.|
3624
3625**Error codes**
3626
3627For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3628
3629| ID| Error Message|
3630| ------- | --------------------------------------------|
3631| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
3632
3633**Example**
3634
3635```ts
3636import { RenderNode } from '@kit.ArkUI';
3637import { common2D, drawing } from '@kit.ArkGraphics2D';
3638class DrawingRenderNode extends RenderNode {
3639  draw(context : DrawContext) {
3640    const canvas = context.canvas;
3641    const font = new drawing.Font();
3642    font.setSize(20);
3643    let runBuffer : Array<drawing.TextBlobRunBuffer> = [
3644      { glyph: 65, positionX: 0, positionY: 0 },
3645      { glyph: 227, positionX: 14.9, positionY: 0 },
3646      { glyph: 283, positionX: 25.84, positionY: 0 },
3647      { glyph: 283, positionX: 30.62, positionY: 0 },
3648      { glyph: 299, positionX: 35.4, positionY: 0}
3649    ];
3650    const textBlob = drawing.TextBlob.makeFromRunBuffer(runBuffer, font, null);
3651    const brush = new drawing.Brush();
3652    brush.setColor({alpha: 255, red: 255, green: 0, blue: 0});
3653    canvas.attachBrush(brush);
3654    canvas.drawTextBlob(textBlob, 20, 20);
3655    canvas.detachBrush();
3656  }
3657}
3658```
3659
3660### bounds
3661
3662bounds(): common2D.Rect
3663
3664Obtains the rectangular bounding box of the text blob.
3665
3666**System capability**: SystemCapability.Graphics.Drawing
3667
3668**Return value**
3669
3670| Type                                              | Description                  |
3671| -------------------------------------------------- | ---------------------- |
3672| [common2D.Rect](js-apis-graphics-common2D.md#rect) | Rectangular bounding box.|
3673
3674**Example**
3675
3676```ts
3677import { common2D, drawing } from '@kit.ArkGraphics2D';
3678const font = new drawing.Font();
3679font.setSize(20);
3680const textBlob = drawing.TextBlob.makeFromString("drawing", font, drawing.TextEncoding.TEXT_ENCODING_UTF8);
3681let bounds = textBlob.bounds();
3682```
3683
3684## Typeface
3685
3686Describes the typeface such as SimSun and Kaiti.
3687
3688### getFamilyName
3689
3690getFamilyName(): string
3691
3692Obtains the name of the typeface, that is, the name of the font family.
3693
3694**System capability**: SystemCapability.Graphics.Drawing
3695
3696**Return value**
3697
3698| Type  | Description                |
3699| ------ | -------------------- |
3700| string | Typeface name.|
3701
3702**Example**
3703
3704```ts
3705import { drawing } from '@kit.ArkGraphics2D';
3706const font = new drawing.Font();
3707let typeface = font.getTypeface();
3708let familyName = typeface.getFamilyName();
3709```
3710
3711### makeFromFile<sup>12+</sup>
3712
3713static makeFromFile(filePath: string): Typeface
3714
3715Constructs a typeface from a file.
3716
3717**System capability**: SystemCapability.Graphics.Drawing
3718
3719**Parameters**
3720
3721| Name        | Type                                      | Mandatory  | Description                 |
3722| ----------- | ---------------------------------------- | ---- | ------------------- |
3723| filePath | string           | Yes  | Path of the file.|
3724
3725**Return value**
3726
3727| Type  | Description                |
3728| ------ | -------------------- |
3729| [Typeface](#typeface) | **Typeface** object.|
3730
3731**Error codes**
3732
3733For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3734
3735| ID| Error Message|
3736| ------- | --------------------------------------------|
3737| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
3738
3739**Example**
3740
3741```ts
3742import { RenderNode } from '@kit.ArkUI';
3743import { drawing } from '@kit.ArkGraphics2D';
3744class TextRenderNode extends RenderNode {
3745  async draw(context: DrawContext) {
3746    const canvas = context.canvas;
3747    let font = new drawing.Font();
3748    let str = "/system/fonts/HarmonyOS_Sans_Italic.ttf";
3749    const mytypeface = drawing.Typeface.makeFromFile(str);
3750    font.setTypeface(mytypeface);
3751    const textBlob = drawing.TextBlob.makeFromString("Hello World", font, drawing.TextEncoding.TEXT_ENCODING_UTF8);
3752    canvas.drawTextBlob(textBlob, 60, 100);
3753  }
3754}
3755```
3756
3757## Font
3758
3759Describes the attributes, such as the size, used for drawing text.
3760
3761### isSubpixel<sup>12+</sup>
3762
3763isSubpixel(): boolean
3764
3765Checks whether sub-pixel rendering is used for this font.
3766
3767**System capability**: SystemCapability.Graphics.Drawing
3768
3769**Return value**
3770
3771| Type  | Description                |
3772| ------ | -------------------- |
3773| boolean | Check result. The value **true** means that sub-pixel rendering is used, and **false** means the opposite.|
3774
3775**Example**
3776
3777```ts
3778import {drawing} from '@kit.ArkGraphics2D';
3779let font: drawing.Font = new drawing.Font();
3780font.enableSubpixel(true)
3781console.info("values=" + font.isSubpixel());
3782```
3783
3784### isLinearMetrics<sup>12+</sup>
3785
3786isLinearMetrics(): boolean
3787
3788Checks whether linear scaling is used for this font.
3789
3790**System capability**: SystemCapability.Graphics.Drawing
3791
3792**Return value**
3793
3794| Type  | Description                |
3795| ------ | -------------------- |
3796| boolean | Check result. The value **true** means that linear scaling is used, and **false** means the opposite.|
3797
3798**Example**
3799
3800```ts
3801import {drawing} from '@kit.ArkGraphics2D';
3802let font: drawing.Font = new drawing.Font();
3803font.enableLinearMetrics(true)
3804console.info("values=" + font.isLinearMetrics());
3805```
3806
3807### getSkewX<sup>12+</sup>
3808
3809getSkewX(): number
3810
3811Obtains the horizontal skew factor of this font.
3812
3813**System capability**: SystemCapability.Graphics.Drawing
3814
3815**Return value**
3816
3817| Type  | Description                |
3818| ------ | -------------------- |
3819| number | Horizontal skew factor.|
3820
3821**Example**
3822
3823```ts
3824import {drawing} from '@kit.ArkGraphics2D';
3825let font: drawing.Font = new drawing.Font();
3826font.setSkewX(-1)
3827console.info("values=" + font.getSkewX());
3828```
3829
3830### isEmbolden<sup>12+</sup>
3831
3832isEmbolden(): boolean
3833
3834Checks whether the bold effect is set for this font.
3835
3836**System capability**: SystemCapability.Graphics.Drawing
3837
3838**Return value**
3839
3840| Type  | Description                |
3841| ------ | -------------------- |
3842| boolean  | Check result. The value **true** means that the bold effect is set, and **false** means the opposite.|
3843
3844**Example**
3845
3846```ts
3847import {drawing} from '@kit.ArkGraphics2D';
3848let font: drawing.Font = new drawing.Font();
3849font.enableEmbolden(true);
3850console.info("values=" + font.isEmbolden());
3851```
3852
3853### getScaleX<sup>12+</sup>
3854
3855getScaleX(): number
3856
3857Obtains the horizontal scale ratio of this font.
3858
3859**System capability**: SystemCapability.Graphics.Drawing
3860
3861**Return value**
3862
3863| Type  | Description                |
3864| ------ | -------------------- |
3865| number  | Horizontal scale ratio.|
3866
3867**Example**
3868
3869```ts
3870import {drawing} from '@kit.ArkGraphics2D';
3871let font: drawing.Font = new drawing.Font();
3872font.setScaleX(2);
3873console.info("values=" + font.getScaleX());
3874```
3875
3876### getHinting<sup>12+</sup>
3877
3878getHinting(): FontHinting
3879
3880Obtains the font hinting effect.
3881
3882**System capability**: SystemCapability.Graphics.Drawing
3883
3884**Return value**
3885
3886| Type  | Description                |
3887| ------ | -------------------- |
3888| [FontHinting](#fonthinting12)  | Font hinting effect.|
3889
3890**Example**
3891
3892```ts
3893import {drawing} from '@kit.ArkGraphics2D';
3894let font: drawing.Font = new drawing.Font();
3895console.info("values=" + font.getHinting());
3896```
3897
3898### getEdging<sup>12+</sup>
3899
3900getEdging(): FontEdging
3901
3902Obtains the font edging effect.
3903
3904**System capability**: SystemCapability.Graphics.Drawing
3905
3906**Return value**
3907
3908| Type  | Description                |
3909| ------ | -------------------- |
3910| [FontEdging](#fontedging12)  | Font edging effect.|
3911
3912**Example**
3913
3914```ts
3915import {drawing} from '@kit.ArkGraphics2D';
3916let font: drawing.Font = new drawing.Font();
3917console.info("values=" + font.getEdging());
3918```
3919
3920### enableSubpixel
3921
3922enableSubpixel(isSubpixel: boolean): void
3923
3924Enables subpixel font rendering.
3925
3926**System capability**: SystemCapability.Graphics.Drawing
3927
3928**Parameters**
3929
3930| Name    | Type   | Mandatory| Description                                                        |
3931| ---------- | ------- | ---- | ------------------------------------------------------------ |
3932| isSubpixel | boolean | Yes  | Whether to enable subpixel font rendering. The value **true** means to enable subpixel font rendering, and **false** means the opposite.|
3933
3934**Error codes**
3935
3936For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3937
3938| ID| Error Message|
3939| ------- | --------------------------------------------|
3940| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
3941
3942**Example**
3943
3944```ts
3945import { drawing } from '@kit.ArkGraphics2D';
3946let font = new drawing.Font();
3947font.enableSubpixel(true);
3948```
3949
3950### enableEmbolden
3951
3952enableEmbolden(isEmbolden: boolean): void
3953
3954Enables emboldened fonts.
3955
3956**System capability**: SystemCapability.Graphics.Drawing
3957
3958**Parameters**
3959
3960| Name    | Type   | Mandatory| Description                                                 |
3961| ---------- | ------- | ---- | ----------------------------------------------------- |
3962| isEmbolden | boolean | Yes  | Whether to enable emboldened fonts. The value **true** means to enable emboldened fonts, and **false** means the opposite.|
3963
3964**Error codes**
3965
3966For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3967
3968| ID| Error Message|
3969| ------- | --------------------------------------------|
3970| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
3971
3972**Example**
3973
3974```ts
3975import { drawing } from '@kit.ArkGraphics2D';
3976let font = new drawing.Font();
3977font.enableEmbolden(true);
3978```
3979
3980### enableLinearMetrics
3981
3982enableLinearMetrics(isLinearMetrics: boolean): void
3983
3984Enables linear font scaling.
3985
3986**System capability**: SystemCapability.Graphics.Drawing
3987
3988**Parameters**
3989
3990| Name         | Type   | Mandatory| Description                                                       |
3991| --------------- | ------- | ---- | ----------------------------------------------------------- |
3992| isLinearMetrics | boolean | Yes  | Whether to enable linear font scaling. The value **true** means to enable linear font scaling, and **false** means the opposite.|
3993
3994**Error codes**
3995
3996For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3997
3998| ID| Error Message|
3999| ------- | --------------------------------------------|
4000| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4001
4002**Example**
4003
4004```ts
4005import { drawing } from '@kit.ArkGraphics2D';
4006let font = new drawing.Font();
4007font.enableLinearMetrics(true);
4008```
4009
4010### setSize
4011
4012setSize(textSize: number): void
4013
4014Sets the text size.
4015
4016**System capability**: SystemCapability.Graphics.Drawing
4017
4018**Parameters**
4019
4020| Name  | Type  | Mandatory| Description            |
4021| -------- | ------ | ---- | ---------------- |
4022| 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.|
4023
4024**Error codes**
4025
4026For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4027
4028| ID| Error Message|
4029| ------- | --------------------------------------------|
4030| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
4031
4032**Example**
4033
4034```ts
4035import { drawing } from '@kit.ArkGraphics2D';
4036let font = new drawing.Font();
4037font.setSize(5);
4038```
4039
4040### getSize
4041
4042getSize(): number
4043
4044Obtains the text size.
4045
4046**System capability**: SystemCapability.Graphics.Drawing
4047
4048**Return value**
4049
4050| Type  | Description            |
4051| ------ | ---------------- |
4052| number | Text size. The value is a floating point number.|
4053
4054**Example**
4055
4056```ts
4057import { drawing } from '@kit.ArkGraphics2D';
4058let font = new drawing.Font();
4059font.setSize(5);
4060let fontSize = font.getSize();
4061```
4062
4063### setTypeface
4064
4065setTypeface(typeface: Typeface): void
4066
4067Sets the typeface.
4068
4069**System capability**: SystemCapability.Graphics.Drawing
4070
4071**Parameters**
4072
4073| Name  | Type                 | Mandatory| Description  |
4074| -------- | --------------------- | ---- | ------ |
4075| typeface | [Typeface](#typeface) | Yes  | **Typeface** object.|
4076
4077**Error codes**
4078
4079For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4080
4081| ID| Error Message|
4082| ------- | --------------------------------------------|
4083| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4084
4085**Example**
4086
4087```ts
4088import { drawing } from '@kit.ArkGraphics2D';
4089let font = new drawing.Font();
4090font.setTypeface(new drawing.Typeface());
4091```
4092
4093### getTypeface
4094
4095getTypeface(): Typeface
4096
4097Obtains the typeface.
4098
4099**System capability**: SystemCapability.Graphics.Drawing
4100
4101**Return value**
4102
4103| Type                 | Description  |
4104| --------------------- | ------ |
4105| [Typeface](#typeface) | **Typeface** object.|
4106
4107**Example**
4108
4109```ts
4110import { drawing } from '@kit.ArkGraphics2D';
4111let font = new drawing.Font();
4112let typeface = font.getTypeface();
4113```
4114
4115### getMetrics
4116
4117getMetrics(): FontMetrics
4118
4119Obtains the font metrics of the typeface.
4120
4121**System capability**: SystemCapability.Graphics.Drawing
4122
4123**Return value**
4124
4125| Type                       | Description             |
4126| --------------------------- | ----------------- |
4127| [FontMetrics](#fontmetrics) | Font metrics.|
4128
4129**Example**
4130
4131```ts
4132import { drawing } from '@kit.ArkGraphics2D';
4133let font = new drawing.Font();
4134let metrics = font.getMetrics();
4135```
4136
4137### measureText
4138
4139measureText(text: string, encoding: TextEncoding): number
4140
4141Measures the text width.
4142
4143> **NOTE**
4144>
4145> 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).
4146
4147**System capability**: SystemCapability.Graphics.Drawing
4148
4149**Parameters**
4150
4151| Name  | Type                         | Mandatory| Description      |
4152| -------- | ----------------------------- | ---- | ---------- |
4153| text     | string                        | Yes  | Text content.|
4154| encoding | [TextEncoding](#textencoding) | Yes  | Encoding format.|
4155
4156**Return value**
4157
4158| Type  | Description            |
4159| ------ | ---------------- |
4160| number | Width of the text. The value is a floating point number.|
4161
4162**Error codes**
4163
4164For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4165
4166| ID| Error Message|
4167| ------- | --------------------------------------------|
4168| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4169
4170**Example**
4171
4172```ts
4173import { drawing } from '@kit.ArkGraphics2D';
4174let font = new drawing.Font();
4175font.measureText("drawing", drawing.TextEncoding.TEXT_ENCODING_UTF8);
4176```
4177
4178### measureSingleCharacter<sup>12+</sup>
4179
4180measureSingleCharacter(text: string): number
4181
4182Measures 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.
4183
4184**System capability**: SystemCapability.Graphics.Drawing
4185
4186**Parameters**
4187
4188| Name| Type               | Mandatory| Description       |
4189| ------ | ------------------- | ---- | ----------- |
4190| text   | string | Yes  | Single character to measure. The length of the string must be 1. |
4191
4192**Return value**
4193
4194| Type  | Description            |
4195| ------ | ---------------- |
4196| number | Width of the character. The value is a floating point number.|
4197
4198**Error codes**
4199
4200For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4201
4202| ID| Error Message|
4203| ------- | --------------------------------------------|
4204| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
4205
4206**Example**
4207
4208```ts
4209import { RenderNode } from '@kit.ArkUI';
4210import { drawing } from '@kit.ArkGraphics2D';
4211
4212class DrawingRenderNode extends RenderNode {
4213  draw(context : DrawContext) {
4214    const canvas = context.canvas;
4215    const font = new drawing.Font();
4216    font.setSize(20);
4217    let width = font.measureSingleCharacter ("Hello");
4218  }
4219}
4220```
4221
4222### setScaleX<sup>12+</sup>
4223
4224setScaleX(scaleX: number): void
4225
4226Sets a horizontal scale factor for this font.
4227
4228**System capability**: SystemCapability.Graphics.Drawing
4229
4230**Parameters**
4231
4232| Name  | Type                         | Mandatory| Description      |
4233| -------- | ----------------------------- | ---- | ---------- |
4234| scaleX     | number                      | Yes  | Horizontal scale factor. The value is a floating point number.|
4235
4236**Error codes**
4237
4238For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4239
4240| ID| Error Message|
4241| ------- | --------------------------------------------|
4242| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4243
4244**Example**
4245
4246```ts
4247import { RenderNode } from '@kit.ArkUI';
4248import { common2D, drawing } from '@kit.ArkGraphics2D';
4249class DrawingRenderNode extends RenderNode {
4250  draw(context : DrawContext) {
4251    const canvas = context.canvas;
4252    const pen = new drawing.Pen();
4253    pen.setStrokeWidth(5);
4254    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
4255    canvas.attachPen(pen);
4256    let font = new drawing.Font();
4257    font.setSize(100);
4258    font.setScaleX(2);
4259    const textBlob = drawing.TextBlob.makeFromString("hello", font, drawing.TextEncoding.TEXT_ENCODING_UTF8);
4260    canvas.drawTextBlob(textBlob, 200, 200);
4261  }
4262}
4263```
4264
4265### setSkewX<sup>12+</sup>
4266
4267setSkewX(skewX: number): void
4268
4269Sets a horizontal skew factor for this font.
4270
4271**System capability**: SystemCapability.Graphics.Drawing
4272
4273**Parameters**
4274
4275| Name  | Type                         | Mandatory| Description      |
4276| -------- | ----------------------------- | ---- | ---------- |
4277| 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.|
4278
4279**Error codes**
4280
4281For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4282
4283| ID| Error Message|
4284| ------- | --------------------------------------------|
4285| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4286
4287**Example**
4288
4289```ts
4290import { RenderNode } from '@kit.ArkUI';
4291import { common2D, drawing } from '@kit.ArkGraphics2D';
4292class DrawingRenderNode extends RenderNode {
4293  draw(context : DrawContext) {
4294    const canvas = context.canvas;
4295    const pen = new drawing.Pen();
4296    pen.setStrokeWidth(5);
4297    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
4298    canvas.attachPen(pen);
4299    let font = new drawing.Font();
4300    font.setSize(100);
4301    font.setSkewX(1);
4302    const textBlob = drawing.TextBlob.makeFromString("hello", font, drawing.TextEncoding.TEXT_ENCODING_UTF8);
4303    canvas.drawTextBlob(textBlob, 200, 200);
4304  }
4305}
4306```
4307
4308### setEdging<sup>12+</sup>
4309
4310setEdging(edging: FontEdging): void
4311
4312Sets a font edging effect.
4313
4314**System capability**: SystemCapability.Graphics.Drawing
4315
4316**Parameters**
4317
4318| Name  | Type                         | Mandatory| Description      |
4319| -------- | ----------------------------- | ---- | ---------- |
4320| edging | [FontEdging](#fontedging12) | Yes  | Font edging effect.|
4321
4322**Error codes**
4323
4324For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4325
4326| ID| Error Message|
4327| ------- | --------------------------------------------|
4328| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
4329
4330**Example**
4331
4332```ts
4333import { drawing } from '@kit.ArkGraphics2D';
4334
4335let font = new drawing.Font();
4336font.setEdging(drawing.FontEdging.SUBPIXEL_ANTI_ALIAS);
4337```
4338
4339### setHinting<sup>12+</sup>
4340
4341setHinting(hinting: FontHinting): void
4342
4343Sets a font hinting effect.
4344
4345**System capability**: SystemCapability.Graphics.Drawing
4346
4347**Parameters**
4348
4349| Name  | Type                         | Mandatory| Description      |
4350| -------- | ----------------------------- | ---- | ---------- |
4351| hinting | [FontHinting](#fonthinting12) | Yes  | Font hinting effect.|
4352
4353**Error codes**
4354
4355For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4356
4357| ID| Error Message|
4358| ------- | --------------------------------------------|
4359| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
4360
4361**Example**
4362
4363```ts
4364import { drawing } from '@kit.ArkGraphics2D';
4365
4366let font = new drawing.Font();
4367font.setHinting(drawing.FontHinting.FULL);
4368```
4369
4370### countText<sup>12+</sup>
4371
4372countText(text: string): number
4373
4374Obtains the number of glyphs represented by text.
4375
4376**System capability**: SystemCapability.Graphics.Drawing
4377
4378**Parameters**
4379
4380| Name  | Type                         | Mandatory| Description      |
4381| -------- | ----------------------------- | ---- | ---------- |
4382| text     | string                        | Yes  | Text content.|
4383
4384**Return value**
4385
4386| Type  | Description            |
4387| ------ | ---------------- |
4388| number | Number of glyphs represented by the text. The value is an integer.|
4389
4390**Error codes**
4391
4392For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4393
4394| ID| Error Message|
4395| ------- | --------------------------------------------|
4396| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4397
4398**Example**
4399
4400```ts
4401import { drawing } from '@kit.ArkGraphics2D';
4402
4403let font = new drawing.Font();
4404let resultNumber: number = font.countText('ABCDE');
4405console.info("count text number: " + resultNumber);
4406```
4407
4408### setBaselineSnap<sup>12+</sup>
4409
4410setBaselineSnap(isBaselineSnap: boolean): void
4411
4412Sets whether to request that baselines be snapped to pixels when the current canvas matrix is axis aligned.
4413
4414**System capability**: SystemCapability.Graphics.Drawing
4415
4416**Parameters**
4417
4418| Name         | Type   | Mandatory| Description                                      |
4419| --------------- | ------- | ---- | ---------------------------------------- |
4420| 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.|
4421
4422**Error codes**
4423
4424For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4425
4426| ID| Error Message|
4427| ------- | --------------------------------------------|
4428| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4429
4430**Example**
4431
4432```ts
4433import { drawing } from '@kit.ArkGraphics2D';
4434
4435let font : drawing.Font = new drawing.Font();
4436font.setBaselineSnap(true);
4437console.info("drawing font isBaselineSnap: " + font.isBaselineSnap());
4438```
4439
4440### isBaselineSnap()<sup>12+</sup>
4441
4442isBaselineSnap(): boolean
4443
4444Checks whether baselines are requested to be snapped to pixels when the current canvas matrix is axis aligned.
4445
4446**System capability**: SystemCapability.Graphics.Drawing
4447
4448**Return value**
4449
4450| Type  | Description            |
4451| ------ | ---------------- |
4452| 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.|
4453
4454**Example**
4455
4456```ts
4457import { drawing } from '@kit.ArkGraphics2D';
4458
4459let font : drawing.Font = new drawing.Font();
4460font.setTypeface(new drawing.Typeface());
4461font.setBaselineSnap(true);
4462console.info("drawing font isBaselineSnap: " + font.isBaselineSnap());
4463```
4464
4465### setEmbeddedBitmaps<sup>12+</sup>
4466
4467setEmbeddedBitmaps(isEmbeddedBitmaps: boolean): void
4468
4469Sets whether to use bitmaps in this font.
4470
4471**System capability**: SystemCapability.Graphics.Drawing
4472
4473**Parameters**
4474
4475| Name  | Type  | Mandatory| Description            |
4476| -------- | ------ | ---- | ---------------- |
4477| 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.|
4478
4479**Error codes**
4480
4481For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4482
4483| ID| Error Message|
4484| ------- | --------------------------------------------|
4485| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4486
4487**Example**
4488
4489```ts
4490import { drawing } from '@kit.ArkGraphics2D';
4491
4492let font : drawing.Font = new drawing.Font();
4493font.setTypeface(new drawing.Typeface());
4494font.setEmbeddedBitmaps(false);
4495console.info("draw isEmbeddedBitmaps: " + font.isEmbeddedBitmaps());
4496```
4497
4498### isEmbeddedBitmaps()<sup>12+</sup>
4499
4500isEmbeddedBitmaps(): boolean
4501
4502Checks whether bitmaps are used in this font.
4503
4504**System capability**: SystemCapability.Graphics.Drawing
4505
4506**Return value**
4507
4508| Type  | Description            |
4509| ------ | ---------------- |
4510| 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.|
4511
4512**Example**
4513
4514```ts
4515import { drawing } from '@kit.ArkGraphics2D';
4516
4517let font : drawing.Font = new drawing.Font();
4518font.setTypeface(new drawing.Typeface());
4519font.setEmbeddedBitmaps(true);
4520console.info("draw isEmbeddedBitmaps: " + font.isEmbeddedBitmaps());
4521```
4522
4523### setForceAutoHinting<sup>12+</sup>
4524
4525setForceAutoHinting(isForceAutoHinting: boolean): void
4526
4527Sets whether to forcibly use auto hinting, that is, whether to always hint glyphs.
4528
4529**System capability**: SystemCapability.Graphics.Drawing
4530
4531**Parameters**
4532
4533| Name  | Type  | Mandatory| Description            |
4534| -------- | ------ | ---- | ---------------- |
4535| isForceAutoHinting | boolean | Yes  | Whether to forcibly use auto hinting. The value **true** means to forcibly use auto hinting, and **false** means the opposite.|
4536
4537**Error codes**
4538
4539For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4540
4541| ID| Error Message|
4542| ------- | --------------------------------------------|
4543| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4544
4545**Example**
4546
4547```ts
4548import { drawing } from '@kit.ArkGraphics2D';
4549
4550let font : drawing.Font = new drawing.Font();
4551font.setTypeface(new drawing.Typeface());
4552font.setForceAutoHinting(false);
4553console.info("drawing isForceAutoHinting:  " + font.isForceAutoHinting());
4554```
4555
4556### isForceAutoHinting<sup>12+</sup>
4557
4558isForceAutoHinting(): boolean
4559
4560Checks whether auto hinting is forcibly used.
4561
4562**System capability**: SystemCapability.Graphics.Drawing
4563
4564**Return value**
4565
4566| Type  | Description            |
4567| ------ | ---------------- |
4568| boolean | Result indicating whether auto hinting is forcibly used. The value **true** means that auto hinting is forcibly used, and **false** means the opposite.|
4569
4570**Example**
4571
4572```ts
4573import { drawing } from '@kit.ArkGraphics2D';
4574
4575let font : drawing.Font = new drawing.Font();
4576font.setTypeface(new drawing.Typeface());
4577font.setForceAutoHinting(false);
4578console.info("drawing isForceAutoHinting:  " + font.isForceAutoHinting());
4579```
4580
4581### getWidths<sup>12+</sup>
4582
4583getWidths(glyphs: Array\<number>): Array\<number>
4584
4585Obtains the width of each glyph in an array.
4586
4587**System capability**: SystemCapability.Graphics.Drawing
4588
4589**Parameters**
4590
4591| Name  | Type                 | Mandatory| Description  |
4592| -------- | --------------------- | ---- | ------ |
4593| glyphs | Array\<number> | Yes  | Glyph array, which can be generated by [textToGlyphs](#texttoglyphs12).|
4594
4595**Return value**
4596
4597| Type  | Description            |
4598| ------ | ---------------- |
4599| Array\<number> | Array that holds the obtained glyph widths.|
4600
4601**Error codes**
4602
4603For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4604
4605| ID| Error Message|
4606| ------- | --------------------------------------------|
4607| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4608
4609**Example**
4610
4611```ts
4612import { drawing } from '@kit.ArkGraphics2D';
4613
4614let font: drawing.Font = new drawing.Font();
4615let text: string = 'hello world';
4616let glyphs: number[] = font.textToGlyphs(text);
4617let fontWidths: Array<number> = font.getWidths(glyphs);
4618for (let index = 0; index < fontWidths.length; index++) {
4619  console.info("get fontWidths[", index, "]:", fontWidths[index]);
4620}
4621```
4622
4623### textToGlyphs<sup>12+</sup>
4624
4625textToGlyphs(text: string, glyphCount?: number): Array\<number>
4626
4627Converts text into glyph indexes.
4628
4629**System capability**: SystemCapability.Graphics.Drawing
4630
4631**Parameters**
4632
4633| Name  | Type                         | Mandatory| Description      |
4634| -------- | ----------------------------- | ---- | ---------- |
4635| text     | string                        | Yes  | Text string.|
4636| 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.|
4637
4638**Return value**
4639
4640| Type  | Description            |
4641| ------ | ---------------- |
4642| Array\<number> | Array that holds the glyph indexes.|
4643
4644**Error codes**
4645
4646For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4647
4648| ID| Error Message|
4649| ------- | --------------------------------------------|
4650| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4651
4652**Example**
4653
4654```ts
4655import { drawing } from '@kit.ArkGraphics2D';
4656
4657let font : drawing.Font = new drawing.Font();
4658let text : string = 'hello world';
4659let glyphs : number[] = font.textToGlyphs(text);
4660console.info("drawing text toglyphs OnTestFunction num =  " + glyphs.length );
4661```
4662
4663## FontMetricsFlags<sup>12+</sup>
4664
4665Enumerates the font measurement flags, which is used to specify whether a field in the font measurement information is valid.
4666
4667**System capability**: SystemCapability.Graphics.Drawing
4668
4669| Name                         | Value       | Description                          |
4670| ----------------------------- | --------- | ------------------------------ |
4671| UNDERLINE_THICKNESS_VALID     | 1 << 0    | The **underlineThickness** field in the [FontMetrics](#fontmetrics) struct is valid.   |
4672| UNDERLINE_POSITION_VALID      | 1 << 1    | The **underlinePosition** field in the [FontMetrics](#fontmetrics) struct is valid. |
4673| STRIKETHROUGH_THICKNESS_VALID | 1 << 2    | The **strikethroughThickness** field in the [FontMetrics](#fontmetrics) struct is valid.|
4674| STRIKETHROUGH_POSITION_VALID  | 1 << 3    | The **strikethroughPosition** field in the [FontMetrics](#fontmetrics) struct is valid. |
4675| BOUNDS_INVALID                | 1 << 4    | The boundary metrics (such as **top**, **bottom**, **xMin**, and **xMax**) in the [FontMetrics](#fontmetrics) struct are invalid. |
4676
4677## FontMetrics
4678
4679Describes the attributes that describe the font size and layout. A typeface has similar font metrics.
4680
4681**System capability**: SystemCapability.Graphics.Drawing
4682
4683| Name   | Type  | Read Only| Optional| Description                                                        |
4684| ------- | ------ | ---- | ---- | ------------------------------------------------------------ |
4685| flags<sup>12+</sup>   | [FontMetricsFlags](#fontmetricsflags12) | Yes  | Yes  | Font measurement flags that are valid.       |
4686| top     | number | Yes  | No  | Maximum distance from the baseline to the highest coordinate of the text. The value is a floating point number.                        |
4687| ascent  | number | Yes  | No  | Distance from the baseline to the highest coordinate of the text. The value is a floating point number.                            |
4688| descent | number | Yes  | No  | Distance from the baseline to the lowest coordinate of the text. The value is a floating point number.                            |
4689| bottom  | number | Yes  | No  | Maximum distance from the baseline to the lowest coordinate of the text. The value is a floating point number.                        |
4690| 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.|
4691| avgCharWidth<sup>12+</sup> | number | Yes  | Yes  | Average character width.                            |
4692| maxCharWidth<sup>12+</sup> | number | Yes  | Yes  | Maximum character width.                            |
4693| 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.               |
4694| 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.       |
4695| xHeight<sup>12+</sup> | number | Yes  | Yes  | Height of the lowercase letter x. The value is usually a negative value.                    |
4696| capHeight<sup>12+</sup> | number | Yes  | Yes  | Height of a capital letter. The value is usually a negative value.                     |
4697| underlineThickness<sup>12+</sup> | number | Yes  | Yes  | Thickness of the underline.                                         |
4698| 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.            |
4699| strikethroughThickness<sup>12+</sup>  | number | Yes  | Yes  | Thickness of the strikethrough.   |
4700| 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.        |
4701
4702## ColorFilter
4703
4704Defines a color filter.
4705
4706### createBlendModeColorFilter
4707
4708createBlendModeColorFilter(color: common2D.Color, mode: BlendMode) : ColorFilter
4709
4710Creates a **ColorFilter** object with a given color and blend mode.
4711
4712**System capability**: SystemCapability.Graphics.Drawing
4713
4714**Parameters**
4715
4716| Name| Type                                                | Mandatory| Description            |
4717| ------ | ---------------------------------------------------- | ---- | ---------------- |
4718| 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.|
4719| mode   | [BlendMode](#blendmode)                              | Yes  | Blend mode.|
4720
4721**Return value**
4722
4723| Type                       | Description              |
4724| --------------------------- | ------------------ |
4725| [ColorFilter](#colorfilter) | **ColorFilter** object created.|
4726
4727**Error codes**
4728
4729For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4730
4731| ID| Error Message|
4732| ------- | --------------------------------------------|
4733| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
4734
4735**Example**
4736
4737```ts
4738import { common2D, drawing } from '@kit.ArkGraphics2D';
4739const color : common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
4740let colorFilter = drawing.ColorFilter.createBlendModeColorFilter(color, drawing.BlendMode.SRC);
4741```
4742
4743### createComposeColorFilter
4744
4745createComposeColorFilter(outer: ColorFilter, inner: ColorFilter) : ColorFilter
4746
4747Creates a **ColorFilter** object by combining another two color filters.
4748
4749**System capability**: SystemCapability.Graphics.Drawing
4750
4751**Parameters**
4752
4753| Name| Type                       | Mandatory| Description                            |
4754| ------ | --------------------------- | ---- | -------------------------------- |
4755| outer  | [ColorFilter](#colorfilter) | Yes  | Color filter that takes effect later in the new filter.|
4756| inner  | [ColorFilter](#colorfilter) | Yes  | Color filter that takes effect first in the new filter.|
4757
4758**Return value**
4759
4760| Type                       | Description              |
4761| --------------------------- | ------------------ |
4762| [ColorFilter](#colorfilter) | **ColorFilter** object created.|
4763
4764**Error codes**
4765
4766For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4767
4768| ID| Error Message|
4769| ------- | --------------------------------------------|
4770| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4771
4772**Example**
4773
4774```ts
4775import { common2D, drawing } from '@kit.ArkGraphics2D';
4776const color : common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
4777let colorFilter1 = drawing.ColorFilter.createBlendModeColorFilter(color, drawing.BlendMode.SRC);
4778let colorFilter2 = drawing.ColorFilter.createBlendModeColorFilter(color, drawing.BlendMode.DST);
4779let colorFilter = drawing.ColorFilter.createComposeColorFilter(colorFilter1, colorFilter2);
4780```
4781
4782### createLinearToSRGBGamma
4783
4784createLinearToSRGBGamma() : ColorFilter
4785
4786Creates a **ColorFilter** object that applies the sRGB gamma curve to the RGB channels.
4787
4788**System capability**: SystemCapability.Graphics.Drawing
4789
4790**Return value**
4791
4792| Type                       | Description              |
4793| --------------------------- | ------------------ |
4794| [ColorFilter](#colorfilter) | **ColorFilter** object created.|
4795
4796**Example**
4797
4798```ts
4799import { drawing } from '@kit.ArkGraphics2D';
4800let colorFilter = drawing.ColorFilter.createLinearToSRGBGamma();
4801```
4802
4803### createSRGBGammaToLinear
4804
4805createSRGBGammaToLinear() : ColorFilter
4806
4807Creates a **ColorFilter** object that applies the RGB channels to the sRGB gamma curve.
4808
4809**System capability**: SystemCapability.Graphics.Drawing
4810
4811**Return value**
4812
4813| Type                       | Description              |
4814| --------------------------- | ------------------ |
4815| [ColorFilter](#colorfilter) | **ColorFilter** object created.|
4816
4817**Example**
4818
4819```ts
4820import { drawing } from '@kit.ArkGraphics2D';
4821let colorFilter = drawing.ColorFilter.createSRGBGammaToLinear();
4822```
4823
4824### createLumaColorFilter
4825
4826createLumaColorFilter() : ColorFilter
4827
4828Creates a **ColorFilter** object that multiplies the luma into the alpha channel.
4829
4830**System capability**: SystemCapability.Graphics.Drawing
4831
4832**Return value**
4833
4834| Type                       | Description              |
4835| --------------------------- | ------------------ |
4836| [ColorFilter](#colorfilter) | **ColorFilter** object created.|
4837
4838**Example**
4839
4840```ts
4841import { drawing } from '@kit.ArkGraphics2D';
4842let colorFilter = drawing.ColorFilter.createLumaColorFilter();
4843```
4844
4845### createMatrixColorFilter<sup>12+</sup>
4846
4847static createMatrixColorFilter(matrix: Array\<number>): ColorFilter
4848
4849Creates a color filter object with a 4*5 color matrix.
4850
4851**System capability**: SystemCapability.Graphics.Drawing
4852
4853**Parameters**
4854
4855| Name  | Type                                        | Mandatory| Description                           |
4856| -------- | -------------------------------------------- | ---- | ------------------------------- |
4857| matrix | Array\<number> | Yes  | An array of 20 numbers, indicating the 4*5 matrix.                |
4858
4859**Return value**
4860
4861| Type                       | Description              |
4862| --------------------------- | ------------------ |
4863| [ColorFilter](#colorfilter) | Color filter created.|
4864
4865**Error codes**
4866
4867For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4868
4869| ID| Error Message|
4870| ------- | --------------------------------------------|
4871| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
4872
4873**Example**
4874
4875```ts
4876import { drawing } from '@kit.ArkGraphics2D';
4877let matrix: Array<number> = [
4878  1, 0, 0, 0, 0,
4879  0, 1, 0, 0, 0,
4880  0, 0, 100, 0, 0,
4881  0, 0, 0, 1, 0
4882];
4883let colorFilter = drawing.ColorFilter.createMatrixColorFilter(matrix);
4884```
4885
4886## JoinStyle<sup>12+</sup>
4887
4888Enumerates the join styles of a pen. The join style defines the shape of the joints of a polyline segment drawn by the pen.
4889
4890**System capability**: SystemCapability.Graphics.Drawing
4891
4892| Name       | Value  | Description                                                        | Diagram  |
4893| ----------- | ---- | ----------------------------------------------------------- | -------- |
4894| 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) |
4895| ROUND_JOIN | 1    | Round corner.| ![ROUND_JOIN](./figures/image_JoinStyle_Round_Join.png) |
4896| BEVEL_JOIN | 2    | Beveled corner.| ![BEVEL_JOIN](./figures/image_JoinStyle_Bevel_Join.png) |
4897
4898## CapStyle<sup>12+</sup>
4899
4900Enumerates the cap styles of a pen. The cap style defines the style of both ends of a line segment drawn by the pen.
4901
4902**System capability**: SystemCapability.Graphics.Drawing
4903
4904| Name       | Value  | Description                                                        | Diagram  |
4905| ---------- | ---- | ----------------------------------------------------------- | -------- |
4906| 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) |
4907| 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) |
4908| 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) |
4909
4910## BlurType<sup>12+</sup>
4911
4912Enumerates the blur types of a mask filter.
4913
4914**System capability**: SystemCapability.Graphics.Drawing
4915
4916| Name  | Value| Description              | Diagram  |
4917| ------ | - | ------------------ | -------- |
4918| NORMAL | 0 | Blurs both inside and outside the original border.         | ![NORMAL](./figures/image_BlueType_Normal.png) |
4919| SOLID  | 1 | Draws solid inside the border, and blurs outside.| ![SOLID](./figures/image_BlueType_Solid.png) |
4920| OUTER  | 2 | Draws nothing inside the border, and blurs outside.| ![OUTER](./figures/image_BlueType_Outer.png) |
4921| INNER  | 3 | Blurs inside the border, and draws nothing outside.| ![INNER](./figures/image_BlueType_Inner.png) |
4922
4923## SamplingOptions<sup>12+</sup>
4924
4925Implements sampling options.
4926
4927### constructor<sup>12+</sup>
4928
4929constructor()
4930
4931Creates a **SamplingOptions** object.
4932
4933**System capability**: SystemCapability.Graphics.Drawing
4934
4935**Example**
4936
4937```ts
4938import { RenderNode } from '@kit.ArkUI';
4939import { common2D, drawing } from '@kit.ArkGraphics2D';
4940class DrawingRenderNode extends RenderNode {
4941  draw(context : DrawContext) {
4942    const canvas = context.canvas;
4943    const pen = new drawing.Pen();
4944    let samplingOptions = new drawing.SamplingOptions();
4945  }
4946}
4947```
4948
4949### constructor<sup>12+</sup>
4950
4951constructor(filterMode: FilterMode)
4952
4953Creates a **SamplingOptions** object.
4954
4955**System capability**: SystemCapability.Graphics.Drawing
4956
4957**Parameters**
4958
4959| Name    | Type                  | Mandatory| Description                                |
4960| ---------- | --------------------- | ---- | ----------------------------------- |
4961| filterMode | [FilterMode](#filtermode12)    | Yes  | Filter mode.                   |
4962
4963**Error codes**
4964
4965For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4966
4967| ID| Error Message|
4968| ------- | --------------------------------------------|
4969| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
4970
4971**Example**
4972
4973```ts
4974import { RenderNode } from '@kit.ArkUI';
4975import { common2D, drawing } from '@kit.ArkGraphics2D';
4976class DrawingRenderNode extends RenderNode {
4977  draw(context : DrawContext) {
4978    const canvas = context.canvas;
4979    let samplingOptions = new drawing.SamplingOptions(drawing.FilterMode.FILTER_MODE_NEAREST);
4980  }
4981}
4982```
4983
4984## Lattice<sup>12+</sup>
4985
4986Implements a lattice object, which is used to divide an image by lattice.
4987
4988### createImageLattice<sup>12+</sup>
4989
4990static 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
4991
4992Divides 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.
4993
4994**System capability**: SystemCapability.Graphics.Drawing
4995
4996**Parameters**
4997
4998| Name      | Type                                                               | Mandatory| Description                                                                              |
4999| ------------ | ------------------------------------------------------------------ | ---- | --------------------------------------------------------------------------------- |
5000| xDivs        | Array\<number>                                                     | Yes  | Array of X coordinates used to divide the image. The value is an integer.                                            |
5001| yDivs        | Array\<number>                                                     | Yes  | Array of Y coordinates used to divide the image. The value is an integer.                                            |
5002| fXCount      | number                                                             | Yes  | Size of the array that holds the X coordinates. The value range is [0, 5].                           |
5003| fYCount      | number                                                             | Yes  | Size of the array that holds the Y coordinates. The value range is [0, 5].                           |
5004| 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.|
5005| 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).|
5006| 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).|
5007
5008**Return value**
5009
5010| Type                      | Description                               |
5011| ------------------------- | ----------------------------------- |
5012| [Lattice](#lattice12)     | **Lattice** object obtained.             |
5013
5014**Error codes**
5015
5016For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5017
5018| ID| Error Message|
5019| ------- | --------------------------------------------|
5020| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
5021
5022**Example**
5023
5024```ts
5025import { RenderNode } from '@kit.ArkUI';
5026import { drawing } from '@kit.ArkGraphics2D';
5027class DrawingRenderNode extends RenderNode {
5028  draw(context : DrawContext) {
5029    let xDivs : Array<number> = [1, 2, 4];
5030    let yDivs : Array<number> = [1, 2, 4];
5031    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.
5032  }
5033}
5034```
5035![Lattice.png](figures/Lattice.png)
5036
5037### createImageLattice<sup>13+</sup>
5038
5039static createImageLattice(xDivs: Array\<number>, yDivs: Array\<number>, fXCount: number, fYCount: number, fBounds?: common2D.Rect | null, fRectTypes?: Array\<RectType> | null, fColors?: Array\<number> | null): Lattice
5040
5041Divides 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.
5042
5043**System capability**: SystemCapability.Graphics.Drawing
5044
5045**Parameters**
5046
5047| Name      | Type                                                               | Mandatory| Description                                                                              |
5048| ------------ | ------------------------------------------------------------------ | ---- | --------------------------------------------------------------------------------- |
5049| xDivs        | Array\<number>                                                     | Yes  | Array of X coordinates used to divide the image. The value is an integer.                                            |
5050| yDivs        | Array\<number>                                                     | Yes  | Array of Y coordinates used to divide the image. The value is an integer.                                            |
5051| fXCount      | number                                                             | Yes  | Size of the array that holds the X coordinates. The value range is [0, 5].                           |
5052| fYCount      | number                                                             | Yes  | Size of the array that holds the Y coordinates. The value range is [0, 5].                           |
5053| 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.|
5054| 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).|
5055| 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).|
5056
5057**Return value**
5058
5059| Type                      | Description                               |
5060| ------------------------- | ----------------------------------- |
5061| [Lattice](#lattice12)     | **Lattice** object obtained.             |
5062
5063**Error codes**
5064
5065For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5066
5067| ID| Error Message|
5068| ------- | --------------------------------------------|
5069| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
5070
5071**Example**
5072
5073```ts
5074import { RenderNode } from '@kit.ArkUI';
5075import { drawing } from '@kit.ArkGraphics2D';
5076class DrawingRenderNode extends RenderNode {
5077  draw(context : DrawContext) {
5078    let xDivs : Array<number> = [1, 2, 4];
5079    let yDivs : Array<number> = [1, 2, 4];
5080    let colorArray :Array<number>=[0xffffff,0x444444,0x999999,0xffffff,0x444444,0x999999,0xffffff,0x444444,0x999999,0x444444,0x999999,0xffffff,0x444444,0x999999,0xffffff,0x444444];
5081    let lattice = drawing.Lattice.createImageLattice(xDivs, yDivs, 3, 3,null,null,colorArray);
5082  }
5083}
5084```
5085
5086## RectType<sup>12+</sup>
5087
5088Enumerates the types of rectangles used to fill the lattices. This enum is used only in [Lattice](#lattice12).
5089
5090**System capability**: SystemCapability.Graphics.Drawing
5091
5092| Name        | Value  | Description                                                            |
5093| ------------ | ---- | --------------------------------------------------------------- |
5094| DEFAULT      | 0    | Draws an image into the lattice.                                         |
5095| TRANSPARENT  | 1    | Sets the lattice to transparent.                                         |
5096| FIXEDCOLOR   | 2    | Draws the colors in the **fColors** array in [Lattice](#lattice12) into the lattice.      |
5097
5098## MaskFilter<sup>12+</sup>
5099
5100Implements a mask filter.
5101
5102### createBlurMaskFilter<sup>12+</sup>
5103
5104static createBlurMaskFilter(blurType: BlurType, sigma: number): MaskFilter
5105
5106Creates a mask filter with a blur effect.
5107
5108**System capability**: SystemCapability.Graphics.Drawing
5109
5110**Parameters**
5111
5112| Name    | Type                  | Mandatory| Description                                |
5113| ---------- | --------------------- | ---- | ----------------------------------- |
5114| blurType   | [BlurType](#blurtype12) | Yes  | Blur type.                          |
5115| sigma      | number                | Yes  | Standard deviation of the Gaussian blur to apply. The value must be a floating point number greater than 0.|
5116
5117**Return value**
5118
5119| Type                     | Description               |
5120| ------------------------- | ------------------ |
5121| [MaskFilter](#maskfilter12) | **MaskFilter** object created.|
5122
5123**Error codes**
5124
5125For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5126
5127| ID| Error Message|
5128| ------- | --------------------------------------------|
5129| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
5130
5131**Example**
5132
5133```ts
5134import { RenderNode } from '@kit.ArkUI';
5135import { common2D, drawing } from '@kit.ArkGraphics2D';
5136class DrawingRenderNode extends RenderNode {
5137  draw(context : DrawContext) {
5138    const canvas = context.canvas;
5139    let maskFilter = drawing.MaskFilter.createBlurMaskFilter(drawing.BlurType.OUTER, 10);
5140  }
5141}
5142```
5143
5144## PathEffect<sup>12+</sup>
5145
5146Implements a path effect.
5147
5148### createDashPathEffect<sup>12+</sup>
5149
5150static createDashPathEffect(intervals:  Array\<number>, phase: number): PathEffect
5151
5152Creates a **PathEffect** object that converts a path into a dotted line.
5153
5154**System capability**: SystemCapability.Graphics.Drawing
5155
5156**Parameters**
5157
5158| Name    | Type          | Mandatory   | Description                                              |
5159| ---------- | ------------- | ------- | -------------------------------------------------- |
5160| 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.|
5161| phase      | number         | Yes     | Offset used during drawing. The value is a floating point number.                                    |
5162
5163**Return value**
5164
5165| Type                     | Description                  |
5166| ------------------------- | --------------------- |
5167| [PathEffect](#patheffect12) | **PathEffect** object created.|
5168
5169**Error codes**
5170
5171For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5172
5173| ID| Error Message|
5174| ------- | --------------------------------------------|
5175| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
5176
5177**Example**
5178
5179```ts
5180import { RenderNode } from '@kit.ArkUI';
5181import { common2D, drawing } from '@kit.ArkGraphics2D';
5182class DrawingRenderNode extends RenderNode {
5183  draw(context : DrawContext) {
5184    const canvas = context.canvas;
5185    let intervals = [10, 5];
5186    let effect = drawing.PathEffect.createDashPathEffect(intervals, 5);
5187  }
5188}
5189```
5190
5191### createCornerPathEffect<sup>12+</sup>
5192
5193static createCornerPathEffect(radius: number): PathEffect
5194
5195Creates a path effect that transforms the sharp angle between line segments into a rounded corner with the specified radius.
5196
5197**System capability**: SystemCapability.Graphics.Drawing
5198
5199**Parameters**
5200
5201| Name    | Type          | Mandatory   | Description                                              |
5202| ---------- | ------------- | ------- | -------------------------------------------------- |
5203| radius     | number        | Yes     | Radius of the rounded corner. The value must be greater than 0. The value is a floating point number.               |
5204
5205**Return value**
5206
5207| Type                     | Description                  |
5208| ------------------------- | --------------------- |
5209| [PathEffect](#patheffect12) | **PathEffect** object created.|
5210
5211**Error codes**
5212
5213For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5214
5215| ID| Error Message|
5216| ------- | --------------------------------------------|
5217| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
5218
5219**Example**
5220
5221```ts
5222import { RenderNode } from '@kit.ArkUI';
5223import { drawing } from '@kit.ArkGraphics2D';
5224class DrawingRenderNode extends RenderNode {
5225  draw(context : DrawContext) {
5226    const canvas = context.canvas;
5227    let effect = drawing.PathEffect.createCornerPathEffect(30);
5228  }
5229}
5230```
5231
5232## ShadowLayer<sup>12+</sup>
5233
5234Implements a shadow layer.
5235
5236### create<sup>12+</sup>
5237
5238static create(blurRadius: number, x: number, y: number, color: common2D.Color): ShadowLayer
5239
5240Creates a **ShadowLayer** object.
5241
5242**System capability**: SystemCapability.Graphics.Drawing
5243
5244**Parameters**
5245
5246| Name    | Type     | Mandatory| Description                                |
5247| ---------- | -------- | ---- | ----------------------------------- |
5248| blurRadius  | number   | Yes  | Radius of the shadow layer. The value must be a floating point number greater than 0.    |
5249| x           | number   | Yes  | Offset on the X axis. The value is a floating point number.       |
5250| y           | number   | Yes  | Offset on the Y axis. The value is a floating point number.       |
5251| 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.|
5252
5253**Return value**
5254
5255| Type                       | Description                 |
5256| --------------------------- | -------------------- |
5257| [ShadowLayer](#shadowlayer12) | **ShadowLayer** object created.|
5258
5259**Error codes**
5260
5261For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5262
5263| ID| Error Message|
5264| ------- | --------------------------------------------|
5265| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
5266
5267**Example**
5268
5269```ts
5270import { RenderNode } from '@kit.ArkUI';
5271import { common2D, drawing } from '@kit.ArkGraphics2D';
5272class DrawingRenderNode extends RenderNode {
5273  draw(context : DrawContext) {
5274    const canvas = context.canvas;
5275    let color : common2D.Color = {alpha: 0xFF, red: 0x00, green: 0xFF, blue: 0x00};
5276    let shadowLayer = drawing.ShadowLayer.create(3, -3, 3, color);
5277  }
5278}
5279```
5280
5281## Pen
5282
5283Defines a pen, which is used to describe the style and color to outline a shape.
5284
5285### constructor<sup>12+</sup>
5286
5287constructor()
5288
5289A constructor used to create a **Pen** object.
5290
5291**System capability**: SystemCapability.Graphics.Drawing
5292
5293**Example**
5294
5295```ts
5296import { drawing } from '@kit.ArkGraphics2D';
5297
5298const pen = new drawing.Pen();
5299```
5300
5301### constructor<sup>12+</sup>
5302
5303constructor(pen: Pen)
5304
5305Copies a **Pen** object to create a new one.
5306
5307**System capability**: SystemCapability.Graphics.Drawing
5308
5309**Parameters**
5310
5311| Name| Type       | Mandatory| Description             |
5312| ------| ----------- | ---- | ---------------- |
5313| pen     | [Pen](#pen) | Yes  | **Pen** object to copy.|
5314
5315**Error codes**
5316
5317For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5318
5319| ID| Error Message|
5320| ------- | --------------------------------------------|
5321| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
5322
5323**Example**
5324
5325```ts
5326import { common2D, drawing } from '@kit.ArkGraphics2D';
5327
5328const pen = new drawing.Pen();
5329const penColor: common2D.Color = { alpha: 255, red: 0, green: 255, blue: 0 };
5330pen.setColor(penColor);
5331pen.setStrokeWidth(10);
5332const newPen = new drawing.Pen(pen);
5333```
5334
5335### setMiterLimit<sup>12+</sup>
5336
5337setMiterLimit(miter: number): void
5338
5339Sets 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.
5340
5341**System capability**: SystemCapability.Graphics.Drawing
5342
5343**Parameters**
5344
5345| Name| Type   | Mandatory| Description             |
5346| ------ | ------ | ---- | ---------------- |
5347| 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.|
5348
5349**Error codes**
5350
5351For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5352
5353| ID| Error Message|
5354| ------- | --------------------------------------------|
5355| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
5356
5357**Example**
5358
5359```ts
5360import { drawing } from '@kit.ArkGraphics2D';
5361
5362const pen = new drawing.Pen();
5363pen.setMiterLimit(5);
5364```
5365
5366### getMiterLimit<sup>12+</sup>
5367
5368getMiterLimit(): number
5369
5370Obtains the maximum ratio allowed between the sharp corner length of a polyline and its line width.
5371
5372**System capability**: SystemCapability.Graphics.Drawing
5373
5374**Return value**
5375
5376| Type  | Description                |
5377| -------| -------------------- |
5378| number | Maximum ratio obtained.|
5379
5380**Example**
5381
5382```ts
5383import { drawing } from '@kit.ArkGraphics2D';
5384
5385const pen = new drawing.Pen();
5386let miter = pen.getMiterLimit();
5387```
5388
5389### setImageFilter<sup>12+</sup>
5390
5391setImageFilter(filter: ImageFilter | null): void
5392
5393Sets an image filter for this pen.
5394
5395**System capability**: SystemCapability.Graphics.Drawing
5396
5397**Parameters**
5398
5399| Name| Type  | Mandatory| Description                   |
5400| ------ | ------ | ---- | ----------------------- |
5401| filter    | [ImageFilter](#imagefilter12) \| null | Yes  |  Image filter. If null is passed in, the image filter effect of the pen will be cleared.|
5402
5403**Error codes**
5404
5405For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5406
5407| ID| Error Message|
5408| ------- | --------------------------------------------|
5409| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types. |
5410
5411**Example**
5412
5413```ts
5414import {drawing} from '@kit.ArkGraphics2D';
5415let colorfilter = drawing.ColorFilter.createSRGBGammaToLinear();
5416let imgFilter = drawing.ImageFilter.createFromColorFilter(colorfilter);
5417let pen = new drawing.Pen();
5418pen.setImageFilter(imgFilter);
5419pen.setImageFilter(null);
5420```
5421
5422### getColorFilter<sup>12+</sup>
5423
5424getColorFilter(): ColorFilter
5425
5426Obtains the color filter of this pen.
5427
5428**System capability**: SystemCapability.Graphics.Drawing
5429
5430**Return value**
5431
5432| Type                       | Description              |
5433| --------------------------- | ------------------ |
5434| [ColorFilter](#colorfilter) | Color filter.|
5435
5436**Example**
5437
5438```ts 
5439import {drawing} from '@kit.ArkGraphics2D';
5440let pen = new drawing.Pen();
5441let colorfilter = drawing.ColorFilter.createLumaColorFilter();
5442pen.setColorFilter(colorfilter);
5443let filter = pen.getColorFilter();
5444```
5445
5446### setColor
5447
5448setColor(color: common2D.Color) : void
5449
5450Sets a color for this pen.
5451
5452**System capability**: SystemCapability.Graphics.Drawing
5453
5454**Parameters**
5455
5456| Name| Type                                                | Mandatory| Description            |
5457| ------ | ---------------------------------------------------- | ---- | ---------------- |
5458| 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.|
5459
5460**Error codes**
5461
5462For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5463
5464| ID| Error Message|
5465| ------- | --------------------------------------------|
5466| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
5467
5468**Example**
5469
5470```ts
5471import { common2D, drawing } from '@kit.ArkGraphics2D';
5472const color : common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
5473const pen = new drawing.Pen();
5474pen.setColor(color);
5475```
5476
5477### setColor<sup>12+</sup>
5478
5479setColor(alpha: number, red: number, green: number, blue: number): void
5480
5481Sets a color for this pen. This API provides better performance than [setColor](#setcolor) and is recommended.
5482
5483**System capability**: SystemCapability.Graphics.Drawing
5484
5485**Parameters**
5486
5487| Name| Type   | Mandatory| Description                                               |
5488| ------ | ------ | ---- | -------------------------------------------------- |
5489| 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.|
5490| 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.  |
5491| 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.  |
5492| 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.  |
5493
5494**Error codes**
5495
5496For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5497
5498| ID| Error Message|
5499| ------- | --------------------------------------------|
5500| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
5501
5502**Example**
5503
5504```ts
5505import { drawing } from '@kit.ArkGraphics2D';
5506const pen = new drawing.Pen();
5507pen.setColor(255, 255, 0, 0);
5508```
5509
5510### getColor<sup>12+</sup>
5511
5512getColor(): common2D.Color
5513
5514Obtains the color of this pen.
5515
5516**System capability**: SystemCapability.Graphics.Drawing
5517
5518**Return value**
5519
5520| Type          | Description           |
5521| -------------- | -------------- |
5522| common2D.Color | Color of the pen.|
5523
5524**Example**
5525
5526```ts
5527import { common2D, drawing } from '@kit.ArkGraphics2D';
5528
5529const color : common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
5530const pen = new drawing.Pen();
5531pen.setColor(color);
5532let colorGet = pen.getColor();
5533```
5534
5535### getHexColor<sup>13+</sup>
5536
5537getHexColor(): number
5538
5539Obtains the color of this pen.
5540
5541**System capability**: SystemCapability.Graphics.Drawing
5542
5543**Return value**
5544
5545| Type          | Description           |
5546| -------------- | -------------- |
5547| number | Color, represented as a 32-bit unsigned integer in hexadecimal ARGB format.|
5548
5549**Example**
5550
5551```ts
5552import { common2D, drawing } from '@kit.ArkGraphics2D';
5553
5554let color : common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
5555let pen = new drawing.Pen();
5556pen.setColor(color);
5557let hex_color: number = pen.getHexColor();
5558console.info('getHexColor: ', hex_color.toString(16));
5559```
5560
5561### setStrokeWidth
5562
5563setStrokeWidth(width: number) : void
5564
5565Sets 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.
5566
5567**System capability**: SystemCapability.Graphics.Drawing
5568
5569**Parameters**
5570
5571| Name| Type  | Mandatory| Description            |
5572| ------ | ------ | ---- | ---------------- |
5573| width  | number | Yes  | Stroke width. The value is a floating point number.|
5574
5575**Error codes**
5576
5577For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5578
5579| ID| Error Message|
5580| ------- | --------------------------------------------|
5581| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
5582
5583**Example**
5584
5585```ts
5586import { drawing } from '@kit.ArkGraphics2D';
5587const pen = new drawing.Pen();
5588pen.setStrokeWidth(5);
5589```
5590
5591### getWidth<sup>12+</sup>
5592
5593getWidth(): number
5594
5595Obtains the stroke width of this pen. The width describes the thickness of the outline of a shape.
5596
5597**System capability**: SystemCapability.Graphics.Drawing
5598
5599**Return value**
5600
5601| Type  | Description           |
5602| ------ | -------------- |
5603| number | Stroke width of the pen.|
5604
5605**Example**
5606
5607```ts
5608import { drawing } from '@kit.ArkGraphics2D';
5609
5610const pen = new drawing.Pen();
5611let width = pen.getWidth();
5612```
5613
5614### setAntiAlias
5615
5616setAntiAlias(aa: boolean) : void
5617
5618Enables anti-aliasing for this pen. Anti-aliasing makes the edges of the content smoother.
5619
5620**System capability**: SystemCapability.Graphics.Drawing
5621
5622**Parameters**
5623
5624| Name| Type   | Mandatory| Description                                             |
5625| ------ | ------- | ---- | ------------------------------------------------- |
5626| aa     | boolean | Yes  | Whether to enable anti-aliasing. The value **true** means to enable anti-aliasing, and **false** means the opposite.|
5627
5628**Error codes**
5629
5630For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5631
5632| ID| Error Message|
5633| ------- | --------------------------------------------|
5634| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
5635
5636**Example**
5637
5638```ts
5639import { drawing } from '@kit.ArkGraphics2D';
5640const pen = new drawing.Pen();
5641pen.setAntiAlias(true);
5642```
5643
5644### isAntiAlias<sup>12+</sup>
5645
5646isAntiAlias(): boolean
5647
5648Checks whether anti-aliasing is enabled for this pen.
5649
5650**System capability**: SystemCapability.Graphics.Drawing
5651
5652**Return value**
5653
5654| Type   | Description                      |
5655| ------- | ------------------------- |
5656| boolean | Result indicating whether anti-aliasing is enabled. The value **true** means that anti-aliasing is enabled, and **false** means the opposite.|
5657
5658**Example**
5659
5660```ts
5661import { drawing } from '@kit.ArkGraphics2D';
5662
5663const pen = new drawing.Pen();
5664let isAntiAlias = pen.isAntiAlias();
5665```
5666
5667### setAlpha
5668
5669setAlpha(alpha: number) : void
5670
5671Sets an alpha value for this pen.
5672
5673**System capability**: SystemCapability.Graphics.Drawing
5674
5675**Parameters**
5676
5677| Name| Type  | Mandatory| Description                                    |
5678| ------ | ------ | ---- | ---------------------------------------- |
5679| 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.|
5680
5681**Error codes**
5682
5683For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5684
5685| ID| Error Message|
5686| ------- | --------------------------------------------|
5687| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
5688
5689**Example**
5690
5691```ts
5692import { drawing } from '@kit.ArkGraphics2D';
5693const pen = new drawing.Pen();
5694pen.setAlpha(128);
5695```
5696
5697### getAlpha<sup>12+</sup>
5698
5699getAlpha(): number
5700
5701Obtains the alpha value of this pen.
5702
5703**System capability**: SystemCapability.Graphics.Drawing
5704
5705**Return value**
5706
5707| Type  | Description             |
5708| ------ | ---------------- |
5709| number | Alpha value of the pen. The return value is an integer ranging from 0 to 255.|
5710
5711**Example**
5712
5713```ts
5714import { drawing } from '@kit.ArkGraphics2D';
5715
5716const pen = new drawing.Pen();
5717let alpha = pen.getAlpha();
5718```
5719
5720### setColorFilter
5721
5722setColorFilter(filter: ColorFilter) : void
5723
5724Sets a color filter for this pen.
5725
5726**System capability**: SystemCapability.Graphics.Drawing
5727
5728**Parameters**
5729
5730| Name| Type                       | Mandatory| Description        |
5731| ------ | --------------------------- | ---- | ------------ |
5732| filter | [ColorFilter](#colorfilter) | Yes  | Color filter. If null is passed in, the color filter is cleared.|
5733
5734**Error codes**
5735
5736For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5737
5738| ID| Error Message|
5739| ------- | --------------------------------------------|
5740| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
5741
5742**Example**
5743
5744```ts
5745import { drawing } from '@kit.ArkGraphics2D';
5746const pen = new drawing.Pen();
5747let colorFilter = drawing.ColorFilter.createLinearToSRGBGamma();
5748pen.setColorFilter(colorFilter);
5749```
5750
5751### setMaskFilter<sup>12+</sup>
5752
5753setMaskFilter(filter: MaskFilter): void
5754
5755Adds a mask filter for this pen.
5756
5757**System capability**: SystemCapability.Graphics.Drawing
5758
5759**Parameters**
5760
5761| Name| Type                      | Mandatory| Description     |
5762| ------ | ------------------------- | ---- | --------- |
5763| filter | [MaskFilter](#maskfilter12) | Yes  | Mask filter. If null is passed in, the mask filter is cleared.|
5764
5765**Error codes**
5766
5767For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5768
5769| ID| Error Message|
5770| ------- | --------------------------------------------|
5771| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
5772
5773**Example**
5774
5775```ts
5776import { RenderNode } from '@kit.ArkUI';
5777import { common2D, drawing } from '@kit.ArkGraphics2D';
5778class DrawingRenderNode extends RenderNode {
5779  draw(context : DrawContext) {
5780    const canvas = context.canvas;
5781    const pen = new drawing.Pen();
5782    pen.setStrokeWidth(5);
5783    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
5784    let maskFilter = drawing.MaskFilter.createBlurMaskFilter(drawing.BlurType.OUTER, 10);
5785    pen.setMaskFilter(maskFilter);
5786  }
5787}
5788```
5789
5790### setPathEffect<sup>12+</sup>
5791
5792setPathEffect(effect: PathEffect): void
5793
5794Sets the path effect for this pen.
5795
5796**System capability**: SystemCapability.Graphics.Drawing
5797
5798**Parameters**
5799
5800| Name | Type                      | Mandatory| Description        |
5801| ------- | ------------------------- | ---- | ------------ |
5802| effect  | [PathEffect](#patheffect12) | Yes  | Path effect. If null is passed in, the path filter is cleared.|
5803
5804**Error codes**
5805
5806For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5807
5808| ID| Error Message|
5809| ------- | --------------------------------------------|
5810| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
5811
5812**Example**
5813
5814```ts
5815import { RenderNode } from '@kit.ArkUI';
5816import { common2D, drawing } from '@kit.ArkGraphics2D';
5817class DrawingRenderNode extends RenderNode {
5818  draw(context : DrawContext) {
5819    const canvas = context.canvas;
5820    const pen = new drawing.Pen();
5821    pen.setStrokeWidth(5);
5822    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
5823    let pathEffect = drawing.PathEffect.createDashPathEffect([30, 10], 0);
5824    pen.setPathEffect(pathEffect);
5825  }
5826}
5827```
5828
5829### setShaderEffect<sup>12+</sup>
5830
5831setShaderEffect(shaderEffect: ShaderEffect): void
5832
5833Sets the shader effect for this pen.
5834
5835**System capability**: SystemCapability.Graphics.Drawing
5836
5837**Parameters**
5838
5839| Name | Type                      | Mandatory| Description        |
5840| ------- | ------------------------- | ---- | ------------ |
5841| shaderEffect  | [ShaderEffect](#shadereffect12) | Yes  | **ShaderEffect** object. If null is passed in, the shader effect will be cleared.|
5842
5843**Error codes**
5844
5845For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5846
5847| ID| Error Message|
5848| ------- | --------------------------------------------|
5849| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
5850
5851**Example**
5852
5853```ts
5854import { drawing } from '@kit.ArkGraphics2D';
5855
5856const pen = new drawing.Pen();
5857let shaderEffect = drawing.ShaderEffect.createLinearGradient({x: 100, y: 100}, {x: 300, y: 300}, [0xFF00FF00, 0xFFFF0000], drawing.TileMode.REPEAT);
5858pen.setShaderEffect(shaderEffect);
5859```
5860
5861### setShadowLayer<sup>12+</sup>
5862
5863setShadowLayer(shadowLayer: ShadowLayer): void
5864
5865Sets a shadow layer for this pen. The shadow layer effect takes effect only when text is drawn.
5866
5867**System capability**: SystemCapability.Graphics.Drawing
5868
5869**Parameters**
5870
5871| Name | Type                      | Mandatory| Description     |
5872| ------- | ------------------------- | ---- | --------- |
5873| shadowLayer  | [ShadowLayer](#shadowlayer12) | Yes  | Shadow layer. If null is passed in, the shadow layer is cleared.|
5874
5875**Error codes**
5876
5877For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5878
5879| ID| Error Message|
5880| ------- | --------------------------------------------|
5881| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
5882
5883**Example**
5884
5885```ts
5886import { RenderNode } from '@kit.ArkUI';
5887import { common2D, drawing } from '@kit.ArkGraphics2D';
5888class DrawingRenderNode extends RenderNode {
5889  draw(context : DrawContext) {
5890    const canvas = context.canvas;
5891    let font = new drawing.Font();
5892    font.setSize(60);
5893    let textBlob = drawing.TextBlob.makeFromString("hello", font, drawing.TextEncoding.TEXT_ENCODING_UTF8);
5894    let pen = new drawing.Pen();
5895    pen.setStrokeWidth(2.0);
5896    let pen_color : common2D.Color = {alpha: 0xFF, red: 0xFF, green: 0x00, blue: 0x00};
5897    pen.setColor(pen_color);
5898    canvas.attachPen(pen);
5899    canvas.drawTextBlob(textBlob, 100, 100);
5900    canvas.detachPen();
5901    let color : common2D.Color = {alpha: 0xFF, red: 0x00, green: 0xFF, blue: 0x00};
5902    let shadowLayer = drawing.ShadowLayer.create(3, -3, 3, color);
5903    pen.setShadowLayer(shadowLayer);
5904    canvas.attachPen(pen);
5905    canvas.drawTextBlob(textBlob, 100, 200);
5906    canvas.detachPen();
5907  }
5908}
5909```
5910
5911### setBlendMode
5912
5913setBlendMode(mode: BlendMode) : void
5914
5915Sets a blend mode for this pen.
5916
5917**System capability**: SystemCapability.Graphics.Drawing
5918
5919**Parameters**
5920
5921| Name| Type                   | Mandatory| Description            |
5922| ------ | ----------------------- | ---- | ---------------- |
5923| mode   | [BlendMode](#blendmode) | Yes  | Blend mode.|
5924
5925**Error codes**
5926
5927For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5928
5929| ID| Error Message|
5930| ------- | --------------------------------------------|
5931| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
5932
5933**Example**
5934
5935```ts
5936import { drawing } from '@kit.ArkGraphics2D';
5937const pen = new drawing.Pen();
5938pen.setBlendMode(drawing.BlendMode.SRC);
5939```
5940
5941### setJoinStyle<sup>12+</sup>
5942
5943setJoinStyle(style: JoinStyle): void
5944
5945Sets the join style for this pen.
5946
5947**System capability**: SystemCapability.Graphics.Drawing
5948
5949**Parameters**
5950
5951| Name| Type                    | Mandatory| Description            |
5952| ------ | ----------------------- | ---- | --------------- |
5953| style  | [JoinStyle](#joinstyle12) | Yes  | Join style.    |
5954
5955**Error codes**
5956
5957For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5958
5959| ID| Error Message|
5960| ------- | --------------------------------------------|
5961| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
5962
5963**Example**
5964
5965```ts
5966import { RenderNode } from '@kit.ArkUI';
5967import { common2D, drawing } from '@kit.ArkGraphics2D';
5968class DrawingRenderNode extends RenderNode {
5969  draw(context : DrawContext) {
5970    const canvas = context.canvas;
5971    const pen = new drawing.Pen();
5972    pen.setStrokeWidth(5);
5973    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
5974    pen.setJoinStyle(drawing.JoinStyle.ROUND_JOIN);
5975  }
5976}
5977```
5978
5979### getJoinStyle<sup>12+</sup>
5980
5981getJoinStyle(): JoinStyle
5982
5983Obtains the join style of this pen.
5984
5985**System capability**: SystemCapability.Graphics.Drawing
5986
5987**Return value**
5988
5989| Type         | Description                   |
5990| ------------- | ---------------------- |
5991| JoinStyle | Join style.        |
5992
5993**Example**
5994
5995```ts
5996import { RenderNode } from '@kit.ArkUI';
5997import { common2D, drawing } from '@kit.ArkGraphics2D';
5998class DrawingRenderNode extends RenderNode {
5999  draw(context : DrawContext) {
6000    const canvas = context.canvas;
6001    const pen = new drawing.Pen();
6002    pen.setStrokeWidth(5);
6003    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
6004    pen.setJoinStyle(drawing.JoinStyle.ROUND_JOIN);
6005    let joinStyle = pen.getJoinStyle();
6006  }
6007}
6008```
6009
6010### setCapStyle<sup>12+</sup>
6011
6012setCapStyle(style: CapStyle): void
6013
6014Sets the cap style for this pen.
6015
6016**System capability**: SystemCapability.Graphics.Drawing
6017
6018**Parameters**
6019
6020| Name| Type                    | Mandatory| Description                  |
6021| ------ | ----------------------- | ---- | --------------------- |
6022| style  | [CapStyle](#capstyle12)   | Yes  | A variable that describes the cap style.   |
6023
6024**Error codes**
6025
6026For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6027
6028| ID| Error Message|
6029| ------- | --------------------------------------------|
6030| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
6031
6032**Example**
6033
6034```ts
6035import { RenderNode } from '@kit.ArkUI';
6036import { common2D, drawing } from '@kit.ArkGraphics2D';
6037class DrawingRenderNode extends RenderNode {
6038  draw(context : DrawContext) {
6039    const canvas = context.canvas;
6040    const pen = new drawing.Pen();
6041    pen.setStrokeWidth(5);
6042    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
6043    pen.setCapStyle(drawing.CapStyle.SQUARE_CAP);
6044  }
6045}
6046```
6047
6048### getCapStyle<sup>12+</sup>
6049
6050getCapStyle(): CapStyle
6051
6052Obtains the cap style of this pen.
6053
6054**System capability**: SystemCapability.Graphics.Drawing
6055
6056**Return value**
6057
6058| Type        | Description               |
6059| ------------ | ------------------ |
6060| CapStyle     | Cap style.|
6061
6062**Example**
6063
6064```ts
6065import { RenderNode } from '@kit.ArkUI';
6066import { common2D, drawing } from '@kit.ArkGraphics2D';
6067class DrawingRenderNode extends RenderNode {
6068  draw(context : DrawContext) {
6069    const canvas = context.canvas;
6070    const pen = new drawing.Pen();
6071    pen.setStrokeWidth(5);
6072    pen.setColor({alpha: 255, red: 255, green: 0, blue: 0});
6073    pen.setCapStyle(drawing.CapStyle.SQUARE_CAP);
6074    let capStyle = pen.getCapStyle();
6075  }
6076}
6077```
6078
6079### setDither
6080
6081setDither(dither: boolean) : void
6082
6083Enables dithering for this pen. Dithering make the drawn color more realistic.
6084
6085**System capability**: SystemCapability.Graphics.Drawing
6086
6087**Parameters**
6088
6089| Name| Type   | Mandatory| Description                                                     |
6090| ------ | ------- | ---- | --------------------------------------------------------- |
6091| dither | boolean | Yes  | Whether to enable dithering. The value **true** means to enable dithering, and **false** means the opposite.|
6092
6093**Error codes**
6094
6095For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6096
6097| ID| Error Message|
6098| ------- | --------------------------------------------|
6099| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6100
6101**Example**
6102
6103```ts
6104import { drawing } from '@kit.ArkGraphics2D';
6105const pen = new drawing.Pen();
6106pen.setDither(true);
6107```
6108
6109### getFillPath<sup>12+</sup>
6110
6111getFillPath(src: Path, dst: Path): boolean
6112
6113Obtains the source path outline drawn using this pen and represents it using a destination path.
6114
6115**System capability**: SystemCapability.Graphics.Drawing
6116
6117**Parameters**
6118
6119| Name  | Type                                        | Mandatory| Description                           |
6120| -------- | -------------------------------------------- | ---- | ------------------------------- |
6121| src | [Path](#path) | Yes  | Source path.                |
6122| dst     | [Path](#path)                | Yes  | Destination path.|
6123
6124**Return value**
6125
6126| Type                 | Description          |
6127| --------------------- | -------------- |
6128| 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.|
6129
6130**Error codes**
6131
6132For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6133
6134| ID| Error Message|
6135| ------- | --------------------------------------------|
6136| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6137
6138**Example**
6139
6140```ts
6141import { drawing } from '@kit.ArkGraphics2D';
6142let pen = new drawing.Pen();
6143let pathSrc: drawing.Path = new drawing.Path();
6144let pathDst: drawing.Path = new drawing.Path();
6145pathSrc.moveTo(0, 0);
6146pathSrc.lineTo(700, 700);
6147let value = pen.getFillPath(pathSrc, pathDst);
6148```
6149
6150### reset<sup>12+</sup>
6151
6152reset(): void
6153
6154Resets this pen to the initial state.
6155
6156**System capability**: SystemCapability.Graphics.Drawing
6157
6158**Example**
6159
6160```ts
6161import { drawing } from '@kit.ArkGraphics2D';
6162
6163const pen = new drawing.Pen();
6164pen.reset();
6165```
6166
6167## Brush
6168
6169Defines a brush, which is used to describe the style and color to fill in a shape.
6170
6171### constructor<sup>12+</sup>
6172
6173constructor()
6174
6175A constructor used to create a **Brush** object.
6176
6177**System capability**: SystemCapability.Graphics.Drawing
6178
6179**Example**
6180
6181```ts
6182import { drawing } from '@kit.ArkGraphics2D';
6183
6184const brush = new drawing.Brush();
6185```
6186
6187### constructor<sup>12+</sup>
6188
6189constructor(brush: Brush)
6190
6191Copies a **Brush** object to create a new one.
6192
6193**System capability**: SystemCapability.Graphics.Drawing
6194
6195**Parameters**
6196
6197| Name| Type       | Mandatory| Description             |
6198| ------| ----------- | ---- | ---------------- |
6199| brush     | [Brush](#brush) | Yes  | **Brush** object to copy.|
6200
6201**Error codes**
6202
6203For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6204
6205| ID| Error Message|
6206| ------- | --------------------------------------------|
6207| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6208
6209**Example**
6210
6211```ts
6212import { common2D, drawing } from '@kit.ArkGraphics2D';
6213
6214const brush = new drawing.Brush();
6215const brushColor: common2D.Color = { alpha: 255, red: 0, green: 255, blue: 0 };
6216brush.setColor(brushColor);
6217const newBrush = new drawing.Brush(brush);
6218```
6219
6220### setColor
6221
6222setColor(color: common2D.Color) : void
6223
6224Sets a color for this brush.
6225
6226**System capability**: SystemCapability.Graphics.Drawing
6227
6228**Parameters**
6229
6230| Name| Type                                                | Mandatory| Description            |
6231| ------ | ---------------------------------------------------- | ---- | ---------------- |
6232| 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.|
6233
6234**Error codes**
6235
6236For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6237
6238| ID| Error Message|
6239| ------- | --------------------------------------------|
6240| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
6241
6242**Example**
6243
6244```ts
6245import { common2D, drawing } from '@kit.ArkGraphics2D';
6246const color : common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
6247const brush = new drawing.Brush();
6248brush.setColor(color);
6249```
6250
6251### setColor<sup>12+</sup>
6252
6253setColor(alpha: number, red: number, green: number, blue: number): void
6254
6255Sets a color for this brush. This API provides better performance than [setColor](#setcolor-1) and is recommended.
6256
6257**System capability**: SystemCapability.Graphics.Drawing
6258 
6259**Parameters**
6260
6261| Name| Type   | Mandatory| Description                                              |
6262| ------ | ------ | ---- | -------------------------------------------------- |
6263| 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.|
6264| 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.  |
6265| 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.  |
6266| 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.  |
6267
6268**Error codes**
6269
6270For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6271
6272| ID| Error Message|
6273| ------- | --------------------------------------------|
6274| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
6275
6276**Example**
6277
6278```ts
6279import { drawing } from '@kit.ArkGraphics2D';
6280const brush = new drawing.Brush();
6281brush.setColor(255, 255, 0, 0);
6282```
6283
6284### getColor<sup>12+</sup>
6285
6286getColor(): common2D.Color
6287
6288Obtains the color of this brush.
6289
6290**System capability**: SystemCapability.Graphics.Drawing
6291
6292**Return value**
6293
6294| Type          | Description           |
6295| -------------- | -------------- |
6296| common2D.Color | Color of the brush.|
6297
6298**Example**
6299
6300```ts
6301import { common2D, drawing } from '@kit.ArkGraphics2D';
6302
6303const color : common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
6304const brush = new drawing.Brush();
6305brush.setColor(color);
6306let colorGet = brush.getColor();
6307```
6308
6309### getHexColor<sup>13+</sup>
6310
6311Obtains the color of this brush.
6312
6313**System capability**: SystemCapability.Graphics.Drawing
6314
6315**Return value**
6316
6317| Type          | Description           |
6318| -------------- | -------------- |
6319| number | Color, represented as a 32-bit unsigned integer in hexadecimal ARGB format.|
6320
6321**Example**
6322
6323```ts
6324import { common2D, drawing } from '@kit.ArkGraphics2D';
6325
6326let color : common2D.Color = { alpha: 255, red: 255, green: 0, blue: 0 };
6327let brush = new drawing.Brush();
6328brush.setColor(color);
6329let hex_color: number = brush.getHexColor();
6330console.info('getHexColor: ', hex_color.toString(16));
6331```
6332
6333### setAntiAlias
6334
6335setAntiAlias(aa: boolean) : void
6336
6337Enables anti-aliasing for this brush. Anti-aliasing makes the edges of the content smoother.
6338
6339**System capability**: SystemCapability.Graphics.Drawing
6340
6341**Parameters**
6342
6343| Name| Type   | Mandatory| Description                                             |
6344| ------ | ------- | ---- | ------------------------------------------------- |
6345| aa     | boolean | Yes  | Whether to enable anti-aliasing. The value **true** means to enable anti-aliasing, and **false** means the opposite.|
6346
6347**Error codes**
6348
6349For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6350
6351| ID| Error Message|
6352| ------- | --------------------------------------------|
6353| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6354
6355**Example**
6356
6357```ts
6358import { drawing } from '@kit.ArkGraphics2D';
6359const brush = new drawing.Brush();
6360brush.setAntiAlias(true);
6361```
6362
6363### isAntiAlias<sup>12+</sup>
6364
6365isAntiAlias(): boolean
6366
6367Checks whether anti-aliasing is enabled for this brush.
6368
6369**System capability**: SystemCapability.Graphics.Drawing
6370
6371**Return value**
6372
6373| Type   | Description                      |
6374| ------- | ------------------------- |
6375| boolean | Result indicating whether anti-aliasing is enabled. The value **true** means that anti-aliasing is enabled, and **false** means the opposite.|
6376
6377**Example**
6378
6379```ts
6380import { drawing } from '@kit.ArkGraphics2D';
6381
6382const brush = new drawing.Brush();
6383let isAntiAlias = brush.isAntiAlias();
6384```
6385
6386### setAlpha
6387
6388setAlpha(alpha: number) : void
6389
6390Sets an alpha value for this brush.
6391
6392**System capability**: SystemCapability.Graphics.Drawing
6393
6394**Parameters**
6395
6396| Name| Type  | Mandatory| Description                                    |
6397| ------ | ------ | ---- | ---------------------------------------- |
6398| 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.|
6399
6400**Error codes**
6401
6402For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6403
6404| ID| Error Message|
6405| ------- | --------------------------------------------|
6406| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
6407
6408**Example**
6409
6410```ts
6411import { drawing } from '@kit.ArkGraphics2D';
6412const brush = new drawing.Brush();
6413brush.setAlpha(128);
6414```
6415
6416### getAlpha<sup>12+</sup>
6417
6418getAlpha(): number
6419
6420Obtains the alpha value of this brush.
6421
6422**System capability**: SystemCapability.Graphics.Drawing
6423
6424**Return value**
6425
6426| Type  | Description             |
6427| ------ | ---------------- |
6428| number | Alpha value of the brush. The return value is an integer ranging from 0 to 255.|
6429
6430**Example**
6431
6432```ts
6433import { drawing } from '@kit.ArkGraphics2D';
6434
6435const brush = new drawing.Brush();
6436let alpha = brush.getAlpha();
6437```
6438
6439### setColorFilter
6440
6441setColorFilter(filter: ColorFilter) : void
6442
6443Sets a color filter for this brush.
6444
6445**System capability**: SystemCapability.Graphics.Drawing
6446
6447**Parameters**
6448
6449| Name| Type                       | Mandatory| Description        |
6450| ------ | --------------------------- | ---- | ------------ |
6451| filter | [ColorFilter](#colorfilter) | Yes  | Color filter. If null is passed in, the color filter is cleared.|
6452
6453**Error codes**
6454
6455For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6456
6457| ID| Error Message|
6458| ------- | --------------------------------------------|
6459| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6460
6461**Example**
6462
6463```ts
6464import { drawing } from '@kit.ArkGraphics2D';
6465const brush = new drawing.Brush();
6466let colorFilter = drawing.ColorFilter.createLinearToSRGBGamma();
6467brush.setColorFilter(colorFilter);
6468```
6469
6470### setMaskFilter<sup>12+</sup>
6471
6472setMaskFilter(filter: MaskFilter): void
6473
6474Adds a mask filter for this brush.
6475
6476**System capability**: SystemCapability.Graphics.Drawing
6477
6478**Parameters**
6479
6480| Name| Type                      | Mandatory| Description     |
6481| ------ | ------------------------- | ---- | --------- |
6482| filter | [MaskFilter](#maskfilter12) | Yes  | Mask filter. If null is passed in, the mask filter is cleared.|
6483
6484**Error codes**
6485
6486For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6487
6488| ID| Error Message|
6489| ------- | --------------------------------------------|
6490| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6491
6492**Example**
6493
6494```ts
6495import { RenderNode } from '@kit.ArkUI';
6496import { common2D, drawing } from '@kit.ArkGraphics2D';
6497class DrawingRenderNode extends RenderNode {
6498  draw(context : DrawContext) {
6499    const canvas = context.canvas;
6500    const brush = new drawing.Brush();
6501    let maskFilter = drawing.MaskFilter.createBlurMaskFilter(drawing.BlurType.OUTER, 10);
6502    brush.setMaskFilter(maskFilter);
6503  }
6504}
6505```
6506
6507### setShaderEffect<sup>12+</sup>
6508
6509setShaderEffect(shaderEffect: ShaderEffect): void
6510
6511Sets the shader effect for this brush.
6512
6513**System capability**: SystemCapability.Graphics.Drawing
6514
6515**Parameters**
6516
6517| Name | Type                      | Mandatory| Description        |
6518| ------- | ------------------------- | ---- | ------------ |
6519| shaderEffect  | [ShaderEffect](#shadereffect12) | Yes  | **ShaderEffect** object. If null is passed in, the shader effect will be cleared.|
6520
6521**Error codes**
6522
6523For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6524
6525| ID| Error Message|
6526| ------- | --------------------------------------------|
6527| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6528
6529**Example**
6530
6531```ts
6532import { drawing } from '@kit.ArkGraphics2D';
6533
6534const brush = new drawing.Brush();
6535let shaderEffect = drawing.ShaderEffect.createLinearGradient({x: 100, y: 100}, {x: 300, y: 300}, [0xFF00FF00, 0xFFFF0000], drawing.TileMode.REPEAT);
6536brush.setShaderEffect(shaderEffect);
6537```
6538
6539### setShadowLayer<sup>12+</sup>
6540
6541setShadowLayer(shadowLayer: ShadowLayer): void
6542
6543Sets a shadow layer for this brush. The shadow layer effect takes effect only when text is drawn.
6544
6545**System capability**: SystemCapability.Graphics.Drawing
6546
6547**Parameters**
6548
6549| Name | Type                      | Mandatory| Description     |
6550| ------- | ------------------------- | ---- | --------- |
6551| shadowLayer  | [ShadowLayer](#shadowlayer12) | Yes  | Shadow layer. If null is passed in, the shadow layer is cleared.|
6552
6553**Error codes**
6554
6555For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6556
6557| ID| Error Message|
6558| ------- | --------------------------------------------|
6559| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6560
6561**Example**
6562
6563```ts
6564import { RenderNode } from '@kit.ArkUI';
6565import { common2D, drawing } from '@kit.ArkGraphics2D';
6566class DrawingRenderNode extends RenderNode {
6567  draw(context : DrawContext) {
6568    const canvas = context.canvas;
6569    let font = new drawing.Font();
6570    font.setSize(60);
6571
6572    let textBlob = drawing.TextBlob.makeFromString("hello", font, drawing.TextEncoding.TEXT_ENCODING_UTF8);
6573    let pen = new drawing.Pen();
6574    pen.setStrokeWidth(2.0);
6575
6576    let pen_color : common2D.Color = {alpha: 0xFF, red: 0xFF, green: 0x00, blue: 0x00};
6577    pen.setColor(pen_color);
6578    canvas.attachPen(pen);
6579    canvas.drawTextBlob(textBlob, 100, 100);
6580    canvas.detachPen();
6581
6582    let color : common2D.Color = {alpha: 0xFF, red: 0x00, green: 0xFF, blue: 0x00};
6583    let shadowLayer = drawing.ShadowLayer.create(3, -3, 3, color);
6584    pen.setShadowLayer(shadowLayer);
6585    canvas.attachPen(pen);
6586    canvas.drawTextBlob(textBlob, 100, 200);
6587    canvas.detachPen();
6588
6589    let brush = new drawing.Brush();
6590    let brush_color : common2D.Color = {alpha: 0xFF, red: 0xFF, green: 0x00, blue: 0x00};
6591    brush.setColor(brush_color);
6592    canvas.attachBrush(brush);
6593    canvas.drawTextBlob(textBlob, 300, 100);
6594    canvas.detachBrush();
6595
6596    brush.setShadowLayer(shadowLayer);
6597    canvas.attachBrush(brush);
6598    canvas.drawTextBlob(textBlob, 300, 200);
6599    canvas.detachBrush();
6600  }
6601}
6602```
6603
6604### setBlendMode
6605
6606setBlendMode(mode: BlendMode) : void
6607
6608Sets a blend mode for this brush.
6609
6610**System capability**: SystemCapability.Graphics.Drawing
6611
6612**Parameters**
6613
6614| Name| Type                   | Mandatory| Description            |
6615| ------ | ----------------------- | ---- | ---------------- |
6616| mode   | [BlendMode](#blendmode) | Yes  | Blend mode.|
6617
6618**Error codes**
6619
6620For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6621
6622| ID| Error Message|
6623| ------- | --------------------------------------------|
6624| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
6625
6626**Example**
6627
6628```ts
6629import { drawing } from '@kit.ArkGraphics2D';
6630const brush = new drawing.Brush();
6631brush.setBlendMode(drawing.BlendMode.SRC);
6632```
6633
6634### setImageFilter<sup>12+</sup>
6635
6636setImageFilter(filter: ImageFilter | null): void
6637
6638Sets an image filter for this brush.
6639
6640**System capability**: SystemCapability.Graphics.Drawing
6641
6642**Parameters**
6643
6644| Name| Type  | Mandatory| Description                   |
6645| ------ | ------ | ---- | ----------------------- |
6646| filter    | [ImageFilter](#imagefilter12) \| null | Yes  | Image filter. If null is passed in, the image filter effect of the brush will be cleared.|
6647
6648**Error codes**
6649
6650For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6651
6652| ID| Error Message|
6653| ------- | --------------------------------------------|
6654| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types. | 
6655
6656**Example**
6657
6658```ts
6659import {drawing} from '@kit.ArkGraphics2D';
6660let brush = new drawing.Brush();
6661let imgFilter = drawing.ImageFilter.createBlurImageFilter(5, 10, drawing.TileMode.DECAL);
6662brush.setImageFilter(imgFilter);
6663brush.setImageFilter(null);
6664```
6665
6666### getColorFilter<sup>12+</sup>
6667
6668getColorFilter(): ColorFilter
6669
6670Obtains the color filter of this brush.
6671
6672**System capability**: SystemCapability.Graphics.Drawing
6673
6674**Return value**
6675
6676| Type                       | Description              |
6677| --------------------------- | ------------------ |
6678| [ColorFilter](#colorfilter) | Color filter.|
6679
6680**Example**
6681
6682```ts 
6683import {drawing} from '@kit.ArkGraphics2D';
6684let brush = new drawing.Brush();
6685let setColorFilter = drawing.ColorFilter.createSRGBGammaToLinear();
6686brush.setColorFilter(setColorFilter);
6687let filter = brush.getColorFilter();   
6688```
6689
6690### reset<sup>12+</sup>
6691
6692reset(): void
6693
6694Resets this brush to the initial state.
6695
6696**System capability**: SystemCapability.Graphics.Drawing
6697
6698**Example**
6699
6700```ts
6701import { drawing } from '@kit.ArkGraphics2D';
6702
6703const brush = new drawing.Brush();
6704brush.reset();
6705```
6706
6707## ScaleToFit<sup>12+</sup>
6708
6709Enumerates the modes of scaling a source rectangle into a destination rectangle.
6710
6711**System capability**: SystemCapability.Graphics.Drawing
6712
6713| Name                  | Value  | Description                          |
6714| ---------------------- | ---- | ------------------------------ |
6715| FILL_SCALE_TO_FIT     | 0    | Scales the source rectangle to completely fill the destination rectangle, potentially changing the aspect ratio of the source rectangle. |
6716| 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.|
6717| CENTER_SCALE_TO_FIT    | 2    | Scales the source rectangle, preserving its aspect ratio, to align it to the center of the destination rectangle.  |
6718| 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.  |
6719
6720## Matrix<sup>12+</sup>
6721
6722Implements a matrix.
6723
6724A 3 x 3 matrix is shown as below.
6725
6726![matrix_3x3](figures/matrix3X3.PNG)
6727
6728Elements 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.
6729If (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:
6730
6731![matrix_xy](figures/matrix_xy.PNG)
6732
6733### constructor<sup>12+</sup>
6734
6735constructor()
6736
6737Creates a **Matrix** object.
6738
6739**System capability**: SystemCapability.Graphics.Drawing
6740
6741**Example**
6742
6743```ts
6744import { drawing } from '@kit.ArkGraphics2D';
6745
6746let matrix = new drawing.Matrix();
6747```
6748
6749### setRotation<sup>12+</sup>
6750
6751setRotation(degree: number, px: number, py: number): void
6752
6753Sets this matrix as an identity matrix and rotates it by a given degree around the rotation point (px, py).
6754
6755**System capability**: SystemCapability.Graphics.Drawing
6756
6757**Parameters**
6758
6759| Name        | Type                                      | Mandatory  | Description                 |
6760| ----------- | ---------------------------------------- | ---- | ------------------- |
6761| 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.|
6762| px          | number                  | Yes   | X coordinate of the rotation point. The value is a floating point number.    |
6763| py          | number                  | Yes   | Y coordinate of the rotation point. The value is a floating point number.    |
6764
6765**Error codes**
6766
6767For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6768
6769| ID| Error Message|
6770| ------- | --------------------------------------------|
6771| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6772
6773**Example**
6774
6775```ts
6776import { drawing } from '@kit.ArkGraphics2D';
6777
6778let matrix = new drawing.Matrix();
6779matrix.setRotation(90, 100, 100);
6780```
6781
6782### setScale<sup>12+</sup>
6783
6784setScale(sx: number, sy: number, px: number, py: number): void
6785
6786Sets this matrix as an identity matrix and scales it with the coefficients (sx, sy) at the rotation point (px, py).
6787
6788**System capability**: SystemCapability.Graphics.Drawing
6789
6790**Parameters**
6791
6792| Name        | Type                                      | Mandatory  | Description                 |
6793| ----------- | ---------------------------------------- | ---- | ------------------- |
6794| 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.    |
6795| 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.    |
6796| px          | number                  | Yes   |  X coordinate of the rotation point. The value is a floating point number.     |
6797| py          | number                  | Yes   |  Y coordinate of the rotation point. The value is a floating point number.     |
6798
6799**Error codes**
6800
6801For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6802
6803| ID| Error Message|
6804| ------- | --------------------------------------------|
6805| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6806
6807**Example**
6808
6809```ts
6810import { drawing } from '@kit.ArkGraphics2D';
6811
6812let matrix = new drawing.Matrix();
6813matrix.setScale(100, 100, 150, 150);
6814```
6815
6816### setTranslation<sup>12+</sup>
6817
6818setTranslation(dx: number, dy: number): void
6819
6820Sets this matrix as an identity matrix and translates it by a given distance (dx, dy).
6821
6822**System capability**: SystemCapability.Graphics.Drawing
6823
6824**Parameters**
6825
6826| Name        | Type                                      | Mandatory  | Description                 |
6827| ----------- | ---------------------------------------- | ---- | ------------------- |
6828| 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.    |
6829| 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.    |
6830
6831**Error codes**
6832
6833For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6834
6835| ID| Error Message|
6836| ------- | --------------------------------------------|
6837| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6838
6839**Example**
6840
6841```ts
6842import { drawing } from '@kit.ArkGraphics2D';
6843
6844let matrix = new drawing.Matrix();
6845matrix.setTranslation(100, 100);
6846```
6847
6848### setMatrix<sup>12+</sup>
6849
6850setMatrix(values: Array\<number>): void
6851
6852Sets parameters for this matrix.
6853
6854**System capability**: SystemCapability.Graphics.Drawing
6855
6856**Parameters**
6857
6858| Name| Type                                                | Mandatory| Description            |
6859| ------ | ---------------------------------------------------- | ---- | ---------------- |
6860| 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.|
6861
6862**Error codes**
6863
6864For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6865
6866| ID| Error Message|
6867| ------- | --------------------------------------------|
6868| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; 3. Parameter verification failed. |
6869
6870**Example**
6871
6872```ts
6873import { drawing } from '@kit.ArkGraphics2D';
6874
6875let matrix = new drawing.Matrix();
6876let value : Array<number> = [2, 2, 2, 2, 2, 2, 2, 2, 2];
6877matrix.setMatrix(value);
6878```
6879
6880### preConcat<sup>12+</sup>
6881
6882preConcat(matrix: Matrix): void
6883
6884Preconcats the existing matrix with the passed-in matrix.
6885
6886**System capability**: SystemCapability.Graphics.Drawing
6887
6888**Parameters**
6889
6890| Name| Type                                                | Mandatory| Description            |
6891| ------ | ---------------------------------------------------- | ---- | ---------------- |
6892| matrix  | [Matrix](#matrix12) | Yes  | **Matrix** object, which is on the right of a multiplication expression.|
6893
6894**Error codes**
6895
6896For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6897
6898| ID| Error Message|
6899| ------- | --------------------------------------------|
6900| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6901
6902**Example**
6903
6904```ts
6905import { drawing } from '@kit.ArkGraphics2D';
6906
6907let matrix1 = new drawing.Matrix();
6908matrix1.setMatrix([2, 1, 3, 1, 2, 1, 3, 1, 2]);
6909let matrix2 = new drawing.Matrix();
6910matrix2.setMatrix([-2, 1, 3, 1, 0, -1, 3, -1, 2]);
6911matrix1.preConcat(matrix2);
6912```
6913
6914### isEqual<sup>12+</sup>
6915
6916isEqual(matrix: Matrix): Boolean
6917
6918Checks whether this matrix is equal to another matrix.
6919
6920**System capability**: SystemCapability.Graphics.Drawing
6921
6922**Parameters**
6923
6924| Name| Type                                                | Mandatory| Description            |
6925| ------ | ---------------------------------------------------- | ---- | ---------------- |
6926| matrix  | [Matrix](#matrix12) | Yes  | Matrix to compare.|
6927
6928**Return value**
6929
6930| Type                       | Description                 |
6931| --------------------------- | -------------------- |
6932| Boolean | Comparison result of the two matrices. The value **true** means that the two matrices are equal, and **false** means the opposite.|
6933
6934**Error codes**
6935
6936For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6937
6938| ID| Error Message|
6939| ------- | --------------------------------------------|
6940| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6941
6942**Example**
6943
6944```ts
6945import { drawing } from '@kit.ArkGraphics2D';
6946
6947let matrix1 = new drawing.Matrix();
6948matrix1.setMatrix([2, 1, 3, 1, 2, 1, 3, 1, 2]);
6949let matrix2 = new drawing.Matrix();
6950matrix2.setMatrix([-2, 1, 3, 1, 0, -1, 3, -1, 2]);
6951if (matrix1.isEqual(matrix2)) {
6952  console.info("matrix1 and matrix2 are equal.");
6953} else {
6954  console.info("matrix1 and matrix2 are not equal.");
6955}
6956```
6957
6958### invert<sup>12+</sup>
6959
6960invert(matrix: Matrix): Boolean
6961
6962Inverts this matrix and returns the result.
6963
6964**System capability**: SystemCapability.Graphics.Drawing
6965
6966**Parameters**
6967
6968| Name| Type                                                | Mandatory| Description            |
6969| ------ | ---------------------------------------------------- | ---- | ---------------- |
6970| matrix  | [Matrix](#matrix12) | Yes  | **Matrix** object used to store the inverted matrix.|
6971
6972**Return value**
6973
6974| Type                       | Description                 |
6975| --------------------------- | -------------------- |
6976| 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).|
6977
6978**Error codes**
6979
6980For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
6981
6982| ID| Error Message|
6983| ------- | --------------------------------------------|
6984| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
6985
6986**Example**
6987
6988```ts
6989import { drawing } from '@kit.ArkGraphics2D';
6990
6991let matrix1 = new drawing.Matrix();
6992matrix1.setMatrix([2, 1, 3, 1, 2, 1, 3, 1, 2]);
6993let matrix2 = new drawing.Matrix();
6994matrix2.setMatrix([-2, 1, 3, 1, 0, -1, 3, -1, 2]);
6995if (matrix1.invert(matrix2)) {
6996  console.info("matrix1 is invertible and matrix2 is set as an inverse matrix of the matrix1.");
6997} else {
6998  console.info("matrix1 is not invertible and matrix2 is not changed.");
6999}
7000```
7001
7002### isIdentity<sup>12+</sup>
7003
7004isIdentity(): Boolean
7005
7006Checks whether this matrix is an identity matrix.
7007
7008**System capability**: SystemCapability.Graphics.Drawing
7009
7010**Return value**
7011
7012| Type                       | Description                 |
7013| --------------------------- | -------------------- |
7014| 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.|
7015
7016**Example**
7017
7018```ts
7019import { drawing } from '@kit.ArkGraphics2D';
7020
7021let matrix = new drawing.Matrix();
7022if (matrix.isIdentity()) {
7023  console.info("matrix is identity.");
7024} else {
7025  console.info("matrix is not identity.");
7026}
7027```
7028
7029### getValue<sup>12+</sup>
7030
7031getValue(index: number): number
7032
7033Obtains the value of a given index in this matrix. The index ranges from 0 to 8.
7034
7035**System capability**: SystemCapability.Graphics.Drawing
7036
7037**Parameters**
7038
7039| Name         | Type   | Mandatory| Description                                                       |
7040| --------------- | ------- | ---- | ----------------------------------------------------------- |
7041| index | number | Yes  | Index. The value is an integer ranging from 0 to 8.|
7042
7043**Return value**
7044
7045| Type                 | Description          |
7046| --------------------- | -------------- |
7047| number | Value obtained, which is an integer.|
7048
7049**Error codes**
7050
7051For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7052
7053| ID| Error Message|
7054| ------- | --------------------------------------------|
7055| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types;3. Parameter verification failed.|
7056
7057**Example**
7058
7059```ts
7060import {drawing} from "@kit.ArkGraphics2D"
7061let matrix = new drawing.Matrix();
7062for (let i = 0; i < 9; i++) {
7063    console.info("matrix "+matrix.getValue(i).toString());
7064}
7065```
7066
7067### postRotate<sup>12+</sup>
7068
7069postRotate(degree: number, px: number, py: number): void
7070
7071Post 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).
7072
7073**System capability**: SystemCapability.Graphics.Drawing
7074
7075**Parameters**
7076
7077| Name         | Type   | Mandatory| Description                                                       |
7078| --------------- | ------- | ---- | ----------------------------------------------------------- |
7079| 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.|
7080| px | number | Yes  | X coordinate of the rotation point. The value is a floating point number.|
7081| py | number | Yes  | Y coordinate of the rotation point. The value is a floating point number.|
7082
7083**Error codes**
7084
7085For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7086
7087| ID| Error Message|
7088| ------- | --------------------------------------------|
7089| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7090
7091**Example**
7092
7093```ts
7094import {drawing} from "@kit.ArkGraphics2D"
7095let matrix = new drawing.Matrix();
7096let degree: number = 2;
7097let px: number = 3;
7098let py: number = 4;
7099matrix.postRotate(degree, px, py);
7100console.info("matrix= "+matrix.getAll().toString());
7101```
7102
7103### postScale<sup>12+</sup>
7104
7105postScale(sx: number, sy: number, px: number, py: number): void
7106
7107Post 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).
7108
7109**System capability**: SystemCapability.Graphics.Drawing
7110
7111**Parameters**
7112
7113| Name         | Type   | Mandatory| Description                                                       |
7114| --------------- | ------- | ---- | ----------------------------------------------------------- |
7115| 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.|
7116| 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.|
7117| px | number | Yes  | X coordinate of the scale point. The value is a floating point number.|
7118| py | number | Yes  | Y coordinate of the scale point. The value is a floating point number.|
7119
7120**Error codes**
7121
7122For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7123
7124| ID| Error Message|
7125| ------- | --------------------------------------------|
7126| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7127
7128**Example**
7129
7130```ts
7131import {drawing} from "@kit.ArkGraphics2D"
7132let matrix = new drawing.Matrix();
7133let sx: number = 2;
7134let sy: number = 0.5;
7135let px: number = 1;
7136let py: number = 1;
7137matrix.postScale(sx, sy, px, py);
7138console.info("matrix= "+matrix.getAll().toString());
7139```
7140
7141### postTranslate<sup>12+</sup>
7142
7143postTranslate(dx: number, dy: number): void
7144
7145Post multiplies this matrix by a matrix that is derived from an identity matrix after it has been translated by a given distance (dx, dy).
7146
7147**System capability**: SystemCapability.Graphics.Drawing
7148
7149**Parameters**
7150
7151| Name         | Type   | Mandatory| Description                                                       |
7152| --------------- | ------- | ---- | ----------------------------------------------------------- |
7153| 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.|
7154| 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.|
7155
7156**Error codes**
7157
7158For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7159
7160| ID| Error Message|
7161| ------- | --------------------------------------------|
7162| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7163
7164**Example**
7165
7166```ts
7167import {drawing} from "@kit.ArkGraphics2D"
7168let matrix = new drawing.Matrix();
7169let dx: number = 3;
7170let dy: number = 4;
7171matrix.postTranslate(dx, dy);
7172console.info("matrix= "+matrix.getAll().toString());
7173```
7174
7175### preRotate<sup>12+</sup>
7176
7177preRotate(degree: number, px: number, py: number): void
7178
7179Premultiplies 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).
7180
7181**System capability**: SystemCapability.Graphics.Drawing
7182
7183**Parameters**
7184
7185| Name         | Type   | Mandatory| Description                                                       |
7186| --------------- | ------- | ---- | ----------------------------------------------------------- |
7187| 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.|
7188| px | number | Yes  | X coordinate of the rotation point. The value is a floating point number.|
7189| py | number | Yes  | Y coordinate of the rotation point. The value is a floating point number.|
7190
7191**Error codes**
7192
7193For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7194
7195| ID| Error Message|
7196| ------- | --------------------------------------------|
7197| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7198
7199**Example**
7200
7201```ts
7202import {drawing} from "@kit.ArkGraphics2D"
7203let matrix = new drawing.Matrix();
7204let degree: number = 2;
7205let px: number = 3;
7206let py: number = 4;
7207matrix.preRotate(degree, px, py);
7208console.info("matrix= "+matrix.getAll().toString());
7209```
7210
7211### preScale<sup>12+</sup>
7212
7213preScale(sx: number, sy: number, px: number, py: number): void
7214
7215Premultiplies 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).
7216
7217**System capability**: SystemCapability.Graphics.Drawing
7218
7219**Parameters**
7220
7221| Name         | Type   | Mandatory| Description                                                       |
7222| --------------- | ------- | ---- | ----------------------------------------------------------- |
7223| 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.|
7224| 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.|
7225| px | number | Yes  | X coordinate of the scale point. The value is a floating point number.|
7226| py | number | Yes  | Y coordinate of the scale point. The value is a floating point number.|
7227
7228**Error codes**
7229
7230For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7231
7232| ID| Error Message|
7233| ------- | --------------------------------------------|
7234| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7235
7236**Example**
7237
7238```ts
7239import {drawing} from "@kit.ArkGraphics2D"
7240let matrix = new drawing.Matrix();
7241let sx: number = 2;
7242let sy: number = 0.5;
7243let px: number = 1;
7244let py: number = 1;
7245matrix.preScale(sx, sy, px, py);
7246console.info("matrix"+matrix.getAll().toString());
7247```
7248
7249### preTranslate<sup>12+</sup>
7250
7251preTranslate(dx: number, dy: number): void
7252
7253Premultiplies a matrix by a matrix that is derived from an identity matrix after it has been translated by a given distance (dx, dy).
7254
7255**System capability**: SystemCapability.Graphics.Drawing
7256
7257**Parameters**
7258
7259| Name         | Type   | Mandatory| Description                                                       |
7260| --------------- | ------- | ---- | ----------------------------------------------------------- |
7261| 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.|
7262| 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.|
7263
7264**Error codes**
7265
7266For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7267
7268| ID| Error Message|
7269| ------- | --------------------------------------------|
7270| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7271
7272**Example**
7273
7274```ts
7275import {drawing} from "@kit.ArkGraphics2D"
7276let matrix = new drawing.Matrix();
7277let dx: number = 3;
7278let dy: number = 4;
7279matrix.preTranslate(dx, dy);
7280console.info("matrix"+matrix.getAll().toString());
7281```
7282
7283### reset<sup>12+</sup>
7284
7285reset(): void
7286
7287Resets this matrix to an identity matrix.
7288
7289**System capability**: SystemCapability.Graphics.Drawing
7290
7291**Example**
7292
7293```ts
7294import {drawing} from "@kit.ArkGraphics2D"
7295let matrix = new drawing.Matrix();
7296matrix.postScale(2, 3, 4, 5);
7297matrix.reset();
7298console.info("matrix= "+matrix.getAll().toString());
7299```
7300
7301### mapPoints<sup>12+</sup>
7302
7303mapPoints(src: Array\<common2D.Point>): Array\<common2D.Point>
7304
7305Maps a source point array to a destination point array by means of matrix transformation.
7306
7307**System capability**: SystemCapability.Graphics.Drawing
7308
7309**Parameters**
7310
7311| Name         | Type   | Mandatory| Description                                                       |
7312| --------------- | ------- | ---- | ----------------------------------------------------------- |
7313| src | Array\<[common2D.Point](js-apis-graphics-common2D.md#point)> | Yes  | Array of source points.|
7314
7315**Return value**
7316
7317| Type                 | Description          |
7318| --------------------- | -------------- |
7319| Array\<[common2D.Point](js-apis-graphics-common2D.md#point)> | Array of points obtained.|
7320
7321**Error codes**
7322
7323For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7324
7325| ID| Error Message|
7326| ------- | --------------------------------------------|
7327| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7328
7329**Example**
7330
7331```ts
7332import {drawing,common2D} from "@kit.ArkGraphics2D"
7333let src: Array<common2D.Point> = [];
7334src.push({x: 15, y: 20});
7335src.push({x: 20, y: 15});
7336src.push({x: 30, y: 10});
7337let matrix = new drawing.Matrix();
7338let dst: Array<common2D.Point> = matrix.mapPoints(src);
7339console.info("matrix= src: "+JSON.stringify(src));
7340console.info("matrix= dst: "+JSON.stringify(dst));
7341```
7342
7343### getAll<sup>12+</sup>
7344
7345getAll(): Array\<number>
7346
7347Obtains all element values of this matrix.
7348
7349**System capability**: SystemCapability.Graphics.Drawing
7350
7351**Return value**
7352
7353| Type                 | Description          |
7354| --------------------- | -------------- |
7355| Array\<number> | Array of matrix values obtained. The length is 9. Each value is a floating point number.|
7356
7357**Example**
7358
7359```ts
7360import {drawing} from "@kit.ArkGraphics2D"
7361let matrix = new drawing.Matrix();
7362console.info("matrix "+ matrix.getAll());
7363```
7364
7365### mapRect<sup>12+</sup>
7366
7367mapRect(dst: common2D.Rect, src: common2D.Rect): boolean
7368
7369Sets 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.
7370
7371![mapRect](./figures/matrix_mapRect.png)
7372
7373**System capability**: SystemCapability.Graphics.Drawing
7374
7375**Parameters**
7376
7377| Name         | Type   | Mandatory| Description                                                       |
7378| --------------- | ------- | ---- | ----------------------------------------------------------- |
7379| dst | [common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes  | **Rectangle** object, which is used to store the bounding rectangle.|
7380| src |[common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes  | Source rectangle.|
7381
7382**Return value**
7383
7384| Type                 | Description          |
7385| --------------------- | -------------- |
7386| 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.|
7387
7388**Error codes**
7389
7390For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7391
7392| ID| Error Message|
7393| ------- | --------------------------------------------|
7394| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7395
7396**Example**
7397
7398```ts
7399import {drawing,common2D} from "@kit.ArkGraphics2D"
7400let dst: common2D.Rect = { left: 100, top: 20, right: 130, bottom: 60 };
7401let src: common2D.Rect = { left: 100, top: 80, right: 130, bottom: 120 };
7402let matrix = new drawing.Matrix();
7403if (matrix.mapRect(dst, src)) {
7404    console.info("matrix= dst "+JSON.stringify(dst));
7405}
7406```
7407
7408### setRectToRect<sup>12+</sup>
7409
7410setRectToRect(src: common2D.Rect, dst: common2D.Rect, scaleToFit: ScaleToFit): boolean
7411
7412Sets this matrix to a transformation matrix that maps a source rectangle to a destination rectangle.
7413
7414**System capability**: SystemCapability.Graphics.Drawing
7415
7416**Parameters**
7417
7418| Name         | Type   | Mandatory| Description                                                       |
7419| --------------- | ------- | ---- | ----------------------------------------------------------- |
7420| src | [common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes  | Source rectangle.|
7421| dst | [common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes  | Destination rectangle.|
7422| scaleToFit | [ScaleToFit](#scaletofit12) | Yes  | Mapping mode from the source rectangle to the target rectangle.|
7423
7424**Return value**
7425
7426| Type                 | Description          |
7427| --------------------- | -------------- |
7428| 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.|
7429
7430**Error codes**
7431
7432For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7433
7434| ID| Error Message|
7435| ------- | --------------------------------------------|
7436| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
7437
7438**Example**
7439
7440```ts
7441import {drawing,common2D} from "@kit.ArkGraphics2D"
7442let src: common2D.Rect = { left: 100, top: 100, right: 300, bottom: 300 };
7443let dst: common2D.Rect = { left: 200, top: 200, right: 600, bottom: 600 };
7444let scaleToFit: drawing.ScaleToFit = drawing.ScaleToFit.FILL_SCALE_TO_FIT
7445let matrix = new drawing.Matrix();
7446if (matrix.setRectToRect(src, dst, scaleToFit)) {
7447    console.info("matrix"+matrix.getAll().toString());
7448}
7449```
7450
7451### setPolyToPoly<sup>12+</sup>
7452
7453setPolyToPoly(src: Array\<common2D.Point>, dst: Array\<common2D.Point>, count: number): boolean
7454
7455Sets this matrix to a transformation matrix that maps the source point array to the destination point array.
7456
7457**System capability**: SystemCapability.Graphics.Drawing
7458
7459**Parameters**
7460
7461| Name         | Type   | Mandatory| Description                                                       |
7462| --------------- | ------- | ---- | ----------------------------------------------------------- |
7463| 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**.|
7464| 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**.|
7465| count | number | Yes  | Number of points in each array. The value is an integer.|
7466
7467**Return value**
7468
7469| Type                 | Description          |
7470| --------------------- | -------------- |
7471| boolean | Result indicating whether the setting is successful. The value **true** means that the setting is successful, and **false** means the opposite.|
7472
7473**Error codes**
7474
7475For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7476
7477| ID| Error Message|
7478| ------- | --------------------------------------------|
7479| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7480
7481**Example**
7482
7483```ts
7484import {drawing,common2D} from "@kit.ArkGraphics2D"
7485let srcPoints: Array<common2D.Point> = [ {x: 10, y: 20}, {x: 200, y: 150} ];
7486let dstPoints: Array<common2D.Point> = [{ x:0, y: 10 }, { x:300, y: 600 }];
7487let matrix = new drawing.Matrix();
7488if (matrix.setPolyToPoly(srcPoints, dstPoints, 2)) {
7489    console.info("matrix"+matrix.getAll().toString());
7490}
7491```
7492
7493## RoundRect<sup>12+</sup>
7494
7495Implements a rounded rectangle.
7496
7497### constructor<sup>12+</sup>
7498
7499constructor(rect: common2D.Rect, xRadii: number, yRadii: number)
7500
7501A 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.
7502
7503**System capability**: SystemCapability.Graphics.Drawing
7504
7505**Parameters**
7506
7507| Name        | Type                                      | Mandatory  | Description                 |
7508| ----------- | ---------------------------------------- | ---- | ------------------- |
7509| rect        | [common2D.Rect](js-apis-graphics-common2D.md#rect) | Yes   | Rectangle that encloses the rounded rectangle to create.     |
7510| xRadii        | number                  | Yes   | Radius of the rounded corner on the X axis. The value is a floating point number. A negative number is invalid.    |
7511| yRadii        | number                  | Yes   | Radius of the rounded corner on the Y axis. The value is a floating point number. A negative number is invalid.    |
7512
7513**Error codes**
7514
7515For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7516
7517| ID| Error Message|
7518| ------- | --------------------------------------------|
7519| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7520
7521**Example**
7522
7523```ts
7524import { common2D, drawing } from '@kit.ArkGraphics2D';
7525
7526let rect: common2D.Rect = {left : 100, top : 100, right : 500, bottom : 300};
7527let roundRect = new drawing.RoundRect(rect, 50, 50);
7528```
7529### setCorner<sup>12+</sup>
7530
7531setCorner(pos: CornerPos, x: number, y: number): void
7532
7533Sets the radii of the specified rounded corner in this rounded rectangle.
7534
7535**System capability**: SystemCapability.Graphics.Drawing
7536
7537**Parameters**
7538
7539| Name  | Type                                        | Mandatory| Description                           |
7540| -------- | -------------------------------------------- | ---- | ------------------------------- |
7541| pos | [CornerPos](#cornerpos12) | Yes  | Position of the rounded corner.                |
7542| x     | number                 | Yes  | Radius of the rounded corner on the X axis. The value is a floating point number.|
7543| y     | number      | Yes  | Radius of the rounded corner on the Y axis. The value is a floating point number.|
7544
7545**Error codes**
7546
7547For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7548
7549| ID| Error Message|
7550| ------- | --------------------------------------------|
7551| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
7552
7553**Example**
7554
7555```ts
7556import { drawing } from '@kit.ArkGraphics2D';
7557let roundRect : drawing.RoundRect = new drawing.RoundRect({left: 0, top: 0, right: 300, bottom: 300}, 50, 50);
7558roundRect.setCorner(drawing.CornerPos.TOP_LEFT_POS, 150, 150);
7559```
7560
7561### getCorner<sup>12+</sup>
7562
7563getCorner(pos: CornerPos): common2D.Point
7564
7565Obtains the radii of the specified rounded corner in this rounded rectangle.
7566
7567**System capability**: SystemCapability.Graphics.Drawing
7568
7569**Parameters**
7570
7571| Name  | Type                                        | Mandatory| Description                           |
7572| -------- | -------------------------------------------- | ---- | ------------------------------- |
7573| pos | [CornerPos](#cornerpos12) | Yes  | Position of the rounded corner.                |
7574
7575**Return value**
7576
7577| Type                 | Description          |
7578| --------------------- | -------------- |
7579| [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.|
7580
7581**Error codes**
7582
7583For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7584
7585| ID| Error Message|
7586| ------- | --------------------------------------------|
7587| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types;3.Parameter verification failed. |
7588
7589**Example**
7590
7591```ts
7592import { drawing } from '@kit.ArkGraphics2D';
7593let roundRect : drawing.RoundRect = new drawing.RoundRect({left: 0, top: 0, right: 300, bottom: 300}, 50, 50);
7594let cornerRadius = roundRect.getCorner(drawing.CornerPos.BOTTOM_LEFT_POS);
7595console.info("getCorner---"+cornerRadius.x)
7596console.info("getCorner---"+cornerRadius.y)
7597```
7598
7599### offset<sup>12+</sup>
7600
7601offset(dx: number, dy: number): void
7602
7603Translates this rounded rectangle by an offset along the X axis and Y axis.
7604
7605**System capability**: SystemCapability.Graphics.Drawing
7606
7607**Parameters**
7608
7609| Name  | Type                                        | Mandatory| Description                           |
7610| -------- | -------------------------------------------- | ---- | ------------------------------- |
7611| 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.                |
7612| 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.                |
7613
7614**Error codes**
7615
7616For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7617
7618| ID| Error Message|
7619| ------- | --------------------------------------------|
7620| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7621
7622**Example**
7623
7624```ts
7625import { drawing } from '@kit.ArkGraphics2D';
7626let roundRect : drawing.RoundRect = new drawing.RoundRect({left: 0, top: 0, right: 300, bottom: 300}, 50, 50);
7627roundRect.offset(100, 100);
7628```
7629
7630## Region<sup>12+</sup>
7631
7632Describes a region, which is used to describe the region where the shape can be drawn.
7633
7634### isPointContained<sup>12+</sup>
7635
7636isPointContained(x: number, y: number) : boolean
7637
7638Checks whether a point is contained in this region.
7639
7640**System capability**: SystemCapability.Graphics.Drawing
7641
7642**Parameters**
7643
7644| Name| Type  | Mandatory| Description                   |
7645| ------ | ------ | ---- | ----------------------- |
7646| 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.|
7647| 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.|
7648
7649**Return value**
7650
7651| Type   | Description          |
7652| ------- | -------------- |
7653| 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.|
7654
7655**Error codes**
7656
7657For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7658
7659| ID| Error Message|
7660| ------- | --------------------------------------------|
7661| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7662
7663**Example**
7664
7665```ts
7666import { RenderNode } from '@kit.ArkUI';
7667class DrawingRenderNode extends RenderNode {
7668  draw(context : DrawContext) {
7669    const canvas = context.canvas;
7670    const pen = new drawing.Pen();
7671    pen.setColor({ alpha: 255, red: 255, green: 0, blue: 0 });
7672    pen.setStrokeWidth(10);
7673    canvas.attachPen(pen);
7674    let region = new drawing.Region();
7675    region.setRect(100, 100, 400, 400);
7676    let flag: boolean = false;
7677    flag = region.isPointContained(200,200);
7678    console.info("region isPointContained : " + flag);
7679    canvas.drawPoint(200,200);
7680    canvas.drawRegion(region);
7681    canvas.detachPen();
7682  }
7683}
7684```
7685
7686### isRegionContained<sup>12+</sup>
7687
7688isRegionContained(other: Region) : boolean
7689
7690Checks whether another region is contained in this region.
7691
7692**System capability**: SystemCapability.Graphics.Drawing
7693
7694**Parameters**
7695
7696| Name| Type  | Mandatory| Description                   |
7697| ------ | ------ | ---- | ----------------------- |
7698| other      | [Region](#region12) | Yes  | **Region** object.|
7699
7700**Return value**
7701
7702| Type   | Description          |
7703| ------- | -------------- |
7704| 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.|
7705
7706**Error codes**
7707
7708For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7709
7710| ID| Error Message|
7711| ------- | --------------------------------------------|
7712| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7713
7714**Example**
7715
7716```ts
7717import { RenderNode } from '@kit.ArkUI';
7718class DrawingRenderNode extends RenderNode {
7719  draw(context : DrawContext) {
7720    const canvas = context.canvas;
7721    const pen = new drawing.Pen();
7722    pen.setColor({ alpha: 255, red: 255, green: 0, blue: 0 });
7723    pen.setStrokeWidth(10);
7724    canvas.attachPen(pen);
7725    let region = new drawing.Region();
7726    let other = new drawing.Region();
7727    region.setRect(100, 100, 400, 400);
7728    other.setRect(150, 150, 250 ,250);
7729    let flag: boolean = false;
7730    flag = region.isRegionContained(other);
7731    console.info("region isRegionContained : " + flag);
7732    canvas.drawRegion(region);
7733    canvas.drawRegion(other);
7734    canvas.detachPen();
7735  }
7736}
7737```
7738
7739### op<sup>12+</sup>
7740
7741op(region: Region, regionOp: RegionOp) : boolean
7742
7743Performs an operation on this region and another region, and stores the resulting region in this **Region** object.
7744
7745**System capability**: SystemCapability.Graphics.Drawing
7746
7747**Parameters**
7748
7749| Name| Type  | Mandatory| Description                   |
7750| ------ | ------ | ---- | ----------------------- |
7751| region      | [Region](#region12) | Yes  | **Region** object.|
7752| regionOp      | [RegionOp](#regionop12) | Yes  | Operation mode of the region.|
7753
7754**Return value**
7755
7756| Type   | Description          |
7757| ------- | -------------- |
7758| 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.|
7759
7760**Error codes**
7761
7762For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7763
7764| ID| Error Message|
7765| ------- | --------------------------------------------|
7766| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7767
7768**Example**
7769
7770```ts
7771import { RenderNode } from '@kit.ArkUI';
7772class DrawingRenderNode extends RenderNode {
7773  draw(context : DrawContext) {
7774    const canvas = context.canvas;
7775    const pen = new drawing.Pen();
7776    pen.setColor({ alpha: 255, red: 255, green: 0, blue: 0 });
7777    pen.setStrokeWidth(10);
7778    canvas.attachPen(pen);
7779    let region = new drawing.Region();
7780    region.setRect(200, 200, 400, 400);
7781    let othregion = new drawing.Region();
7782    othregion.setRect(110, 110, 240, 240);
7783    let flag: boolean = false;
7784    flag = region.op(othregion,drawing.RegionOp.REPLACE);
7785    console.info("region op : " + flag);
7786    canvas.drawRegion(region);
7787    canvas.detachPen();
7788  }
7789}
7790```
7791
7792### quickReject<sup>12+</sup>
7793
7794quickReject(left: number, top: number, right: number, bottom: number) : boolean
7795
7796Checks 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.
7797
7798**System capability**: SystemCapability.Graphics.Drawing
7799
7800**Parameters**
7801
7802| Name| Type  | Mandatory| Description                   |
7803| ------ | ------ | ---- | ----------------------- |
7804| 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.|
7805| 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.|
7806| 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.|
7807| 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.|
7808
7809**Return value**
7810
7811| Type   | Description          |
7812| ------- | -------------- |
7813| boolean | Check result. The value **true** means that the two do not intersect, and **false** means the opposite.|
7814
7815**Error codes**
7816
7817For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7818
7819| ID| Error Message|
7820| ------- | --------------------------------------------|
7821| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7822
7823**Example**
7824
7825```ts
7826import { RenderNode } from '@kit.ArkUI';
7827class DrawingRenderNode extends RenderNode {
7828  draw(context : DrawContext) {
7829    const canvas = context.canvas;
7830    const pen = new drawing.Pen();
7831    pen.setColor({ alpha: 255, red: 255, green: 0, blue: 0 });
7832    pen.setStrokeWidth(10);
7833    canvas.attachPen(pen);
7834    let region = new drawing.Region();
7835    region.setRect(100, 100, 400, 400);
7836    let flag: boolean = false;
7837    flag = region.quickReject(50, 50, 70, 70);
7838    console.info("region quickReject : " + flag);
7839    canvas.drawRegion(region);
7840    canvas.detachPen();
7841  }
7842}
7843```
7844
7845### setPath<sup>12+</sup>
7846
7847setPath(path: Path, clip: Region) : boolean
7848
7849Sets a region that matches the outline of a path within the cropping area.
7850
7851**System capability**: SystemCapability.Graphics.Drawing
7852
7853**Parameters**
7854
7855| Name| Type  | Mandatory| Description                   |
7856| ------ | ------ | ---- | ----------------------- |
7857| path      | [Path](#path) | Yes  | **Path** object.|
7858| clip      | [Region](#region12) | Yes  | **Region** object.|
7859
7860**Return value**
7861
7862| Type   | Description          |
7863| ------- | -------------- |
7864| boolean | Result of the setting operation. The value **true** means that the setting is successful, and **false** means the opposite.|
7865
7866**Error codes**
7867
7868For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7869
7870| ID| Error Message|
7871| ------- | --------------------------------------------|
7872| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7873
7874**Example**
7875
7876```ts
7877import { RenderNode } from '@kit.ArkUI';
7878class DrawingRenderNode extends RenderNode {
7879  draw(context : DrawContext) {
7880    const canvas = context.canvas;
7881    const pen = new drawing.Pen();
7882    pen.setColor({ alpha: 255, red: 255, green: 0, blue: 0 });
7883    pen.setStrokeWidth(10);
7884    canvas.attachPen(pen);
7885    let region = new drawing.Region();
7886    let path = new drawing.Path();
7887    region.setRect(100, 100, 400, 400);
7888    path.arcTo(50, 50, 300, 300, 0, 359);
7889    let flag: boolean = false;
7890    flag = region.setPath(path,region);
7891    console.info("region setPath : " + flag);
7892    canvas.drawRegion(region);
7893    canvas.detachPen();
7894  }
7895}
7896```
7897
7898### setRect<sup>12+</sup>
7899
7900setRect(left: number, top: number, right: number, bottom: number) : boolean
7901
7902Sets a rectangle.
7903
7904**System capability**: SystemCapability.Graphics.Drawing
7905
7906**Parameters**
7907
7908| Name| Type  | Mandatory| Description                   |
7909| ------ | ------ | ---- | ----------------------- |
7910| 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.|
7911| 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.|
7912| 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.|
7913| 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.|
7914
7915**Return value**
7916
7917| Type   | Description          |
7918| ------- | -------------- |
7919| boolean | Result of the setting operation. The value **true** means that the setting is successful, and **false** means the opposite.|
7920
7921**Error codes**
7922
7923For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7924
7925| ID| Error Message|
7926| ------- | --------------------------------------------|
7927| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7928
7929**Example**
7930
7931```ts
7932import { RenderNode } from '@kit.ArkUI';
7933class DrawingRenderNode extends RenderNode {
7934  draw(context : DrawContext) {
7935    const canvas = context.canvas;
7936    const pen = new drawing.Pen();
7937    pen.setColor({ alpha: 255, red: 255, green: 0, blue: 0 });
7938    pen.setStrokeWidth(10);
7939    canvas.attachPen(pen);
7940    let region = new drawing.Region();
7941    let flag: boolean = false;
7942    flag = region.setRect(50, 50, 300, 300);
7943    console.info("region setRect : " + flag);
7944    canvas.drawRegion(region);
7945    canvas.detachPen();
7946  }
7947}
7948```
7949
7950## TileMode<sup>12+</sup>
7951
7952Enumerates the tile modes of the shader effect.
7953
7954**System capability**: SystemCapability.Graphics.Drawing
7955
7956| Name                  | Value  | Description                          |
7957| ---------------------- | ---- | ------------------------------ |
7958| CLAMP     | 0    | Replicates the edge color if the shader effect draws outside of its original boundary.|
7959| REPEAT    | 1    | Repeats the shader effect in both horizontal and vertical directions.|
7960| MIRROR    | 2    | Repeats the shader effect in both horizontal and vertical directions, alternating mirror images.|
7961| DECAL     | 3    | Renders the shader effect only within the original boundary.|
7962
7963## ShaderEffect<sup>12+</sup>
7964
7965Implements 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.
7966
7967### createColorShader<sup>12+</sup>
7968
7969static createColorShader(color: number): ShaderEffect
7970
7971Creates a **ShaderEffect** object with a single color.
7972
7973**System capability**: SystemCapability.Graphics.Drawing
7974
7975**Parameters**
7976
7977| Name| Type                                              | Mandatory| Description          |
7978| ------ | -------------------------------------------------- | ---- | -------------- |
7979| color   | number | Yes  | Color in the ARGB format. The value is a 32-bit unsigned integer.|
7980
7981**Return value**
7982
7983| Type   | Description                      |
7984| ------- | ------------------------- |
7985| [ShaderEffect](#shadereffect12) | **ShaderEffect** object with a single color.|
7986
7987**Error codes**
7988
7989For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
7990
7991| ID| Error Message|
7992| ------- | --------------------------------------------|
7993| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types. |
7994
7995**Example**
7996
7997```ts
7998import { drawing } from '@kit.ArkGraphics2D';
7999
8000let shaderEffect = drawing.ShaderEffect.createColorShader(0xFFFF0000);
8001```
8002
8003### createLinearGradient<sup>12+</sup>
8004
8005static createLinearGradient(startPt: common2D.Point, endPt: common2D.Point, colors: Array
8006\<number>, mode: TileMode, pos?: Array\<number> | null, matrix?: Matrix | null): ShaderEffect
8007
8008Creates a **ShaderEffect** object that generates a linear gradient between two points.
8009
8010**System capability**: SystemCapability.Graphics.Drawing
8011
8012**Parameters**
8013
8014| Name| Type                                              | Mandatory| Description          |
8015| ------ | -------------------------------------------------- | ---- | -------------- |
8016| startPt  | [common2D.Point](js-apis-graphics-common2D.md#point)  | Yes  | Start point.|
8017| endPt   | [common2D.Point](js-apis-graphics-common2D.md#point)  | Yes  | End point.|
8018| colors | Array\<number> | Yes  | Array of colors to distribute between the two points. The values in the array are 32-bit (ARGB) unsigned integers.|
8019| mode  | [TileMode](#tilemode12) | Yes  | Tile mode of the shader effect.|
8020| 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.|
8021| 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.|
8022
8023![LinearGradient](./figures/image_createLinearGradient.png)
8024
8025The 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.
8026
8027**Return value**
8028
8029| Type   | Description                      |
8030| ------- | ------------------------- |
8031| [ShaderEffect](#shadereffect12) | **ShaderEffect** object created.|
8032
8033**Error codes**
8034
8035For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
8036
8037| ID| Error Message|
8038| ------- | --------------------------------------------|
8039| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; 3. Parameter verification failed. |
8040
8041**Example**
8042
8043```ts
8044import { common2D,drawing } from '@kit.ArkGraphics2D';
8045
8046let startPt: common2D.Point = { x: 100, y: 100 };
8047let endPt: common2D.Point = { x: 300, y: 300 };
8048let shaderEffect =drawing.ShaderEffect.createLinearGradient(startPt, endPt, [0xFF00FF00, 0xFFFF0000], drawing.TileMode.REPEAT);
8049```
8050
8051### createRadialGradient<sup>12+</sup>
8052
8053static createRadialGradient(centerPt: common2D.Point, radius: number, colors: Array\<number>, mode: TileMode, pos?: Array\<number> | null, matrix?: Matrix | null): ShaderEffect;
8054
8055Creates 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.
8056
8057**System capability**: SystemCapability.Graphics.Drawing
8058
8059**Parameters**
8060
8061| Name| Type                                              | Mandatory| Description          |
8062| ------ | -------------------------------------------------- | ---- | -------------- |
8063| centerPt  | [common2D.Point](js-apis-graphics-common2D.md#point)  | Yes  | Center of the circle.|
8064| radius   | number  | Yes  | Radius of the gradient. A negative number is invalid. The value is a floating point number.|
8065| 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.|
8066| mode  | [TileMode](#tilemode12) | Yes  | Tile mode of the shader effect.|
8067| 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.|
8068| 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.|
8069
8070![RadialGradient](./figures/image_createRadialGradient.png)
8071
8072The 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.
8073
8074**Return value**
8075
8076| Type   | Description                      |
8077| ------- | ------------------------- |
8078| [ShaderEffect](#shadereffect12) | **ShaderEffect** object created.|
8079
8080**Error codes**
8081
8082For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
8083
8084| ID| Error Message|
8085| ------- | --------------------------------------------|
8086| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; 3. Parameter verification failed. |
8087
8088**Example**
8089
8090```ts
8091import { common2D,drawing } from '@kit.ArkGraphics2D';
8092
8093let centerPt: common2D.Point = { x: 100, y: 100 };
8094let shaderEffect = drawing.ShaderEffect.createRadialGradient(centerPt, 100, [0xFF00FF00, 0xFFFF0000], drawing.TileMode.REPEAT);
8095```
8096
8097### createSweepGradient<sup>12+</sup>
8098
8099static createSweepGradient(centerPt: common2D.Point, colors: Array\<number>,
8100  mode: TileMode, startAngle: number, endAngle: number, pos?: Array\<number> | null,
8101  matrix?: Matrix | null): ShaderEffect;
8102
8103Creates 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.
8104
8105**System capability**: SystemCapability.Graphics.Drawing
8106
8107**Parameters**
8108
8109| Name| Type                                              | Mandatory| Description          |
8110| ------ | -------------------------------------------------- | ---- | -------------- |
8111| centerPt  | [common2D.Point](js-apis-graphics-common2D.md#point)  | Yes  | Center of the circle.|
8112| 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.|
8113| mode  | [TileMode](#tilemode12) | Yes  | Tile mode of the shader effect.|
8114| 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.|
8115| 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.|
8116| 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.|
8117| 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.|
8118
8119![SweepGradient](./figures/image_createSweepGradient.png)
8120
8121The 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.
8122
8123**Return value**
8124
8125| Type   | Description                      |
8126| ------- | ------------------------- |
8127| [ShaderEffect](#shadereffect12) | **ShaderEffect** object created.|
8128
8129**Error codes**
8130
8131For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
8132
8133| ID| Error Message|
8134| ------- | --------------------------------------------|
8135| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; 3. Parameter verification failed. |
8136
8137**Example**
8138
8139```ts
8140import { common2D,drawing } from '@kit.ArkGraphics2D';
8141
8142let centerPt: common2D.Point = { x: 100, y: 100 };
8143let shaderEffect = drawing.ShaderEffect.createSweepGradient(centerPt, [0xFF00FF00, 0xFFFF0000], drawing.TileMode.REPEAT, 100, 200);
8144```
8145
8146### createConicalGradient<sup>12+</sup>
8147
8148static createConicalGradient(startPt: common2D.Point, startRadius: number, endPt: common2D.Point, endRadius: number, colors: Array\<number>, mode: TileMode, 
8149pos?: Array\<number> | null, matrix?: Matrix | null): ShaderEffect;
8150
8151Creates a **ShaderEffect** object that generates a conical gradient between two given circles.
8152
8153**System capability**: SystemCapability.Graphics.Drawing
8154
8155**Parameters**
8156
8157| Name| Type                                              | Mandatory| Description          |
8158| ------ | -------------------------------------------------- | ---- | -------------- |
8159| startPt  | [common2D.Point](js-apis-graphics-common2D.md#point)  | Yes  |Center of the start circle of the gradient.|
8160| startRadius | number | Yes  | Radius of the start circle of the gradient. A negative number is invalid. The value is a floating point number.|
8161| endPt  | [common2D.Point](js-apis-graphics-common2D.md#point)  | Yes  | Center of the end circle of the gradient.|
8162| endRadius | number | Yes  | Radius of the end circle of the gradient. A negative value is invalid. The value is a floating point number.|
8163| 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.|
8164| mode  | [TileMode](#tilemode12) | Yes  | Tile mode of the shader effect.|
8165| 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.|
8166| 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.|
8167
8168![ConicalGradient](./figures/image_createConicalGradient.png)
8169
8170The 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.
8171
8172**Return value**
8173
8174| Type   | Description                      |
8175| ------- | ------------------------- |
8176| [ShaderEffect](#shadereffect12) | **ShaderEffect** object created.|
8177
8178**Error codes**
8179
8180For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
8181
8182| ID| Error Message|
8183| ------- | --------------------------------------------|
8184| 401 | Parameter error.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types; 3. Parameter verification failed. |
8185
8186**Example**
8187
8188```ts
8189import { common2D,drawing } from '@kit.ArkGraphics2D';
8190
8191let startPt: common2D.Point = { x: 100, y: 100 };
8192let endPt: common2D.Point = {x: 200, y: 200};
8193let shaderEffect = drawing.ShaderEffect.createConicalGradient(startPt, 100, endPt, 50, [0xFF00FF00, 0xFFFF0000], drawing.TileMode.REPEAT);
8194```
8195
8196## RegionOp<sup>12+</sup>
8197
8198Enumerates the operations for combining two regions.
8199
8200**System capability**: SystemCapability.Graphics.Drawing
8201
8202| Name                  | Value  | Description                          | Diagram  |
8203| --------------------- | ---- | ------------------------------ | -------- |
8204| DIFFERENCE         | 0    | Difference operation. | ![CLEAR](./figures/image_RegionOp_Difference.png)|
8205| INTERSECT          | 1    | Intersect operation.| ![INTERSECT](./figures/image_RegionOp_Intersect.png)|
8206| UNION              | 2    | Union operation.  | ![UNION](./figures/image_RegionOpe_Union.png)|
8207| XOR                | 3    | XOR operation.  | ![XOR](./figures/image_RegionOp_Xor.png)|
8208| REVERSE_DIFFERENCE | 4    | Reverse difference operation.  | ![REVERSE_DIFFERENCE](./figures/image_RegionOp_Reverse_difference.png)|
8209| REPLACE            | 5    | Replace operation.  | ![REPLACE](./figures/image_RegionOp_Replace.png)|
8210
8211> **NOTE**
8212>
8213> 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.
8214
8215## CornerPos<sup>12+</sup>
8216
8217Enumerates the corner positions of a rounded rectangle.
8218
8219**System capability**: SystemCapability.Graphics.Drawing
8220
8221| Name                  | Value  | Description                          |
8222| --------------------- | ---- | ------------------------------ | 
8223| TOP_LEFT_POS          | 0    | Top left corner of the rounded rectangle. |
8224| TOP_RIGHT_POS         | 1    | Top right corner of the rounded rectangle.|
8225| BOTTOM_RIGHT_POS      | 2    | Bottom right corner of the rounded rectangle.  |
8226| BOTTOM_LEFT_POS       | 3    | Bottom left corner of the rounded rectangle.  |
8227