diff --git a/en/application-dev/reference/apis/js-apis-inputmethod.md b/en/application-dev/reference/apis/js-apis-inputmethod.md index 8d784daa9d3371d8e891201ac640057bf91d7cee..05c8e5dd3a3c5f6528ffcd66b6886d729b31634b 100644 --- a/en/application-dev/reference/apis/js-apis-inputmethod.md +++ b/en/application-dev/reference/apis/js-apis-inputmethod.md @@ -13,7 +13,7 @@ The **inputMethod** module provides an input method framework, which can be used import inputMethod from '@ohos.inputmethod'; ``` -## Constants +## Constants8+ Provides the constants. @@ -23,7 +23,7 @@ Provides the constants. | -------- | -------- | -------- | -------- | | MAX_TYPE_NUM | number | 128 | Maximum number of supported input methods.| -## InputMethodProperty +## InputMethodProperty8+ Describes the input method application attributes. @@ -56,7 +56,7 @@ Obtains an **[InputMethodController](#inputmethodcontroller)** instance. let inputMethodController = inputMethod.getInputMethodController(); ``` -## inputMethod.getInputMethodSetting +## inputMethod.getInputMethodSetting8+ getInputMethodSetting(): InputMethodSetting @@ -136,7 +136,7 @@ inputMethodController.stopInput().then((result) => { }) ``` -## InputMethodSetting +## InputMethodSetting8+ In the following API examples, you must first use [getInputMethodSetting](#inputmethodgetinputmethodsetting) to obtain an **InputMethodSetting** instance, and then call the APIs using the obtained instance. @@ -152,7 +152,7 @@ Obtains a list of installed input methods. This API uses an asynchronous callbac | Name | Type | Mandatory| Description | | -------- | -------------------------------------------------- | ---- | ---------------------- | -| callback | AsyncCallback<Array<[InputMethodProperty](#inputmethodproperty)>> | Yes | Callback used to return the list of installed input methods.| +| callback | AsyncCallback<Array<[InputMethodProperty](#inputmethodproperty8)>> | Yes | Callback used to return the list of installed input methods.| **Example** @@ -166,7 +166,7 @@ inputMethodSetting.listInputMethod((err, data) => { }); ``` -### listInputMethod +### listInputMethod8+ listInputMethod(): Promise<Array<InputMethodProperty>> @@ -190,7 +190,7 @@ inputMethodSetting.listInputMethod().then((data) => { }) ``` -### displayOptionalInputMethod +### displayOptionalInputMethod8+ displayOptionalInputMethod(callback: AsyncCallback<void>): void @@ -216,7 +216,7 @@ inputMethodSetting.displayOptionalInputMethod((err) => { }); ``` -### displayOptionalInputMethod +### displayOptionalInputMethod8+ displayOptionalInputMethod(): Promise<void> diff --git a/en/application-dev/reference/arkui-js/js-components-canvas-canvasrenderingcontext2d.md b/en/application-dev/reference/arkui-js/js-components-canvas-canvasrenderingcontext2d.md index f3ede6c1ec2980d9053ad552e4d29ca4987aaa87..08f2054909b730cd3702c1da89ce3cfcb22947bb 100644 --- a/en/application-dev/reference/arkui-js/js-components-canvas-canvasrenderingcontext2d.md +++ b/en/application-dev/reference/arkui-js/js-components-canvas-canvasrenderingcontext2d.md @@ -1,12 +1,13 @@ # CanvasRenderingContext2D -> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** -> Supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version. +> **NOTE** +> +> This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version. **CanvasRenderingContext2D** allows you to draw rectangles, text, images, and other objects on a canvas. -- Example +**Example** ```
@@ -44,36 +45,40 @@ ![screenshot-8](figures/screenshot-8.png) + ## Attributes -| Name | Type | Default Value | Description | -| ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------- | ------------------------------------------------------------ | -| [fillStyle](js-components-canvas-canvasrenderingcontext2d.md) | \ \| [CanvasGradient](js-components-canvas-canvasgradient.md) \| CanvasPattern | - | Style to fill an area.
-When the type is **\**, this parameter indicates the color of the filling area.
-When the type is **CanvasGradient**, this parameter indicates a gradient object, which is created using the **createLinearGradient()** method.
- When the type is **CanvasPattern**, this parameter indicates a canvas pattern, which is created using the **createPattern()** method. | -| [lineWidth](js-components-canvas-canvasrenderingcontext2d.md) | number | - | Line width. | -| [strokeStyle](js-components-canvas-canvasrenderingcontext2d.md) | \ \| [CanvasGradient](js-components-canvas-canvasgradient.md) \| CanvasPattern | - | Stroke style.
- When the type is **\**, this parameter indicates the stroke color.
- When the type is **CanvasGradient**, this parameter indicates a gradient object, which is created using the **createLinearGradient()** method.
-When the type is **CanvasPattern**, this parameter indicates a canvas pattern, which is created using the **createPattern()** method. | -| [lineCap](js-components-canvas-canvasrenderingcontext2d.md) | string | butt | Style of the specified line endpoint. The options are as follows:
- **butt**: The endpoints of the line are squared off.
- **round**: The endpoints of the line are rounded.
- **square**: The endpoints of the line are squared off, and each endpoint has added a rectangle whose length is the same as the line thickness and whose width is half of the line thickness. | -| [lineJoin](js-components-canvas-canvasrenderingcontext2d.md) | string | miter | Style of the intersection point between line segments. The options are as follows:
-**round**: The intersection is a sector, whose radius at the rounded corner is equal to the line width.
- **bevel**: The intersection is a triangle. The rectangular corner of each line is independent.
-**miter**: The intersection has a miter corner by extending the outside edges of the lines until they meet. You can view the effect of this attribute in **miterLimit**. | -| [miterLimit](js-components-canvas-canvasrenderingcontext2d.md) | number | 10 | Maximum miter length. The miter length is the distance between the inner corner and the outer corner where two lines meet. | -| [font](js-components-canvas-canvasrenderingcontext2d.md) | string | "normal normal 14px sans-serif" | Font style. Syntax: ctx.font="font-style font-weight font-size font-family"5+
-(Optional) **font-style**: font style. Available values are **normal** and **italic**.
- (Optional) **font-weight**: font weight. Available values are as follows: **normal**, **bold**, **bolder**, **lighter**, **100**, **200**, **300**, **400**, **500**, **600**, **700**, **800**, **900**.
- (Optional) **font-size**: font size and row height. The unit can only be pixels.
- (Optional) **font-family**: font family. Available values are **sans-serif**, **serif**, and **monospace**. | -| [textAlign](js-components-canvas-canvasrenderingcontext2d.md) | string | left | Text alignment mode. Available values are as follows:
- **left**: The text is left-aligned.
-**right**: The text is right-aligned.
- **center**: The text is center-aligned.
- **start**: The text is aligned with the start bound.
- **end**: The text is aligned with the end bound.
>![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> In the **ltr** layout mode, the value **start** equals **left**. In the **rtl** layout mode, the value **start** equals **right**. | -| [textBaseline](js-components-canvas-canvasrenderingcontext2d.md) | string | alphabetic | Horizontal alignment mode of text. Available values are as follows:
- **alphabetic**: The text baseline is the normal alphabetic baseline.
- **top**: The text baseline is on the top of the text bounding box.
-**hanging**: The text baseline is a hanging baseline over the text.
- **middle**: The text baseline is in the middle of the text bounding box.
- **ideographic**: The text baseline is the ideographic baseline. If a character exceeds the alphabetic baseline, the ideographic baseline is located at the bottom of the excessive character.
- **bottom**: The text baseline is at the bottom of the text bounding box. Its difference from the ideographic baseline is that the ideographic baseline does not consider letters in the next line. | -| [globalAlpha](js-components-canvas-canvasrenderingcontext2d.md) | number | - | Opacity.
**0.0**: completely transparent.
**1.0**: completely opaque. | -| [lineDashOffset](js-components-canvas-canvasrenderingcontext2d.md) | number | 0.0 | Offset of the dashed line. The precision is float. | -| [globalCompositeOperation](js-components-canvas-canvasrenderingcontext2d.md) | string | source-over | Composition operation type. Available values are as follows: source-over, source-atop, source-in, source-out, destination-over, destination-atop, destination-in, destination-out, lighter, copy, and xor. For details, see [Operation types](js-components-canvas-canvasrenderingcontext2d.md). | -| [shadowBlur](js-components-canvas-canvasrenderingcontext2d.md) | number | 0.0 | Blur level during shadow drawing. A larger value indicates a more blurred effect. The precision is float. | -| [shadowColor](js-components-canvas-canvasrenderingcontext2d.md) | \ | - | Shadow color. | -| [shadowOffsetX](js-components-canvas-canvasrenderingcontext2d.md) | number | - | X-axis shadow offset relative to the original object. | -| [shadowOffsetY](js-components-canvas-canvasrenderingcontext2d.md) | number | - | Y-axis shadow offset relative to the original object. | -| [imageSmoothingEnabled](js-components-canvas-canvasrenderingcontext2d.md)6+ | boolean | true | Whether to adjust the image smoothness during image drawing. The value **true** means to enable this feature, and **false** means the opposite. | +| Name | Type | Description | +| ---------------------------------------- | ---------------------------------------- | ---------------------------------------- | +| [fillStyle](#fillstyle) | <color> \| [CanvasGradient](../arkui-js/js-components-canvas-canvasgradient.md) \| CanvasPattern | Style to fill an area.
- When the type is **\**, this parameter indicates the color of the filling area.
- When the type is **CanvasGradient**, this parameter indicates a gradient object, which is created using the **createLinearGradient()** method.
- When the type is **CanvasPattern**, this parameter indicates a canvas pattern, which is created using the **createPattern()** method.| +| [lineWidth](#linewidth) | number | Line width. | +| [strokeStyle](#strokestyle) | <color> \| [CanvasGradient](../arkui-js/js-components-canvas-canvasgradient.md) \| CanvasPattern | Stroke style.
- When the type is **\**, this parameter indicates the stroke color.
- When the type is **CanvasGradient**, this parameter indicates a gradient object, which is created using the **createLinearGradient()** method.
- When the type is **CanvasPattern**, this parameter indicates a canvas pattern, which is created using the **createPattern()** method.| +| [lineCap](#linecap) | string | Style of the specified line endpoint. The options are as follows:
- **butt**: The endpoints of the line are squared off.
- **round**: The endpoints of the line are rounded.
- **square**: The endpoints of the line are squared off, and each endpoint has added a rectangle whose length is the same as the line thickness and whose width is half of the line thickness.
Default value: **butt**| +| [lineJoin](#linejoin) | string | Style of the intersection point between line segments. The options are as follows:
- **round**: The intersection is a sector, whose radius at the rounded corner is equal to the line width.
- **bevel**: The intersection is a triangle. The rectangular corner of each line is independent.
- **miter**: The intersection has a miter corner by extending the outside edges of the lines until they meet. You can view the effect of this attribute in **miterLimit**.
Default value: **miter**| +| [miterLimit](#miterlimit) | number | Maximum miter length. The miter length is the distance between the inner corner and the outer corner where two lines meet.
Default value: **10** | +| [font](#font) | string | Font style.
Syntax: ctx.font="font-style font-weight font-size font-family"5+
- (Optional) **font-style**: font style. Available values are **normal** and **italic**.
- (Optional) **font-weight**: font weight. Available values are as follows: **normal**, **bold**, **bolder**, **lighter**, **100**, **200**, **300**, **400**, **500**, **600**, **700**, **800**, **900**.
- (Optional) **font-size**: font size and row height. The unit can only be pixels.
- (Optional) **font-family**: font family. Available values are **sans-serif**, **serif**, and **monospace**.
Default value: **"normal normal 14px sans-serif"**| +| [textAlign](#textalign) | string | Text alignment mode. Available values are as follows:
- **left**: The text is left-aligned.
- **right**: The text is right-aligned.
- **center**: The text is center-aligned.
- **start**: The text is aligned with the start bound.
- **end**: The text is aligned with the end bound.
In the **ltr** layout mode, the value **start** equals **left**. In the **rtl** layout mode, the value **start** equals **right**.
Default value: **left**| +| [textBaseline](#textbaseline) | string | Horizontal alignment mode of text. Available values are as follows:
- **alphabetic**: The text baseline is the normal alphabetic baseline.
- **top**: The text baseline is on the top of the text bounding box.
- **hanging**: The text baseline is a hanging baseline over the text.
- **middle**: The text baseline is in the middle of the text bounding box.
- **ideographic**: The text baseline is the ideographic baseline. If a character exceeds the alphabetic baseline, the ideographic baseline is located at the bottom of the excessive character.
- **bottom**: The text baseline is at the bottom of the text bounding box. Its difference from the ideographic baseline is that the ideographic baseline does not consider letters in the next line.
Default value: **alphabetic**| +| [globalAlpha](#globalalpha) | number | Opacity.
**0.0**: completely transparent.
**1.0**: completely opaque. | +| [lineDashOffset](#linedashoffset) | number | Offset of the dashed line. The precision is float.
Default value: **0.0** | +| [globalCompositeOperation](#globalcompositeoperation) | string | Composition operation type. Available values are as follows: **source-over**, **source-atop**, **source-in**, **source-out**, **destination-over**, **destination-atop**, **destination-in**, **destination-out**, **lighter**, copy, and **xor**. For details, see [Operation types](#globalcompositeoperation).
Default value: **ource-over**| +| [shadowBlur](#shadowblur) | number | Blur level during shadow drawing. A larger value indicates a more blurred effect. The precision is float.
Default value: **0.0**| +| [shadowColor](#shadowcolor) | <color> | Shadow color. | +| [shadowOffsetX](#shadowoffsetx) | number | X-axis shadow offset relative to the original object. | +| [shadowOffsetY](#shadowoffsety) | number | Y-axis shadow offset relative to the original object. | +| [imageSmoothingEnabled](#imagesmoothingenabled6)6+ | boolean | Whether to adjust the image smoothness during image drawing. The value **true** means to enable this feature, and **false** means the opposite.
Default value: **true**| + ### fillStyle -``` + ``` -
- +
+ ``` + +``` //xxx.js export default { onShow() { @@ -87,6 +92,7 @@ export default { ![en-us_image_0000001166962736](figures/en-us_image_0000001166962736.png) + ### lineWidth ``` @@ -94,6 +100,9 @@ export default {
+``` + +``` //xxx.js export default { onShow() { @@ -103,10 +112,12 @@ export default { ctx.strokeRect(25, 25, 85, 105); } } + ``` ![en-us_image_0000001166484430](figures/en-us_image_0000001166484430.png) + ### strokeStyle ``` @@ -114,6 +125,9 @@ export default {
+``` + +``` //xxx.js export default { onShow() { @@ -126,6 +140,7 @@ export default { } ``` + ![en-us_image_0000001212124299](figures/en-us_image_0000001212124299.png) ### lineCap @@ -135,6 +150,9 @@ export default {
+``` + +``` //xxx.js export default { onShow() { @@ -159,6 +177,9 @@ export default {
+``` + +``` //xxx.js export default { onShow() { @@ -184,6 +205,9 @@ export default {
+``` + +``` //xxx.js export default { onShow() { @@ -202,6 +226,7 @@ export default { ![en-us_image_0000001167001464](figures/en-us_image_0000001167001464.png) + ### font ``` @@ -209,6 +234,9 @@ export default {
+``` + +``` //xxx.js export default { onShow() { @@ -222,6 +250,7 @@ export default { ![en-us_image_0000001167046832](figures/en-us_image_0000001167046832.png) + ### textAlign ``` @@ -229,6 +258,9 @@ export default {
+``` + +``` //xxx.js export default { onShow() { @@ -252,8 +284,10 @@ export default { ctx.fillText('textAlign=right',140, 140); } } + ``` + ![en-us_image_0000001167472798](figures/en-us_image_0000001167472798.png) ### textBaseline @@ -263,6 +297,9 @@ export default {
+``` + +``` //xxx.js export default { onShow() { @@ -296,6 +333,9 @@ export default {
+``` + +``` //xxx.js export default { onShow() { @@ -320,6 +360,9 @@ export default {
+``` + +``` //xxx.js export default { onShow() { @@ -337,60 +380,66 @@ export default { ### globalCompositeOperation -- Operation types +Enumerates the operation types. - | Value | Description | - | ---------------- | ------------------------------------------------------------ | - | source-over | Displays the new drawing above the existing drawing. This attribute is used by default. | - | source-atop | Displays the new drawing on the top of the existing drawing. | - | source-in | Displays the new drawing inside the existing drawing. | - | source-out | Displays part of the new drawing that is outside of the existing drawing. | - | destination-over | Displays the existing drawing above the new drawing. | - | destination-atop | Displays the existing drawing on the top of the new drawing. | - | destination-in | Displays the existing drawing inside the new drawing. | - | destination-out | Displays part of the existing drawing that is outside of the new drawing. | - | lighter | Displays both the new drawing and the existing drawing. | - | copy | Displays the new drawing and neglects the existing drawing. | - | xor | Combines the new drawing and existing drawing using the XOR operation. | +| Value | Description | +| ---------------- | ------------------------ | +| source-over | Displays the new drawing above the existing drawing. This attribute is used by default. | +| source-atop | Displays the new drawing on the top of the existing drawing. | +| source-in | Displays the new drawing inside the existing drawing. | +| source-out | Displays part of the new drawing that is outside of the existing drawing. | +| destination-over | Displays the existing drawing above the new drawing. | +| destination-atop | Displays the existing drawing on the top of the new drawing. | +| destination-in | Displays the existing drawing inside the new drawing. | +| destination-out | Displays the existing drawing outside the new drawing. | +| lighter | Displays both the new and existing drawing. | +| copy | Displays the new drawing and neglects the existing drawing. | +| xor | Combines the new drawing and existing drawing using the XOR operation.| -- Example +**Example** ```
-//xxx.js -export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.fillStyle = 'rgb(255,0,0)'; - ctx.fillRect(20, 20, 50, 50); - ctx.globalCompositeOperation = 'source-over'; - ctx.fillStyle = 'rgb(0,0,255)'; - ctx.fillRect(50, 50, 50, 50); - // Start drawing second example - ctx.fillStyle = 'rgb(255,0,0)'; - ctx.fillRect(120, 20, 50, 50); - ctx.globalCompositeOperation = 'destination-over'; - ctx.fillStyle = 'rgb(0,0,255)'; - ctx.fillRect(150, 50, 50, 50); - } -} ``` -![en-us_image_0000001213192781](figures/en-us_image_0000001213192781.png) + ``` + //xxx.js + export default { + onShow() { + const el =this.$refs.canvas; + const ctx = el.getContext('2d'); + ctx.fillStyle = 'rgb(255,0,0)'; + ctx.fillRect(20, 20, 50, 50); + ctx.globalCompositeOperation = 'source-over'; + ctx.fillStyle = 'rgb(0,0,255)'; + ctx.fillRect(50, 50, 50, 50); + // Start drawing second example + ctx.fillStyle = 'rgb(255,0,0)'; + ctx.fillRect(120, 20, 50, 50); + ctx.globalCompositeOperation = 'destination-over'; + ctx.fillStyle = 'rgb(0,0,255)'; + ctx.fillRect(150, 50, 50, 50); + } + } + ``` + + ![en-us_image_0000001213192781](figures/en-us_image_0000001213192781.png) -In the above example, the blue rectangle represents the new drawing, and the red rectangle represents the existing drawing. + In the above example, the blue rectangle represents the new drawing, and the red rectangle represents the existing drawing. ### shadowBlur -``` + ```
- +
+ ``` + +``` //xxx.js export default { onShow() { @@ -413,6 +462,9 @@ export default {
+``` + +``` //xxx.js export default { onShow() { @@ -435,6 +487,9 @@ export default {
+``` + +``` //xxx.js export default { onShow() { @@ -449,6 +504,7 @@ export default { } ``` + ![en-us_image_0000001167631876](figures/en-us_image_0000001167631876.png) ### shadowOffsetY @@ -458,6 +514,9 @@ export default {
+``` + +``` //xxx.js export default { onShow() { @@ -474,13 +533,16 @@ export default { ![en-us_image_0000001213193285](figures/en-us_image_0000001213193285.png) -### imageSmoothingEnabled6+ +### imageSmoothingEnabled6+ ```
+``` + +``` //xxx.js export default { onShow() { @@ -498,41 +560,47 @@ export default { ![smoothoff](figures/smoothoff.png) + + ## Methods + ### fillRect fillRect(x: number, y: number, width:number, height: number): void Fills a rectangle on the canvas. -- Parameters +**Parameters** - | Name | Type | Description | - | ------ | ------ | ------------------------------------------------------- | - | x | number | X-coordinate of the upper left corner of the rectangle. | - | y | number | Y-coordinate of the upper left corner of the rectangle. | - | width | number | Width of the rectangle. | - | height | number | Height of the rectangle. | +| Name | Type | Description | +| ------ | ------ | ------------- | +| x | number | X-coordinate of the upper left corner of the rectangle.| +| y | number | Y-coordinate of the upper left corner of the rectangle.| +| width | number | Width of the rectangle. | +| height | number | Height of the rectangle. | -- Example +**Example** ```
-//xxx.js -export default { - onShow() { - const el =this.$refs.canvas; - const ctx = el.getContext('2d'); - ctx.fillRect(20, 20, 200, 150); - } -} ``` -![en-us_image_0000001214811029](figures/en-us_image_0000001214811029.png) + ``` + //xxx.js + export default { + onShow() { + const el =this.$refs.canvas; + const ctx = el.getContext('2d'); + ctx.fillRect(20, 20, 200, 150); + } + } + ``` + + ![en-us_image_0000001214811029](figures/en-us_image_0000001214811029.png) ### clearRect @@ -540,17 +608,16 @@ clearRect(x: number, y: number, width:number, height: number): void Clears the content in a rectangle on the canvas. -- Parameters +**Parameters** - | Name | Type | Description | - | ------ | ------ | ------------------------------------------------------- | - | x | number | X-coordinate of the upper left corner of the rectangle. | - | y | number | Y-coordinate of the upper left corner of the rectangle. | - | width | number | Width of the rectangle. | - | height | number | Height of the rectangle. | - -- Example +| Name | Type | Description | +| ------ | ------ | ------------- | +| x | number | X-coordinate of the upper left corner of the rectangle.| +| y | number | Y-coordinate of the upper left corner of the rectangle.| +| width | number | Width of the rectangle. | +| height | number | Height of the rectangle. | +**Example** ```
@@ -573,23 +640,23 @@ Clears the content in a rectangle on the canvas. ![en-us_image_0000001214619417](figures/en-us_image_0000001214619417.png) + ### strokeRect strokeRect(x: number, y: number, width:number, height: number): void Draws a rectangle stroke on the canvas. -- Parameters +**Parameters** - | Name | Type | Description | - | ------ | ------ | ------------------------------------------------------------ | - | x | number | X-coordinate of the upper left corner of the rectangle stroke. | - | y | number | Y-coordinate of the upper left corner of the rectangle stroke. | - | width | number | Width of the rectangle. | - | height | number | Height of the rectangle. | - -- Example +| Name | Type | Description | +| ------ | ------ | ------------ | +| x | number | X-coordinate of the upper left corner of the rectangle stroke.| +| y | number | Y-coordinate of the upper left corner of the rectangle stroke.| +| width | number | Width of the rectangle. | +| height | number | Height of the rectangle. | +**Example** ```
@@ -610,22 +677,22 @@ Draws a rectangle stroke on the canvas. ![en-us_image_0000001214822091](figures/en-us_image_0000001214822091.png) + ### fillText fillText(text: string, x: number, y: number): void Draws filled text on the canvas. -- Parameters - - | Name | Type | Description | - | ---- | ------ | -------------------------------------------------- | - | text | string | Text to draw. | - | x | number | X-coordinate of the lower left corner of the text. | - | y | number | Y-coordinate of the lower left corner of the text. | +**Parameters** -- Example +| Name | Type | Description | +| ---- | ------ | --------------- | +| text | string | Text to draw. | +| x | number | X-coordinate of the lower left corner of the text.| +| y | number | Y-coordinate of the lower left corner of the text.| +**Example** ```
@@ -653,16 +720,15 @@ strokeText(text: string, x: number, y: number): void Draws a text stroke on the canvas. -- Parameters +**Parameters** - | Name | Type | Description | - | ---- | ------ | -------------------------------------------------- | - | text | string | Text to draw. | - | x | number | X-coordinate of the lower left corner of the text. | - | y | number | Y-coordinate of the lower left corner of the text. | - -- Example +| Name | Type | Description | +| ---- | ------ | --------------- | +| text | string | Text to draw. | +| x | number | X-coordinate of the lower left corner of the text.| +| y | number | Y-coordinate of the lower left corner of the text.| +**Example** ```
@@ -690,20 +756,19 @@ measureText(text: string): TextMetrics Returns a **TextMetrics** object used to obtain the width of specified text. -- Parameters - - | Name | Type | Description | - | ---- | ------ | -------------------- | - | text | string | Text to be measured. | +**Parameters** -- Return value +| Name | Type | Description | +| ---- | ------ | ---------- | +| text | string | Text to be measured.| - | Type | Description | - | ----------- | ------------------------------------------------------------ | - | TextMetrics | Object that contains the text width. You can obtain the width by **TextMetrics.width**. | +**Return value** -- Example +| Type | Description | +| ----------- | -------------------------------------- | +| TextMetrics | Object that contains the text width. You can obtain the width by **TextMetrics.width**.| +**Example** ```
@@ -727,14 +792,13 @@ Returns a **TextMetrics** object used to obtain the width of specified text. ![en-us_image_0000001169142476](figures/en-us_image_0000001169142476.png) -### stroke +### stroke stroke(): void Draws a stroke. -- Example - +**Example** ```
@@ -759,14 +823,13 @@ Draws a stroke. ![en-us_image_0000001236697937](figures/en-us_image_0000001236697937.png) -### beginPath +### beginPath beginPath(): void Creates a drawing path. -- Example - +**Example** ```
@@ -792,21 +855,20 @@ Creates a drawing path. ![en-us_image_0000001214629745](figures/en-us_image_0000001214629745.png) -### moveTo +### moveTo moveTo(x: number, y: number): void Moves a drawing path to a target position on the canvas. -- Parameters +**Parameters** - | Name | Type | Description | - | ---- | ------ | ------------------------------------ | - | x | number | X-coordinate of the target position. | - | y | number | Y-coordinate of the target position. | - -- Example +| Name | Type | Description | +| ---- | ------ | --------- | +| x | number | X-coordinate of the target position.| +| y | number | Y-coordinate of the target position.| +**Example** ```
@@ -830,21 +892,20 @@ Moves a drawing path to a target position on the canvas. ![en-us_image_0000001169309948](figures/en-us_image_0000001169309948.png) -### lineTo +### lineTo lineTo(x: number, y: number): void Connects the current point to a target position using a straight line. -- Parameters +**Parameters** - | Name | Type | Description | - | ---- | ------ | ------------------------------------ | - | x | number | X-coordinate of the target position. | - | y | number | Y-coordinate of the target position. | - -- Example +| Name | Type | Description | +| ---- | ------ | --------- | +| x | number | X-coordinate of the target position.| +| y | number | Y-coordinate of the target position.| +**Example** ```
@@ -868,14 +929,13 @@ Connects the current point to a target position using a straight line. ![en-us_image_0000001169469914](figures/en-us_image_0000001169469914.png) -### closePath +### closePath closePath(): void Draws a closed path. -- Example - +**Example** ```
@@ -907,21 +967,20 @@ createPattern(image: Image, repetition: string): Object Creates a pattern for image filling based on a specified source image and repetition mode. -- Parameters - - | Name | Type | Description | - | ---------- | ------ | ------------------------------------------------------------ | - | image | Image | Source image. For details, see [Image](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.1-Release/en/application-dev/reference/arkui-js/js-components-canvas-image.md). | - | repetition | string | Repetition mode. The value can be **"repeat"**, **"repeat-x"**, **"repeat-y"**, or **"no-repeat"**. | +**Parameters** -- Return value +| Name | Type | Description | +| ---------- | ------ | ---------------------------------------- | +| image | Image | Source image. For details, see [Image](../arkui-js/js-components-canvas-image.md).| +| repetition | string | Repetition mode. The value can be **"repeat"**, **"repeat-x"**, **"repeat-y"**, or **"no-repeat"**.| - | Type | Description | - | ------ | ------------------------- | - | Object | Pattern of image filling. | +**Return value** -- Example +| Type | Description | +| ------ | ----------------- | +| Object | Pattern of image filling.| +**Example** ```
@@ -952,19 +1011,18 @@ bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, Draws a cubic bezier curve on the canvas. -- Parameters +**Parameters** - | Name | Type | Description | - | ---- | ------ | --------------------------------------------------------- | - | cp1x | number | X-coordinate of the first parameter of the bezier curve. | - | cp1y | number | Y-coordinate of the first parameter of the bezier curve. | - | cp2x | number | X-coordinate of the second parameter of the bezier curve. | - | cp2y | number | Y-coordinate of the second parameter of the bezier curve. | - | x | number | X-coordinate of the end point on the bezier curve. | - | y | number | Y-coordinate of the end point on the bezier curve. | - -- Example +| Name | Type | Description | +| ---- | ------ | -------------- | +| cp1x | number | X-coordinate of the first parameter of the bezier curve.| +| cp1y | number | Y-coordinate of the first parameter of the bezier curve.| +| cp2x | number | X-coordinate of the second parameter of the bezier curve.| +| cp2y | number | Y-coordinate of the second parameter of the bezier curve.| +| x | number | X-coordinate of the end point on the bezier curve. | +| y | number | Y-coordinate of the end point on the bezier curve. | +**Example** ```
@@ -994,17 +1052,16 @@ quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void Draws a quadratic curve on the canvas. -- Parameters - - | Name | Type | Description | - | ---- | ------ | -------------------------------------------------- | - | cpx | number | X-coordinate of the bezier curve parameter. | - | cpy | number | Y-coordinate of the bezier curve parameter. | - | x | number | X-coordinate of the end point on the bezier curve. | - | y | number | Y-coordinate of the end point on the bezier curve. | +**Parameters** -- Example +| Name | Type | Description | +| ---- | ------ | ----------- | +| cpx | number | X-coordinate of the bezier curve parameter.| +| cpy | number | Y-coordinate of the bezier curve parameter.| +| x | number | X-coordinate of the end point on the bezier curve.| +| y | number | Y-coordinate of the end point on the bezier curve.| +**Example** ```
@@ -1028,25 +1085,24 @@ Draws a quadratic curve on the canvas. ![en-us_image_0000001169461910](figures/en-us_image_0000001169461910.png) -### arc +### arc arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise: boolean): void Draws an arc on the canvas. -- Parameters - - | Name | Type | Description | - | ------------- | ------- | -------------------------------------------- | - | x | number | X-coordinate of the center point of the arc. | - | y | number | Y-coordinate of the center point of the arc. | - | radius | number | Radius of the arc. | - | startAngle | number | Start radian of the arc. | - | endAngle | number | End radian of the arc. | - | anticlockwise | boolean | Whether to draw the arc counterclockwise. | +**Parameters** -- Example +| Name | Type | Description | +| ------------- | ------- | ---------- | +| x | number | X-coordinate of the center point of the arc.| +| y | number | Y-coordinate of the center point of the arc.| +| radius | number | Radius of the arc. | +| startAngle | number | Start radian of the arc. | +| endAngle | number | End radian of the arc. | +| anticlockwise | boolean | Whether to draw the arc counterclockwise.| +**Example** ```
@@ -1075,18 +1131,17 @@ arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void Draws an arc based on the radius and points on the arc. -- Parameters +**Parameters** - | Name | Type | Description | - | ------ | ------ | -------------------------------------------- | - | x1 | number | X-coordinate of the first point on the arc. | - | y1 | number | Y-coordinate of the first point on the arc. | - | x2 | number | X-coordinate of the second point on the arc. | - | y2 | number | Y-coordinate of the second point on the arc. | - | radius | number | Radius of the arc. | - -- Example +| Name | Type | Description | +| ------ | ------ | --------------- | +| x1 | number | X-coordinate of the first point on the arc.| +| y1 | number | Y-coordinate of the first point on the arc.| +| x2 | number | X-coordinate of the second point on the arc.| +| y2 | number | Y-coordinate of the second point on the arc.| +| radius | number | Radius of the arc. | +**Example** ```
@@ -1101,7 +1156,7 @@ Draws an arc based on the radius and points on the arc. const el =this.$refs.canvas; const ctx = el.getContext('2d'); ctx.moveTo(100, 20); - ctx.arcTo(150, 20, 150, 70, 50); // Create an arc. + ctx.arcTo(150, 20, 150, 70, 50); // Create an arc ctx.stroke(); } } @@ -1109,27 +1164,26 @@ Draws an arc based on the radius and points on the arc. ![en-us_image_0000001169143586](figures/en-us_image_0000001169143586.png) -### ellipse6+ +### ellipse6+ ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, anticlockwise: number): void Draws an ellipse in the specified rectangular region on the canvas. -- Parameters - - | Name | Type | Description | - | ------------- | ------ | ------------------------------------------------------------ | - | x | number | X-coordinate of the ellipse center. | - | y | number | Y-coordinate of the ellipse center. | - | radiusX | number | Ellipse radius on the x-axis. | - | radiusY | number | Ellipse radius on the y-axis. | - | rotation | number | Rotation angle of the ellipse. The unit is radian. | - | startAngle | number | Angle of the start point for drawing the ellipse. The unit is radian. | - | endAngle | number | Angle of the end point for drawing the ellipse. The unit is radian. | - | anticlockwise | number | Whether to draw the ellipse counterclockwise. The value **0** means clockwise, and **1** means counterclockwise. This parameter is optional. The default value is **0**. | +**Parameters** -- Example +| Name | Type | Description | +| ------------- | ------ | ------------------------------------ | +| x | number | X-coordinate of the ellipse center. | +| y | number | Y-coordinate of the ellipse center. | +| radiusX | number | Ellipse radius on the x-axis. | +| radiusY | number | Ellipse radius on the y-axis. | +| rotation | number | Rotation angle of the ellipse. The unit is radian. | +| startAngle | number | Angle of the start point for drawing the ellipse. The unit is radian. | +| endAngle | number | Angle of the end point for drawing the ellipse. The unit is radian. | +| anticlockwise | number | Whether to draw the ellipse counterclockwise. The value **0** means clockwise, and **1** means counterclockwise. This parameter is optional. The default value is **0**.| +**Example** ```
@@ -1152,23 +1206,22 @@ Draws an ellipse in the specified rectangular region on the canvas. ![ellipse](figures/ellipse.png) -### rect +### rect rect(x: number, y: number, width: number, height: number): void Creates a rectangle on the canvas. -- Parameters - - | Name | Type | Description | - | ------ | ------ | ------------------------------------------------------- | - | x | number | X-coordinate of the upper left corner of the rectangle. | - | y | number | Y-coordinate of the upper left corner of the rectangle. | - | width | number | Width of the rectangle. | - | height | number | Height of the rectangle. | +**Parameters** -- Example +| Name | Type | Description | +| ------ | ------ | ------------- | +| x | number | X-coordinate of the upper left corner of the rectangle.| +| y | number | Y-coordinate of the upper left corner of the rectangle.| +| width | number | Width of the rectangle. | +| height | number | Height of the rectangle. | +**Example** ```
@@ -1182,7 +1235,7 @@ Creates a rectangle on the canvas. onShow() { const el =this.$refs.canvas; const ctx = el.getContext('2d'); - ctx.rect(20, 20, 100, 100); // Create a 100*100 rectangle at (20, 20). + ctx.rect(20, 20, 100, 100); // Create a 100*100 rectangle at (20, 20) ctx.stroke(); // Draw it } } @@ -1196,8 +1249,7 @@ fill(): void Fills the area inside a closed path on the canvas. -- Example - +**Example** ```
@@ -1211,8 +1263,8 @@ Fills the area inside a closed path on the canvas. onShow() { const el =this.$refs.canvas; const ctx = el.getContext('2d'); - ctx.rect(20, 20, 100, 100); // Create a 100*100 rectangle at (20, 20). - ctx.fill(); // Fill the rectangle using default settings. + ctx.rect(20, 20, 100, 100); // Create a 100*100 rectangle at (20, 20) + ctx.fill(); // Draw it in default setting } } ``` @@ -1225,8 +1277,7 @@ clip(): void Sets the current path to a clipping path. -- Example - +**Example** ```
@@ -1243,7 +1294,7 @@ Sets the current path to a clipping path. ctx.rect(0, 0, 200, 200); ctx.stroke(); ctx.clip(); - // Clip a rectangle and fill it with red paint. + // Draw red rectangle after clip ctx.fillStyle = "rgb(255,0,0)"; ctx.fillRect(0, 0, 150, 150); } @@ -1258,14 +1309,13 @@ rotate(rotate: number): void Rotates a canvas clockwise around its coordinate axes. -- Parameters - - | Name | Type | Description | - | ------ | ------ | ------------------------------------------------------------ | - | rotate | number | Clockwise rotation angle. You can use **Math.PI / 180** to convert the angle to a radian. | +**Parameters** -- Example +| Name | Type | Description | +| ------ | ------ | ---------------------------------------- | +| rotate | number | Clockwise rotation angle. You can use **Math.PI / 180** to convert the angle to a radian.| +**Example** ```
@@ -1293,15 +1343,14 @@ scale(x: number, y: number): void Scales the canvas based on scale factors. -- Parameters +**Parameters** - | Name | Type | Description | - | ---- | ------ | ------------------------ | - | x | number | Horizontal scale factor. | - | y | number | Vertical scale factor. | - -- Example +| Name | Type | Description | +| ---- | ------ | ----------- | +| x | number | Horizontal scale factor.| +| y | number | Vertical scale factor.| +**Example** ```
@@ -1316,7 +1365,7 @@ Scales the canvas based on scale factors. const el =this.$refs.canvas; const ctx = el.getContext('2d'); ctx.strokeRect(10, 10, 25, 25); - ctx.scale(2, 2);// Scale to 200%. + ctx.scale(2, 2);// Scale to 200% ctx.strokeRect(10, 10, 25, 25); } } @@ -1330,25 +1379,25 @@ transform(scaleX: number, skewX: number, skewY: number, scale: number, translate Defines a transformation matrix. To transform a graph, you only need to set parameters of the matrix. The coordinates of the graph are multiplied by the matrix values to obtain new coordinates of the transformed graph. You can use the matrix to implement multiple transform effects. -> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** -> The following formulas calculate coordinates of the transformed graph. **x** and **y** represent coordinates before transformation, and **x'** and **y'** represent coordinates after transformation. +> **NOTE**
+> The following formulas calculate coordinates of the transformed graph. **x** and **y** represent coordinates before transformation, and **x'** and **y'** represent coordinates after transformation. > -> - x' = scaleX * x + skewY * y + translateX -> - y' = skewX * x + scaleY * y + translateY - -- Parameters +> - x' = scaleX \* x + skewY \* y + translateX +> +> - y' = skewX \* x + scaleY \* y + translateY - | Name | Type | Description | - | ---------- | ------ | ------------------- | - | scaleX | number | X-axis scale. | - | skewX | number | X-axis skew. | - | skewY | number | Y-axis skew. | - | scaleY | number | Y-axis scale. | - | translateX | number | X-axis translation. | - | translateY | number | Y-axis translation. | +**Parameters** -- Example +| Name | Type | Description | +| ---------- | ------ | -------- | +| scaleX | number | X-axis scale.| +| skewX | number | X-axis skew.| +| skewY | number | Y-axis skew.| +| scaleY | number | Y-axis scale.| +| translateX | number | X-axis translation.| +| translateY | number | Y-axis translation.| +**Example** ```
@@ -1380,21 +1429,20 @@ Defines a transformation matrix. To transform a graph, you only need to set para setTransform(scaleX: number, skewX: number, skewY: number, scale: number, translateX: number, translateY: number): void -Resets the existing transformation matrix and creates a new transformation matrix by using the same parameters as the **transform()** function. - -- Parameters +Resets the existing transformation matrix and creates a new transformation matrix by using the same parameters as the **transform()** API. - | Name | Type | Description | - | ---------- | ------ | ------------------- | - | scaleX | number | X-axis scale. | - | skewX | number | X-axis skew. | - | skewY | number | Y-axis skew. | - | scaleY | number | Y-axis scale. | - | translateX | number | X-axis translation. | - | translateY | number | Y-axis translation. | +**Parameters** -- Example +| Name | Type | Description | +| ---------- | ------ | -------- | +| scaleX | number | X-axis scale.| +| skewX | number | X-axis skew.| +| skewY | number | Y-axis skew.| +| scaleY | number | Y-axis scale.| +| translateX | number | X-axis translation.| +| translateY | number | Y-axis translation.| +**Example** ```
@@ -1425,15 +1473,14 @@ translate(x: number, y: number): void Moves the origin of the coordinate system. -- Parameters - - | Name | Type | Description | - | ---- | ------ | ------------------- | - | x | number | X-axis translation. | - | y | number | Y-axis translation. | +**Parameters** -- Example +| Name | Type | Description | +| ---- | ------ | -------- | +| x | number | X-axis translation.| +| y | number | Y-axis translation.| +**Example** ```
@@ -1456,23 +1503,24 @@ Moves the origin of the coordinate system. ![en-us_image_0000001169144864](figures/en-us_image_0000001169144864.png) -### createPath2D6+ +### createPath2D6+ createPath2D(path: Path2D, cmds: string): Path2D Creates a **Path2D** object. -- Parameters +**Parameters** - | Name | Type | Description | - | ---- | ------ | ---------------------------------- | - | path | Path2D | **Path2D** object. | - | cmds | string | Path description of the SVG image. | +| Name | Type | Description | +| ---- | ------ | -------------- | +| path | Path2D | **Path2D** object. | +| cmds | string | Path description of the SVG image.| -- Return value [Path2D object](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.1-Release/en/application-dev/reference/arkui-js/js-components-canvas-path2d.md) +**Return value** -- Example + [Path2D object](../arkui-js/js-components-canvas-path2d.md) +**Example** ```
@@ -1508,22 +1556,21 @@ drawImage(image: Image, sx: number, sy: number, sWidth: number, sHeight: number, Draws an image on the canvas. -- Parameters +**Parameters** - | Name | Type | Description | - | ------- | ------ | ------------------------------------------------------------ | - | image | Image | Source image. For details, see [Image](js-components-canvas-image.md). | - | sx | number | X-coordinate of the upper left corner of the rectangle used to crop the source image. | - | sy | number | Y-coordinate of the upper left corner of the rectangle used to crop the source image. | - | sWidth | number | Target width to crop the source image. | - | sHeight | number | Target height to crop the source image. | - | dx | number | X-coordinate of the upper left corner of the drawing area on the canvas. | - | dy | number | Y-coordinate of the upper left corner of the drawing area on the canvas. | - | dWidth | number | Width of the drawing area. | - | dHeight | number | Height of the drawing area. | - -- Example +| Name | Type | Description | +| ------- | ------------------------------ | ---------------------------------------- | +| image | Image \| PixelMap9+ | Image resource. For details, see [Image](../arkui-js/js-components-canvas-image.md) or [PixelMap](../apis/js-apis-image.md#pixelmap7).| +| sx | number | X-coordinate of the upper left corner of the rectangle used to crop the source image. | +| sy | number | Y-coordinate of the upper left corner of the rectangle used to crop the source image. | +| sWidth | number | Target width to crop the source image. | +| sHeight | number | Target height to crop the source image. | +| dx | number | X-coordinate of the upper left corner of the drawing area on the canvas. | +| dy | number | Y-coordinate of the upper left corner of the drawing area on the canvas. | +| dWidth | number | Width of the drawing area. | +| dHeight | number | Height of the drawing area. | +**Example** ```
@@ -1552,8 +1599,7 @@ restore(): void Restores the saved drawing context. -- Example - +**Example** ```
@@ -1578,8 +1624,7 @@ save(): void Saves the current drawing context. -- Example - +**Example** ```
@@ -1598,29 +1643,28 @@ Saves the current drawing context. } ``` -### createLinearGradient6+ +### createLinearGradient6+ createLinearGradient(x0: number, y0: number, x1: number, y1: number): Object -Creates a linear gradient and returns a **CanvasGradient** object. For details, see [CanvasGradient](js-components-canvas-canvasgradient.md). - -- Parameters +Creates a linear gradient and returns a **CanvasGradient** object. For details, see [CanvasGradient](../arkui-js/js-components-canvas-canvasgradient.md). - | Name | Type | Description | - | ---- | ------ | -------------------------------- | - | x0 | number | X-coordinate of the start point. | - | y0 | number | Y-coordinate of the start point. | - | x1 | number | X-coordinate of the end point. | - | y1 | number | Y-coordinate of the end point. | +**Parameters** -- Return value +| Name | Type | Description | +| ---- | ------ | -------- | +| x0 | number | X-coordinate of the start point.| +| y0 | number | Y-coordinate of the start point.| +| x1 | number | X-coordinate of the end point.| +| y1 | number | Y-coordinate of the end point.| - | Type | Description | - | ------ | ---------------------------------- | - | Object | Created **CanvasGradient** object. | +**Return value** -- Example +| Type | Description | +| ------ | ---------------------- | +| Object | Created **CanvasGradient** object.| +**Example** ```
@@ -1638,9 +1682,9 @@ Creates a linear gradient and returns a **CanvasGradient** object. For details, // Linear gradient: start(50,0) end(300,100) var gradient = ctx.createLinearGradient(50,0, 300,100); // Add three color stops - gradient.addColorStop(0.0, 'red'); - gradient.addColorStop(0.5, 'white'); - gradient.addColorStop(1.0, 'green'); + gradient.addColorStop(0.0, '#ff0000'); + gradient.addColorStop(0.5, '#ffffff'); + gradient.addColorStop(1.0, '#00ff00'); // Set the fill style and draw a rectangle ctx.fillStyle = gradient; ctx.fillRect(0, 0, 500, 500); @@ -1650,31 +1694,30 @@ Creates a linear gradient and returns a **CanvasGradient** object. For details, ![en-us_image_0000001169303416](figures/en-us_image_0000001169303416.png) -### createRadialGradient6+ +### createRadialGradient6+ createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number, r1: number): Object Creates a radial gradient and returns a **CanvasGradient** object. -- Parameters - - | Name | Type | Description | - | ---- | ------ | ------------------------------------------------------------ | - | x0 | number | X-coordinate of the center of the start circle. | - | y0 | number | Y-coordinate of the center of the start circle. | - | r0 | number | Radius of the start circle, which must be a non-negative finite number. | - | x1 | number | X-coordinate of the center of the end circle. | - | y1 | number | Y-coordinate of the center of the end circle. | - | r1 | number | Radius of the end circle, which must be a non-negative finite number. | +**Parameters** -- Return value +| Name | Type | Description | +| ---- | ------ | ----------------- | +| x0 | number | X-coordinate of the center of the start circle. | +| y0 | number | Y-coordinate of the center of the start circle. | +| r0 | number | Radius of the start circle, which must be a non-negative finite number.| +| x1 | number | X-coordinate of the center of the end circle. | +| y1 | number | Y-coordinate of the center of the end circle. | +| r1 | number | Radius of the end circle, which must be a non-negative finite number.| - | Type | Description | - | ------ | ---------------------------------- | - | Object | Created **CanvasGradient** object. | +**Return value** -- Example +| Type | Description | +| ------ | ---------------------- | +| Object | Created **CanvasGradient** object.| +**Example** ```
@@ -1692,9 +1735,9 @@ Creates a radial gradient and returns a **CanvasGradient** object. // Radial gradient: inner circle(200,200,r:50) outer circle(200,200,r:200) var gradient = ctx.createRadialGradient(200,200,50, 200,200,200); // Add three color stops - gradient.addColorStop(0.0, 'red'); - gradient.addColorStop(0.5, 'white'); - gradient.addColorStop(1.0, 'green'); + gradient.addColorStop(0.0, '#ff0000'); + gradient.addColorStop(0.5, '#ffffff'); + gradient.addColorStop(1.0, '#00ff00'); // Set the fill style and draw a rectangle ctx.fillStyle = gradient; ctx.fillRect(0, 0, 500, 500); @@ -1708,24 +1751,23 @@ Creates a radial gradient and returns a **CanvasGradient** object. createImageData(width: number, height: number, imageData: Object): Object -Creates an **ImageData** object. For details, see [ImageData](js-components-canvas-imagedata.md). +Creates an **ImageData** object. For details, see [ImageData](../arkui-js/js-components-canvas-imagedata.md). -- Parameters +**Parameters** - | Name | Type | Description | - | --------- | ------ | ------------------------------------------------------------ | - | width | number | Width of the **ImageData** object. | - | height | number | Height of the **ImageData** object. | - | imagedata | Object | **ImageData** object with the same width and height copied from the original **ImageData** object. | +| Name | Type | Description | +| --------- | ------ | ----------------- | +| width | number | Width of the **ImageData** object. | +| height | number | Height of the **ImageData** object. | +| imagedata | Object | **ImageData** object with the same width and height copied from the original **ImageData** object.| -- Return value +**Return value** - | Type | Description | - | ------ | ----------------------------- | - | Object | Created **ImageData** object. | - -- Example +| Type | Description | +| ------ | ----------------- | +| Object | Created **ImageData** object.| +**Example** ```
@@ -1749,29 +1791,28 @@ Creates an **ImageData** object. For details, see [ImageData](js-components-canv getImageData(sx: number, sy: number, sw: number, sh: number): Object -Creates an **ImageData** object with pixels in the specified area on the canvas. - -- Parameters +Obtains the **ImageData** object created with the pixels within the specified area on the canvas. - | Name | Type | Description | - | ---- | ------ | --------------------------------------------------------- | - | sx | number | X-coordinate of the upper left corner of the output area. | - | sy | number | Y-coordinate of the upper left corner of the output area. | - | sw | number | Width of the output area. | - | sh | number | Height of the output area. | +**Parameters** -- Return value +| Name | Type | Description | +| ---- | ------ | --------------- | +| sx | number | X-coordinate of the upper left corner of the output area.| +| sy | number | Y-coordinate of the upper left corner of the output area.| +| sw | number | Width of the output area. | +| sh | number | Height of the output area. | - | Type | Description | - | ------ | ------------------------------------------------------------ | - | Object | **ImageData** object that contains pixels in the specified area on the canvas. | +**Return value** -- Example +| Type | Description | +| ------ | ----------------------- | +| Object | **ImageData** object that contains pixels in the specified area on the canvas.| +**Example** ```
- +
``` @@ -1792,24 +1833,23 @@ putImageData(imageData: Object, dx: number, dy: number, dirtyX: number, dirtyY: Puts the **ImageData** onto a rectangular area on the canvas. -- Parameters +**Parameters** - | Name | Type | Description | - | ----------- | ------ | ------------------------------------------------------------ | - | imagedata | Object | **ImageData** object with pixels to put onto the canvas. | - | dx | number | X-axis offset of the rectangular area on the canvas. | - | dy | number | Y-axis offset of the rectangular area on the canvas. | - | dirtyX | number | X-axis offset of the upper left corner of the rectangular area relative to that of the source image. | - | dirtyY | number | Y-axis offset of the upper left corner of the rectangular area relative to that of the source image. | - | dirtyWidth | number | Width of the rectangular area to crop the source image. | - | dirtyHeight | number | Height of the rectangular area to crop the source image. | - -- Example +| Name | Type | Description | +| ----------- | ------ | ----------------------------- | +| imagedata | Object | **ImageData** object with pixels to put onto the canvas. | +| dx | number | X-axis offset of the rectangular area on the canvas. | +| dy | number | Y-axis offset of the rectangular area on the canvas. | +| dirtyX | number | X-axis offset of the upper left corner of the rectangular area relative to that of the source image.| +| dirtyY | number | Y-axis offset of the upper left corner of the rectangular area relative to that of the source image.| +| dirtyWidth | number | Width of the rectangular area to crop the source image. | +| dirtyHeight | number | Height of the rectangular area to crop the source image. | +**Example** ```
- +
``` @@ -1839,14 +1879,13 @@ setLineDash(segments: Array): void Sets the dash line style. -- Parameters - - | Name | Type | Description | - | -------- | ----- | ------------------------------------------------------------ | - | segments | Array | An array describing the interval of alternate line segments and length of spacing. | +**Parameters** -- Example +| Name | Type | Description | +| -------- | ----- | -------------------- | +| segments | Array | An array describing the interval of alternate line segments and length of spacing.| +**Example** ```
@@ -1875,14 +1914,13 @@ getLineDash(): Array Obtains the dash line style. -- Return value - - | Type | Description | - | ----- | ------------------------------------------------------------ | - | Array | An array describing the interval of alternate line segments and length of spacing. | +**Return value** -- Example +| Type | Description | +| ----- | ------------------------ | +| Array | An array describing the interval of alternate line segments and length of spacing.| +**Example** ```
@@ -1901,20 +1939,19 @@ Obtains the dash line style. } ``` -### transferFromImageBitmap7+ +### transferFromImageBitmap7+ transferFromImageBitmap(bitmap: ImageBitmap): void Displays the specified **ImageBitmap** object. -- Parameters +**Parameters** - | Name | Type | Description | - | ------ | ----------- | ---------------------------------- | - | bitmap | ImageBitmap | **ImageBitmap** object to display. | - -- Example +| Name | Type | Description | +| ------ | ----------- | ------------------ | +| bitmap | ImageBitmap | **ImageBitmap** object to display.| +**Example** ```
@@ -1932,11 +1969,11 @@ Displays the specified **ImageBitmap** object. var offscreen = new OffscreenCanvas(500,500); var offscreenCanvasCtx = offscreen.getContext("2d"); offscreenCanvasCtx.fillRect(0, 0, 200, 200); - + var bitmap = offscreen.transferToImageBitmap(); canvas.transferFromImageBitmap(bitmap); } } ``` - ![en-us_image_0000001168984882](figures/en-us_image_0000001168984882.png) \ No newline at end of file + ![en-us_image_0000001168984882](figures/en-us_image_0000001168984882.png) diff --git a/en/application-dev/reference/arkui-js/js-offscreencanvasrenderingcontext2d.md b/en/application-dev/reference/arkui-js/js-offscreencanvasrenderingcontext2d.md index 1ca6d51ef332ae367846b5eec73121814ae5398d..5cf4219ddc9e2b94cf19e0170f7056ac2af76032 100644 --- a/en/application-dev/reference/arkui-js/js-offscreencanvasrenderingcontext2d.md +++ b/en/application-dev/reference/arkui-js/js-offscreencanvasrenderingcontext2d.md @@ -1,229 +1,218 @@ # OffscreenCanvasRenderingContext2D +> **NOTE** +> +> The APIs of this module are supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. ->![](../../public_sys-resources/icon-note.gif) **NOTE:** ->**OffscreenCanvasRenderingContext2D** is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. -Use **OffscreenCanvasRenderingContext2D** to draw rectangles, images, and texts on an **OffscreenCanvas**. +Use **OffscreenCanvasRenderingContext2D** to draw rectangles, images, and texts on an **OffscreenCanvas**. + ## Attributes -In addition to the attributes that are supported by **CanvasRenderingContext2D**, the following attributes are supported. - -| Name | Type | Description | -| ------ | ------ | ------------------------------------------------------------ | -| filter | string | Image filter.
Available options are as follows:
- **blur**: applies the Gaussian blur for the image.
- **brightness**: applies a linear multiplication to the image to make it look brighter or darker.
- **contrast**: adjusts the image contrast.
- **drop-shadow**: sets a shadow effect for the image.
- **grayscale**: converts the image to a grayscale image.
- **hue-rotate**: applies hue rotation to the image.
- **invert**: inverts the input image.
- **opacity**: opacity of the converted image.
- **saturate**: saturation of the converted image.
- **sepia**: converts the image to dark brown. | - - -- Example - - ``` - -
- -
- ``` - - ``` - //xxx.js - export default { - onShow(){ - var ctx = this.$refs.canvasId.getContext('2d'); - var offscreen = new OffscreenCanvas(360, 500); - var offCanvas2 = offscreen.getContext("2d"); - var img = new Image(); - img.src = 'common/images/flower.jpg'; - offCanvas2.drawImage(img, 0, 0, 100, 100); - offCanvas2.filter = 'blur(5px)'; - offCanvas2.drawImage(img, 100, 0, 100, 100); - - offCanvas2.filter = 'grayscale(50%)'; - offCanvas2.drawImage(img, 200, 0, 100, 100); - - offCanvas2.filter = 'hue-rotate(90deg)'; - offCanvas2.drawImage(img, 0, 100, 100, 100); - - offCanvas2.filter = 'invert(100%)'; - offCanvas2.drawImage(img, 100, 100, 100, 100); - - offCanvas2.filter = 'drop-shadow(8px 8px 10px green)'; - offCanvas2.drawImage(img, 200, 100, 100, 100); - - offCanvas2.filter = 'brightness(0.4)'; - offCanvas2.drawImage(img, 0, 200, 100, 100); - - offCanvas2.filter = 'opacity(25%)'; - offCanvas2.drawImage(img, 100, 200, 100, 100); - - offCanvas2.filter = 'saturate(30%)'; - offCanvas2.drawImage(img, 200, 200, 100, 100); - - offCanvas2.filter = 'sepia(60%)'; - offCanvas2.drawImage(img, 0, 300, 100, 100); - - offCanvas2.filter = 'contrast(200%)'; - offCanvas2.drawImage(img, 100, 300, 100, 100); - var bitmap = offscreen.transferToImageBitmap(); - ctx.transferFromImageBitmap(bitmap); - } +In addition to the attributes that are supported by **CanvasRenderingContext2D**, the following attributes are supported. + +| Name | Type | Description | +| ------ | ------ | ---------------------------------------- | +| filter | string | Image filter.
Available options are as follows:
- **blur**: applies the Gaussian blur for the image.
- **brightness**: applies a linear multiplication to the image to make it look brighter or darker.
- **contrast**: adjusts the image contrast.
- **drop-shadow**: sets a shadow effect for the image.
- **grayscale**: converts the image to a grayscale image.
- **hue-rotate**: applies hue rotation to the image.
- **invert**: inverts the image.
- **opacity**: sets the image opacity.
- **saturate**: sets the image saturation.
- **sepia**: converts the image to sepia.| + +**Example** + ``` + +
+ +
+ ``` + + ``` + //xxx.js + export default { + onShow(){ + var ctx = this.$refs.canvasId.getContext('2d'); + var offscreen = new OffscreenCanvas(360, 500); + var offCanvas2 = offscreen.getContext("2d"); + var img = new Image(); + img.src = 'common/images/flower.jpg'; + offCanvas2.drawImage(img, 0, 0, 100, 100); + offCanvas2.filter = 'blur(5px)'; + offCanvas2.drawImage(img, 100, 0, 100, 100); + + offCanvas2.filter = 'grayscale(50%)'; + offCanvas2.drawImage(img, 200, 0, 100, 100); + + offCanvas2.filter = 'hue-rotate(90deg)'; + offCanvas2.drawImage(img, 0, 100, 100, 100); + + offCanvas2.filter = 'invert(100%)'; + offCanvas2.drawImage(img, 100, 100, 100, 100); + + offCanvas2.filter = 'drop-shadow(8px 8px 10px green)'; + offCanvas2.drawImage(img, 200, 100, 100, 100); + + offCanvas2.filter = 'brightness(0.4)'; + offCanvas2.drawImage(img, 0, 200, 100, 100); + + offCanvas2.filter = 'opacity(25%)'; + offCanvas2.drawImage(img, 100, 200, 100, 100); + + offCanvas2.filter = 'saturate(30%)'; + offCanvas2.drawImage(img, 200, 200, 100, 100); + + offCanvas2.filter = 'sepia(60%)'; + offCanvas2.drawImage(img, 0, 300, 100, 100); + + offCanvas2.filter = 'contrast(200%)'; + offCanvas2.drawImage(img, 100, 300, 100, 100); + var bitmap = offscreen.transferToImageBitmap(); + ctx.transferFromImageBitmap(bitmap); } - ``` - - + } + ``` ## Methods -In addition to the attributes that are supported by **CanvasRenderingContext2D**, the following attributes are supported. +In addition to the methods that are supported by **CanvasRenderingContext2D**, the following methods are supported. + ### isPointInPath -isPointInPath\(path?: Path2D, x: number, y: number\): boolean +isPointInPath(path?: Path2D, x: number, y: number): boolean Checks whether a specified point is in the path area. -- Parameters - - | Name | Type | Mandatory | Description | - | ---- | ------ | --------- | ------------------------------------------------------------ | - | path | Path2D | No | Path used for checking. If this parameter is not set, the current path is used. | - | x | number | Yes | X-coordinate of the point used for checking. | - | y | number | Yes | Y-coordinate of the point used for checking. | - -- Return values - - | Type | Description | - | ------- | ---------------------------------------------- | - | boolean | Whether a specified point is in the path area. | - -- Example - - ``` - -
- In path:{{textValue}} - -
- ``` - - ``` - // xxx.js - export default { - data: { - textValue: 0 - }, - onShow(){ - var canvas = this.$refs.canvas.getContext('2d'); - var offscreen = new OffscreenCanvas(500,500); - var offscreenCanvasCtx = offscreen.getContext("2d"); - - offscreenCanvasCtx.rect(10, 10, 100, 100); - offscreenCanvasCtx.fill(); - this.textValue = offscreenCanvasCtx.isPointInPath(30, 70); - - var bitmap = offscreen.transferToImageBitmap(); - canvas.transferFromImageBitmap(bitmap); - } +**Parameters** +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ----------------------------- | +| path | Path2D | No | Path used for checking. If this parameter is not set, the current path is used.| +| x | number | Yes | X-coordinate of the point used for checking. | +| y | number | Yes | Y-coordinate of the point used for checking. | + +**Return value** +| Type | Description | +| ------- | ------------- | +| boolean | Whether a specified point is in the path area.| + +**Example** + ``` + +
+ In path:{{textValue}} + +
+ ``` + + ``` + // xxx.js + export default { + data: { + textValue: 0 + }, + onShow(){ + var canvas = this.$refs.canvas.getContext('2d'); + var offscreen = new OffscreenCanvas(500,500); + var offscreenCanvasCtx = offscreen.getContext("2d"); + + offscreenCanvasCtx.rect(10, 10, 100, 100); + offscreenCanvasCtx.fill(); + this.textValue = offscreenCanvasCtx.isPointInPath(30, 70); + + var bitmap = offscreen.transferToImageBitmap(); + canvas.transferFromImageBitmap(bitmap); } - ``` - - ![](figures/en-us_image_0000001224354967.png) + } + ``` +![en-us_image_0000001224354967](figures/en-us_image_0000001224354967.png) ### isPointInStroke -isPointInStroke\(path?: Path2D, x: number, y: number\): boolean +isPointInStroke(path?: Path2D, x: number, y: number): boolean Checks whether a specified point is on the edge line of a path. -- Parameters - - | Name | Type | Mandatory | Description | - | ---- | ------ | --------- | ------------------------------------------------------------ | - | path | Path2D | No | Path used for checking. If this parameter is not set, the current path is used. | - | x | number | Yes | X-coordinate of the point used for checking. | - | y | number | Yes | Y-coordinate of the point used for checking. | - -- Return values - - | Type | Description | - | ------- | ---------------------------------------------- | - | boolean | Whether a specified point is in the path area. | - -- Example - - ``` - -
- In path:{{textValue}} - -
- ``` - - ``` - // xxx.js - export default { - data: { - textValue: 0 - }, - onShow(){ - var canvas = this.$refs.canvas.getContext('2d'); - var offscreen = new OffscreenCanvas(500,500); - var offscreenCanvasCtx = offscreen.getContext("2d"); - - offscreenCanvasCtx.rect(10, 10, 100, 100); - offscreenCanvasCtx.stroke(); - this.textValue = offscreenCanvasCtx.isPointInStroke(50, 10); - - var bitmap = offscreen.transferToImageBitmap(); - canvas.transferFromImageBitmap(bitmap); - } +**Parameters** +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ----------------------------- | +| path | Path2D | No | Path used for checking. If this parameter is not set, the current path is used.| +| x | number | Yes | X-coordinate of the point used for checking. | +| y | number | Yes | Y-coordinate of the point used for checking. | + +**Return value** +| Type | Description | +| ------- | ------------- | +| boolean | Whether a specified point is in the path area.| + +**Example** + ``` + +
+ In path:{{textValue}} + +
+ ``` + + ``` + // xxx.js + export default { + data: { + textValue: 0 + }, + onShow(){ + var canvas = this.$refs.canvas.getContext('2d'); + var offscreen = new OffscreenCanvas(500,500); + var offscreenCanvasCtx = offscreen.getContext("2d"); + + offscreenCanvasCtx.rect(10, 10, 100, 100); + offscreenCanvasCtx.stroke(); + this.textValue = offscreenCanvasCtx.isPointInStroke(50, 10); + + var bitmap = offscreen.transferToImageBitmap(); + canvas.transferFromImageBitmap(bitmap); } - ``` - - ![](figures/en-us_image_0000001178875308.png) + } + ``` +![en-us_image_0000001178875308](figures/en-us_image_0000001178875308.png) ### resetTransform -resetTransform\(\): void - -- Example - - ``` - -
- In path:{{textValue}} - -
- ``` - - ``` - //xxx.js - export default { - data:{ - textValue:0 - }, - onShow(){ - var canvas = this.$refs.canvas.getContext('2d'); - var offscreen = new OffscreenCanvas(500,500); - var offscreenCanvasCtx = offscreen.getContext("2d"); - - offscreenCanvasCtx.transform(1, 0, 1.7, 1, 0, 0); - offscreenCanvasCtx.fillStyle = 'gray'; - offscreenCanvasCtx.fillRect(40, 40, 50, 20); - offscreenCanvasCtx.fillRect(40, 90, 50, 20); - - // Non-skewed rectangles - offscreenCanvasCtx.resetTransform(); - offscreenCanvasCtx.fillStyle = 'red'; - offscreenCanvasCtx.fillRect(40, 40, 50, 20); - offscreenCanvasCtx.fillRect(40, 90, 50, 20); - - var bitmap = offscreen.transferToImageBitmap(); - canvas.transferFromImageBitmap(bitmap); - } - } - ``` - - ![](figures/en-us_image_0000001179035242.png) - +resetTransform(): void + +**Example** + ``` + +
+ In path:{{textValue}} + +
+ ``` + + ``` + //xxx.js + export default { + data:{ + textValue:0 + }, + onShow(){ + var canvas = this.$refs.canvas.getContext('2d'); + var offscreen = new OffscreenCanvas(500,500); + var offscreenCanvasCtx = offscreen.getContext("2d"); + + offscreenCanvasCtx.transform(1, 0, 1.7, 1, 0, 0); + offscreenCanvasCtx.fillStyle = '#a9a9a9'; + offscreenCanvasCtx.fillRect(40, 40, 50, 20); + offscreenCanvasCtx.fillRect(40, 90, 50, 20); + + // Non-skewed rectangles + offscreenCanvasCtx.resetTransform(); + offscreenCanvasCtx.fillStyle = '#ff0000'; + offscreenCanvasCtx.fillRect(40, 40, 50, 20); + offscreenCanvasCtx.fillRect(40, 90, 50, 20); + + var bitmap = offscreen.transferToImageBitmap(); + canvas.transferFromImageBitmap(bitmap); + } + } + ``` + +![en-us_image_0000001179035242](figures/en-us_image_0000001179035242.png) diff --git a/en/application-dev/reference/arkui-ts/ts-canvasrenderingcontext2d.md b/en/application-dev/reference/arkui-ts/ts-canvasrenderingcontext2d.md index 1e0ce0647f6067d5396e131e6bcc7ac75bc6a718..19d0aac5c5096003b9533bd4af274ab66d6bcdc7 100644 --- a/en/application-dev/reference/arkui-ts/ts-canvasrenderingcontext2d.md +++ b/en/application-dev/reference/arkui-ts/ts-canvasrenderingcontext2d.md @@ -428,7 +428,7 @@ struct LineDashOffset { this.context.arc(100, 75, 50, 0, 6.28) this.context.setLineDash([10,20]) this.context.lineDashOffset = 10.0 - this.context.stroke() + this.context.stroke(); }) } .width('100%') @@ -721,8 +721,8 @@ Draws an outlined rectangle on the canvas. @Entry @Component struct StrokeRect { - private settings: RenderingContextSettings = new RenderingContextSettings(true) - private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) + private settings: RenderingContextSettings = new RenderingContextSettings(true); + private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings); build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -802,8 +802,6 @@ Draws filled text on the canvas. | text | string | Yes | '' | Text to draw. | | x | number | Yes | 0 | X-coordinate of the lower left corner of the text.| | y | number | Yes | 0 | Y-coordinate of the lower left corner of the text.| -| maxWidth | number | No | - | Maximum width allowed for the text. | - **Example** ```ts @@ -1583,7 +1581,7 @@ struct Fill { region.lineTo(270, 90) region.closePath() // Fill path - this.context.fillStyle = 'green' + this.context.fillStyle = '#00ff00' this.context.fill(region, "evenodd") }) } @@ -2269,7 +2267,7 @@ struct CanvasGetLineDash { .onReady(() => { this.context.arc(100, 75, 50, 0, 6.28) this.context.setLineDash([10,20]) - this.context.stroke() + this.context.stroke(); let res = this.context.getLineDash() }) } @@ -2408,7 +2406,8 @@ Restores the saved drawing context. struct CanvasExample { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - + private img:ImageBitmap = new ImageBitmap("common/images/icon.jpg") + build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Canvas(this.context) @@ -2417,7 +2416,7 @@ Restores the saved drawing context. .backgroundColor('#ffff00') .onReady(() =>{ this.context.save() // save the default state - this.context.fillStyle = "green" + this.context.fillStyle = "#00ff00" this.context.fillRect(20, 20, 100, 100) this.context.restore() // restore to the default state this.context.fillRect(150, 75, 100, 100) @@ -2455,7 +2454,7 @@ Saves all states of the canvas in the stack. This API is usually called when the .backgroundColor('#ffff00') .onReady(() =>{ this.context.save() // save the default state - this.context.fillStyle = "green" + this.context.fillStyle = "#00ff00" this.context.fillRect(20, 20, 100, 100) this.context.restore() // restore to the default state this.context.fillRect(150, 75, 100, 100) @@ -2502,9 +2501,9 @@ Creates a linear gradient. .backgroundColor('#ffff00') .onReady(() =>{ var grad = this.context.createLinearGradient(50,0, 300,100) - grad.addColorStop(0.0, 'red') - grad.addColorStop(0.5, 'white') - grad.addColorStop(1.0, 'green') + grad.addColorStop(0.0, '#ff0000') + grad.addColorStop(0.5, '#ffffff') + grad.addColorStop(1.0, '#00ff00') this.context.fillStyle = grad this.context.fillRect(0, 0, 500, 500) }) @@ -2553,9 +2552,9 @@ Creates a linear gradient. .backgroundColor('#ffff00') .onReady(() =>{ var grad = this.context.createRadialGradient(200,200,50, 200,200,200) - grad.addColorStop(0.0, 'red') - grad.addColorStop(0.5, 'white') - grad.addColorStop(1.0, 'green') + grad.addColorStop(0.0, '#ff0000') + grad.addColorStop(0.5, '#ffffff') + grad.addColorStop(1.0, '#00ff00') this.context.fillStyle = grad this.context.fillRect(0, 0, 500, 500) }) diff --git a/en/application-dev/reference/arkui-ts/ts-components-canvas-canvasgradient.md b/en/application-dev/reference/arkui-ts/ts-components-canvas-canvasgradient.md index 4ed45d0084a9d456f6fa715775d001b1e054808b..7c8b95655a9470ea7fd1951132f7b2c7974a45da 100644 --- a/en/application-dev/reference/arkui-ts/ts-components-canvas-canvasgradient.md +++ b/en/application-dev/reference/arkui-ts/ts-components-canvas-canvasgradient.md @@ -17,10 +17,10 @@ Adds a color stop for the **CanvasGradient** object based on the specified offse **Parameters** - | Name | Type | Mandatory | Default Value | Description | - | ------ | ------ | ---- | --------- | ---------------------------- | - | offset | number | Yes | 0 | Relative position of the gradient stop along the gradient vector. The value ranges from 0 to 1.| - | color | string | Yes | '#ffffff' | Gradient color to set. | +| Name | Type | Mandatory | Default Value | Description | +| ------ | ------ | ---- | --------- | ---------------------------- | +| offset | number | Yes | 0 | Relative position of the gradient stop along the gradient vector. The value ranges from 0 to 1.| +| color | string | Yes | '#ffffff' | Gradient color to set. | **Example** @@ -41,9 +41,9 @@ struct Page45 { .backgroundColor('#ffff00') .onReady(() => { var grad = this.context.createLinearGradient(50, 0, 300, 100) - grad.addColorStop(0.0, 'red') - grad.addColorStop(0.5, 'white') - grad.addColorStop(1.0, 'green') + grad.addColorStop(0.0, '#ff0000') + grad.addColorStop(0.5, '#ffffff') + grad.addColorStop(1.0, '#00ff00') this.context.fillStyle = grad this.context.fillRect(0, 0, 500, 500) }) diff --git a/en/application-dev/reference/arkui-ts/ts-offscreencanvasrenderingcontext2d.md b/en/application-dev/reference/arkui-ts/ts-offscreencanvasrenderingcontext2d.md index abfbce542354cce435a5e611f13f8bc73b28e64f..9f04894b549d772d71561ed46d46c094dc839a60 100644 --- a/en/application-dev/reference/arkui-ts/ts-offscreencanvasrenderingcontext2d.md +++ b/en/application-dev/reference/arkui-ts/ts-offscreencanvasrenderingcontext2d.md @@ -182,7 +182,7 @@ struct LineCapExample { } ``` -![en-us_image_0000001194192454](figures/en-us_image_0000001194192454.PNG) +![en-us_image_0000001194192454](figures/en-us_image_0000001194192454.png) ### lineJoin @@ -2625,9 +2625,9 @@ Creates a linear gradient. .backgroundColor('#ffff00') .onReady(() =>{ var grad = this.offContext.createLinearGradient(50,0, 300,100) - grad.addColorStop(0.0, 'red') - grad.addColorStop(0.5, 'white') - grad.addColorStop(1.0, 'green') + grad.addColorStop(0.0, '#ff0000') + grad.addColorStop(0.5, '#ffffff') + grad.addColorStop(1.0, '#00ff00') this.offContext.fillStyle = grad this.offContext.fillRect(0, 0, 500, 500) var image = this.offContext.transferToImageBitmap() @@ -2679,9 +2679,9 @@ Creates a linear gradient. .backgroundColor('#ffff00') .onReady(() =>{ var grad = this.offContext.createRadialGradient(200,200,50, 200,200,200) - grad.addColorStop(0.0, 'red') - grad.addColorStop(0.5, 'white') - grad.addColorStop(1.0, 'green') + grad.addColorStop(0.0, '#ff0000') + grad.addColorStop(0.5, '#ffffff') + grad.addColorStop(1.0, '#00ff00') this.offContext.fillStyle = grad this.offContext.fillRect(0, 0, 500, 500) var image = this.offContext.transferToImageBitmap()