1# DrawingRenderingContext
2
3**DrawingRenderingContext** provides a rendering context for drawing rectangles, text, images, and other objects on a canvas.
4
5> **NOTE**
6>
7> This feature is supported since API version 12. Updates will be marked with a superscript to indicate their earliest API version.
8
9## APIs
10
11DrawingRenderingContext(unit?: LengthMetricsUnit)
12
13**Widget capability**: This API can be used in ArkTS widgets since API version 12.
14
15**System capability**: SystemCapability.ArkUI.ArkUI.Full
16
17**Parameters**
18
19| Name     | Type| Mandatory  | Description|
20| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
21| unit<sup>12+</sup>  | [LengthMetricsUnit](../js-apis-arkui-graphics.md#lengthmetricsunit12) | No   | Unit mode of the **DrawingRenderingContext** object. The value cannot be changed once set. The configuration method is the same as that of [CanvasRenderingContext2D](ts-canvasrenderingcontext2d.md#lengthmetricsunit12).<br>Default value: **DEFAULT**|
22
23## Attributes
24
25**Atomic service API**: This API can be used in atomic services since API version 12.
26
27**System capability**: SystemCapability.ArkUI.ArkUI.Full
28
29| Name      | Type| Read Only| Optional| Description|
30| ---------- | ------------ | -------------------- | ---------------------------- | ---------------------------- |
31| size       | [Size](#size)    | No| No| Width and height of the context.<br>Default unit: vp                                           |
32| canvas     | [Canvas](../../apis-arkgraphics2d/js-apis-graphics-drawing.md#canvas) | No| No| **Canvas** object. For details, see [Canvas](../../apis-arkgraphics2d/js-apis-graphics-drawing.md#canvas).|
33
34### Size
35
36**Atomic service API**: This API can be used in atomic services since API version 12.
37
38**System capability**: SystemCapability.ArkUI.ArkUI.Full
39
40| Name| Type| Read Only| Optional| Description|
41| ---------- | -------------- | ------ | ---------------- | ------------------------ |
42| width | number | No| No| Width of the **DrawingRenderingContext** object.|
43| height | number | No| No| Height of the **DrawingRenderingContext** object.|
44
45## Methods
46
47### invalidate
48
49invalidate(): void
50
51**Atomic service API**: This API can be used in atomic services since API version 12.
52
53**System capability**: SystemCapability.ArkUI.ArkUI.Full
54
55Invalidates the component and triggers re-rendering of the component.
56
57**Example**
58
59This example shows how to use the APIs in **DrawingRenderingContext** for drawing.
60
61```ts
62// xxx.ets
63@Entry
64@Component
65struct CanvasExample {
66  private context: DrawingRenderingContext = new DrawingRenderingContext()
67
68  build() {
69    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
70      Canvas(this.context)
71        .width('100%')
72        .height('100%')
73        .backgroundColor('#ffff00')
74        .onReady(() => {
75          this.context.canvas.drawCircle(200, 200, 100)
76          this.context.invalidate()
77        })
78    }
79    .width('100%')
80    .height('100%')
81  }
82}
83```
84  ![en-us_image_0000001194032666](figures/canvas_drawingRenderingContext.png)
85