You need to sign in or sign up before continuing.
提交 02f0a7d5 编写于 作者: E ester.zhou

update docs (7222)

Signed-off-by: Nester.zhou <ester.zhou@huawei.com>
上级 0b3ac1a4
# CanvasGradient<a name="EN-US_TOPIC_0000001173164733"></a> # CanvasGradient
**CanvasGradient** provides a gradient object. > **NOTE**
>
> This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version.
## addColorStop<a name="section12691015917"></a> **CanvasGradient** provides a gradient object.
addColorStop\(offset: number, color: string\): void
Adds a color stop for the** CanvasGradient** object based on the specified offset and gradient color.
- Parameters
<a name="table1032173253712"></a>
<table><thead align="left"><tr id="row166643263712"><th class="cellrowborder" valign="top" width="21.69%" id="mcps1.1.4.1.1"><p id="p1966932123714"><a name="p1966932123714"></a><a name="p1966932123714"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="34.74%" id="mcps1.1.4.1.2"><p id="p10661232173710"><a name="p10661232173710"></a><a name="p10661232173710"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="43.57%" id="mcps1.1.4.1.3"><p id="p66673283719"><a name="p66673283719"></a><a name="p66673283719"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row1166193243714"><td class="cellrowborder" valign="top" width="21.69%" headers="mcps1.1.4.1.1 "><p id="p96673263717"><a name="p96673263717"></a><a name="p96673263717"></a>offset</p>
</td>
<td class="cellrowborder" valign="top" width="34.74%" headers="mcps1.1.4.1.2 "><p id="p1674323372"><a name="p1674323372"></a><a name="p1674323372"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="43.57%" headers="mcps1.1.4.1.3 "><p id="p12672326374"><a name="p12672326374"></a><a name="p12672326374"></a>Proportion of the distance between the color stop and the start point to the total length. The value ranges from 0 to 1.</p>
</td>
</tr>
<tr id="row146783253715"><td class="cellrowborder" valign="top" width="21.69%" headers="mcps1.1.4.1.1 "><p id="p46773203715"><a name="p46773203715"></a><a name="p46773203715"></a>color</p>
</td>
<td class="cellrowborder" valign="top" width="34.74%" headers="mcps1.1.4.1.2 "><p id="p1967173213712"><a name="p1967173213712"></a><a name="p1967173213712"></a>string</p>
</td>
<td class="cellrowborder" valign="top" width="43.57%" headers="mcps1.1.4.1.3 "><p id="p1467123233710"><a name="p1467123233710"></a><a name="p1467123233710"></a>Gradient color to set.</p>
</td>
</tr>
</tbody>
</table>
- Example Code
```
<!-- xxx.hml -->
<div>
<canvas ref="canvas" style="width: 500px; height: 500px; background-color: #ffff00;"></canvas>
<input type="button" style="width: 180px; height: 60px;" value="fillStyle" onclick="handleClick" />
</div>
```
```
// xxx.js
export default {
handleClick() {
const el =this.$refs.canvas;
const ctx =el.getContext('2d');
const gradient = ctx.createLinearGradient(0,0,100,0);
gradient.addColorStop(0,'#00ffff');
gradient.addColorStop(1,'#ffff00');
}
}
```
![](figures/en-us_image_0000001152610806.png)
## addColorStop
addColorStop(offset: number, color: string): void
Adds a color stop for the **CanvasGradient** object based on the specified offset and gradient color.
**Parameters**
| Name | Type | Description |
| ------ | ------ | ------------------------------------------------------------ |
| offset | number | Proportion of the distance between the color stop and the start point to the total length. The value ranges from 0 to 1. |
| color | string | Gradient color to set. |
**Example**
```html
<!-- xxx.hml -->
<div>
<canvas ref="canvas" style="width: 500px; height: 500px; background-color: #ffff00;"></canvas>
<input type="button" style="width: 180px; height: 60px;" value="fillStyle"onclick="handleClick" />
</div>
```
```js
// xxx.js
export default {
handleClick() {
const el =this.$refs.canvas;
const ctx =el.getContext('2d');
const gradient = ctx.createLinearGradient(0,0,100,0);
gradient.addColorStop(0,'#00ffff');
gradient.addColorStop(1,'#ffff00');
}
}
```
![en-us_image_0000001152610806](figures/en-us_image_0000001152610806.png)
# Path2D<a name="EN-US_TOPIC_0000001173164751"></a> # Path2D
**Path2D** allows you to describe a path through an existing path. This path can be drawn through the **stroke** API of **Canvas**. > **NOTE**
>
> This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version.
## addPath<a name="section12484748163816"></a> **Path2D** allows you to describe a path through an existing path. This path can be drawn through the **stroke** API of **Canvas**.
addPath\(path: Object\): void ## addPath
addPath(path: Object): void
Adds a path to this path. Adds a path to this path.
- Parameters **Parameters**
<a name="table1948454813819"></a> | Name | Type | Description |
<table><thead align="left"><tr id="row17484114816383"><th class="cellrowborder" valign="top" width="21.69%" id="mcps1.1.4.1.1"><p id="p1348494853817"><a name="p1348494853817"></a><a name="p1348494853817"></a>Name</p> | ---- | ------ | ------------------------------ |
</th> | path | Object | Path to be added to this path. |
<th class="cellrowborder" valign="top" width="34.74%" id="mcps1.1.4.1.2"><p id="p1148414873815"><a name="p1148414873815"></a><a name="p1148414873815"></a>Type</p>
</th> **Example**
<th class="cellrowborder" valign="top" width="43.57%" id="mcps1.1.4.1.3"><p id="p34841948133816"><a name="p34841948133816"></a><a name="p34841948133816"></a>Description</p> ```html
</th> <!-- xxx.hml -->
</tr> <div>
</thead> <canvas ref="canvas" style="width: 500px; height: 500px; background-color: #ffff00;"></canvas>
<tbody><tr id="row1148424813816"><td class="cellrowborder" valign="top" width="21.69%" headers="mcps1.1.4.1.1 "><p id="p64848482383"><a name="p64848482383"></a><a name="p64848482383"></a>path</p> </div>
</td> ```
<td class="cellrowborder" valign="top" width="34.74%" headers="mcps1.1.4.1.2 "><p id="p9484194817384"><a name="p9484194817384"></a><a name="p9484194817384"></a>Object</p>
</td> ```js
<td class="cellrowborder" valign="top" width="43.57%" headers="mcps1.1.4.1.3 "><p id="p9484144883813"><a name="p9484144883813"></a><a name="p9484144883813"></a>Path to be added to this path.</p> // xxx.js
</td> export default {
</tr> onShow() {
</tbody> const el =this.$refs.canvas;
</table> const ctx = el.getContext('2d');
var path1 = ctx.createPath2D("M250 150 L150 350 L350 350 Z");
- Example var path2 = ctx.createPath2D();
path2.addPath(path1);
``` ctx.stroke(path2);
<!-- xxx.hml --> }
<div> }
<canvas ref="canvas" style="width: 500px; height: 500px; background-color: #ffff00;"></canvas> ```
</div>
``` ![en-us_image_0000001173164873](figures/en-us_image_0000001173164873.png)
``` ## setTransform
//xxx.js
export default { setTransform(scaleX: number, skewX: number, skewY: number, scaleY: number, translateX: number, translateY: number): void
onShow() {
const el =this.$refs.canvas;
const ctx = el.getContext('2d');
var path1 = ctx.createPath2D("M250 150 L150 350 L350 350 Z");
var path2 = ctx.createPath2D();
path2.addPath(path1);
ctx.stroke(path2);
}
}
```
![](figures/en-us_image_0000001173164873.png)
## setTransform<a name="section68262045132013"></a>
setTransform\(scaleX: number, skewX: number, skewY: number, scaleY: number, translateX: number, translateY: number\): void
Sets the path transformation matrix. Sets the path transformation matrix.
- Parameters **Parameters**
<a name="table4826104515201"></a> | Name | Type | Description |
<table><thead align="left"><tr id="row58261345122010"><th class="cellrowborder" valign="top" width="33.333333333333336%" id="mcps1.1.4.1.1"><p id="p1382684562019"><a name="p1382684562019"></a><a name="p1382684562019"></a>Name</p> | ---------- | ------ | ----------------------------------- |
</th> | scaleX | number | Scale ratio of the x-axis. |
<th class="cellrowborder" valign="top" width="33.333333333333336%" id="mcps1.1.4.1.2"><p id="p382617450202"><a name="p382617450202"></a><a name="p382617450202"></a>Type</p> | skewX | number | Skew angle of the x-axis. |
</th> | skewY | number | Skew angle of the y-axis. |
<th class="cellrowborder" valign="top" width="33.333333333333336%" id="mcps1.1.4.1.3"><p id="p48261945172017"><a name="p48261945172017"></a><a name="p48261945172017"></a>Description</p> | scaleY | number | Scale ratio of the y-axis. |
</th> | translateX | number | Translation distance of the x-axis. |
</tr> | translateY | number | Translation distance of the y-axis. |
</thead>
<tbody><tr id="row1182611454206"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p178262456205"><a name="p178262456205"></a><a name="p178262456205"></a>scaleX</p> **Example**
</td> ```html
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p182620458203"><a name="p182620458203"></a><a name="p182620458203"></a>number</p> <!-- xxx.hml -->
</td> <div>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p10751910222"><a name="p10751910222"></a><a name="p10751910222"></a>Scale ratio of the x-axis</p> <canvas ref="canvas" style="width: 200px; height: 150px; background-color: #ffff00;"></canvas>
</td> </div>
</tr> ```
<tr id="row168266458201"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p16827445142013"><a name="p16827445142013"></a><a name="p16827445142013"></a>skewX</p>
</td> ```js
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p68274454204"><a name="p68274454204"></a><a name="p68274454204"></a>number</p> // xxx.js
</td> export default {
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p71155207223"><a name="p71155207223"></a><a name="p71155207223"></a>Skew angle of the x-axis</p> onShow() {
</td> const el =this.$refs.canvas;
</tr> const ctx = el.getContext('2d');
<tr id="row38271945122016"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p7827134572011"><a name="p7827134572011"></a><a name="p7827134572011"></a>skewY</p> var path = ctx.createPath2D("M250 150 L150 350 L350 350 Z");
</td> path.setTransform(0.8, 0, 0, 0.4, 0, 0);
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p168275453206"><a name="p168275453206"></a><a name="p168275453206"></a>number</p> ctx.stroke(path);
</td> }
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p562016295229"><a name="p562016295229"></a><a name="p562016295229"></a>Skew angle of the y-axis</p> }
</td> ```
</tr>
<tr id="row13827114514206"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p11827745122012"><a name="p11827745122012"></a><a name="p11827745122012"></a>scaleY</p> ![en-us_image_0000001127125208](figures/en-us_image_0000001127125208.png)
</td>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p168272459209"><a name="p168272459209"></a><a name="p168272459209"></a>number</p>
</td> ## closePath
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p19205153616222"><a name="p19205153616222"></a><a name="p19205153616222"></a>Scale ratio of the y-axis</p>
</td> closePath(): void
</tr>
<tr id="row482704512010"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p2082713455206"><a name="p2082713455206"></a><a name="p2082713455206"></a>translateX</p>
</td>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p5827104512206"><a name="p5827104512206"></a><a name="p5827104512206"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p10511942152217"><a name="p10511942152217"></a><a name="p10511942152217"></a>Translation distance of the x-axis</p>
</td>
</tr>
<tr id="row1274814215213"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p574820262114"><a name="p574820262114"></a><a name="p574820262114"></a>translateY</p>
</td>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p1174820232117"><a name="p1174820232117"></a><a name="p1174820232117"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p1645314484227"><a name="p1645314484227"></a><a name="p1645314484227"></a>Translation distance of the y-axis</p>
</td>
</tr>
</tbody>
</table>
- Example
```
<!-- xxx.hml -->
<div>
<canvas ref="canvas" style="width: 200px; height: 150px; background-color: #ffff00;"></canvas>
</div>
```
```
//xxx.js
export default {
onShow() {
const el =this.$refs.canvas;
const ctx = el.getContext('2d');
var path = ctx.createPath2D("M250 150 L150 350 L350 350 Z");
path.setTransform(0.8, 0, 0, 0.4, 0, 0);
ctx.stroke(path);
}
}
```
![](figures/en-us_image_0000001127125208.png)
## closePath<a name="section653891424217"></a>
closePath\(\): void
Moves the current point of the path back to the start point of the path, and draws a straight line between the current point and the start point. If the shape is closed or has only one point, this method does not perform any action. Moves the current point of the path back to the start point of the path, and draws a straight line between the current point and the start point. If the shape is closed or has only one point, this method does not perform any action.
- Example **Example**
```html
<!-- xxx.hml -->
<div>
<canvas ref="canvas" style="width: 200px; height: 150px; background-color: #ffff00;"></canvas>
</div>
```
```js
// xxx.js
export default {
onShow() {
const el =this.$refs.canvas;
const ctx = el.getContext('2d');
var path = ctx.createPath2D();
path.moveTo(200, 100);
path.lineTo(300, 100);
path.lineTo(200, 200);
path.closePath();
ctx.stroke(path);
}
}
```
![](figures/en-us_image_0000001127125202.png)
## moveTo
moveTo(x: number, y: number): void
``` Moves the current coordinate point of the path to the target point, without drawing a line during the movement.
<!-- xxx.hml -->
<div>
<canvas ref="canvas" style="width: 200px; height: 150px; background-color: #ffff00;"></canvas>
</div>
```
``` **Parameters**
//xxx.js
export default {
onShow() {
const el =this.$refs.canvas;
const ctx = el.getContext('2d');
var path = ctx.createPath2D();
path.moveTo(200, 100);
path.lineTo(300, 100);
path.lineTo(200, 200);
path.closePath();
ctx.stroke(path);
}
}
```
![](figures/en-us_image_0000001127125202.png) | Parameter | Type | Description |
| --------- | ------ | --------------------------------- |
| x | number | X-coordinate of the target point. |
| y | number | Y-coordinate of the target point. |
**Example**
```html
<!-- xxx.hml -->
<div>
<canvas ref="canvas" style="width: 300px; height: 250px; background-color: #ffff00;"></canvas>
</div>
```
## moveTo<a name="section384917162456"></a> ```js
// xxx.js
export default {
onShow() {
const el =this.$refs.canvas;
const ctx = el.getContext('2d');
var path = ctx.createPath2D();
path.moveTo(50, 100);
path.lineTo(250, 100);
path.lineTo(150, 200);
path.closePath();
ctx.stroke(path);
}
}
```
moveTo\(x: number, y: number\): void ![en-us_image_0000001173164869](figures/en-us_image_0000001173164869.png)
Moves the current coordinate point of the path to the target point, without drawing a line during the movement.
- Parameters ## lineTo
<a name="table78491916124512"></a> lineTo(x: number, y: number): void
<table><thead align="left"><tr id="row14850181613456"><th class="cellrowborder" valign="top" width="21.69%" id="mcps1.1.4.1.1"><p id="p11850191612454"><a name="p11850191612454"></a><a name="p11850191612454"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="34.74%" id="mcps1.1.4.1.2"><p id="p9850416144514"><a name="p9850416144514"></a><a name="p9850416144514"></a>Type</p>
</th>
<th class="cellrowborder" valign="top" width="43.57%" id="mcps1.1.4.1.3"><p id="p1850816154519"><a name="p1850816154519"></a><a name="p1850816154519"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row6850181612455"><td class="cellrowborder" valign="top" width="21.69%" headers="mcps1.1.4.1.1 "><p id="p17850161612455"><a name="p17850161612455"></a><a name="p17850161612455"></a>x</p>
</td>
<td class="cellrowborder" valign="top" width="34.74%" headers="mcps1.1.4.1.2 "><p id="p118501716164516"><a name="p118501716164516"></a><a name="p118501716164516"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="43.57%" headers="mcps1.1.4.1.3 "><p id="p3850181634517"><a name="p3850181634517"></a><a name="p3850181634517"></a>X-coordinate of the target point</p>
</td>
</tr>
<tr id="row12850181618452"><td class="cellrowborder" valign="top" width="21.69%" headers="mcps1.1.4.1.1 "><p id="p1185081616453"><a name="p1185081616453"></a><a name="p1185081616453"></a>y</p>
</td>
<td class="cellrowborder" valign="top" width="34.74%" headers="mcps1.1.4.1.2 "><p id="p98506164455"><a name="p98506164455"></a><a name="p98506164455"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="43.57%" headers="mcps1.1.4.1.3 "><p id="p138501116104518"><a name="p138501116104518"></a><a name="p138501116104518"></a>Y-coordinate of the target point</p>
</td>
</tr>
</tbody>
</table>
- Example
```
<!-- xxx.hml -->
<div>
<canvas ref="canvas" style="width: 300px; height: 250px; background-color: #ffff00;"></canvas>
</div>
```
```
//xxx.js
export default {
onShow() {
const el =this.$refs.canvas;
const ctx = el.getContext('2d');
var path = ctx.createPath2D();
path.moveTo(50, 100);
path.lineTo(250, 100);
path.lineTo(150, 200);
path.closePath();
ctx.stroke(path);
}
}
```
![](figures/en-us_image_0000001173164869.png)
## lineTo<a name="section1374011322484"></a>
lineTo\(x: number, y: number\): void
Draws a straight line from the current point to the target point. Draws a straight line from the current point to the target point.
- Parameters **Parameters**
<a name="table174093224819"></a> | Parameter | Type | Description |
<table><thead align="left"><tr id="row187401432134818"><th class="cellrowborder" valign="top" width="21.69%" id="mcps1.1.4.1.1"><p id="p374173224817"><a name="p374173224817"></a><a name="p374173224817"></a>Parameter</p> | --------- | ------ | --------------------------------- |
</th> | x | number | X-coordinate of the target point. |
<th class="cellrowborder" valign="top" width="34.74%" id="mcps1.1.4.1.2"><p id="p2741183219482"><a name="p2741183219482"></a><a name="p2741183219482"></a>Type</p> | y | number | Y-coordinate of the target point. |
</th>
<th class="cellrowborder" valign="top" width="43.57%" id="mcps1.1.4.1.3"><p id="p1774112327488"><a name="p1774112327488"></a><a name="p1774112327488"></a>Description</p> **Example**
</th>
</tr> ```html
</thead> <!-- xxx.hml -->
<tbody><tr id="row1741143284810"><td class="cellrowborder" valign="top" width="21.69%" headers="mcps1.1.4.1.1 "><p id="p19741103254812"><a name="p19741103254812"></a><a name="p19741103254812"></a>x</p> <div>
</td> <canvas ref="canvas" style="width: 400px; height: 450px; background-color: #ffff00;"></canvas>
<td class="cellrowborder" valign="top" width="34.74%" headers="mcps1.1.4.1.2 "><p id="p57411832154812"><a name="p57411832154812"></a><a name="p57411832154812"></a>number</p> </div>
</td> ```
<td class="cellrowborder" valign="top" width="43.57%" headers="mcps1.1.4.1.3 "><p id="p1474119322489"><a name="p1474119322489"></a><a name="p1474119322489"></a>X-coordinate of the target point</p>
</td> ```js
</tr> // xxx.js
<tr id="row97411532144814"><td class="cellrowborder" valign="top" width="21.69%" headers="mcps1.1.4.1.1 "><p id="p14741193212488"><a name="p14741193212488"></a><a name="p14741193212488"></a>y</p> export default {
</td> onShow() {
<td class="cellrowborder" valign="top" width="34.74%" headers="mcps1.1.4.1.2 "><p id="p127411332174814"><a name="p127411332174814"></a><a name="p127411332174814"></a>number</p> const el =this.$refs.canvas;
</td> const ctx = el.getContext('2d');
<td class="cellrowborder" valign="top" width="43.57%" headers="mcps1.1.4.1.3 "><p id="p137412326481"><a name="p137412326481"></a><a name="p137412326481"></a>Y-coordinate of the target point</p> var path = ctx.createPath2D();
</td> path.moveTo(100, 100);
</tr> path.lineTo(100, 200);
</tbody> path.lineTo(200, 200);
</table> path.lineTo(200, 100);
path.closePath();
- Example ctx.stroke(path);
}
``` }
<!-- xxx.hml --> ```
<div>
<canvas ref="canvas" style="width: 400px; height: 450px; background-color: #ffff00;"></canvas> ![en-us_image_0000001127285024](figures/en-us_image_0000001127285024.png)
</div>
```
## bezierCurveTo
```
//xxx.js bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void
export default {
onShow() {
const el =this.$refs.canvas;
const ctx = el.getContext('2d');
var path = ctx.createPath2D();
path.moveTo(100, 100);
path.lineTo(100, 200);
path.lineTo(200, 200);
path.lineTo(200, 100);
path.closePath();
ctx.stroke(path);
}
}
```
![](figures/en-us_image_0000001127285024.png)
## bezierCurveTo<a name="section122413525494"></a>
bezierCurveTo\(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number\): void
Draws a cubic bezier curve on the canvas. Draws a cubic bezier curve on the canvas.
- Parameters **Parameters**
<a name="table5241185218495"></a> | Parameter | Type | Description |
<table><thead align="left"><tr id="row1224175215491"><th class="cellrowborder" valign="top" width="33.333333333333336%" id="mcps1.1.4.1.1"><p id="p192411529491"><a name="p192411529491"></a><a name="p192411529491"></a>Parameter</p> | --------- | ------ | --------------------------------------------------------- |
</th> | cp1x | number | X-coordinate of the first parameter of the bezier curve. |
<th class="cellrowborder" valign="top" width="33.333333333333336%" id="mcps1.1.4.1.2"><p id="p4241052154910"><a name="p4241052154910"></a><a name="p4241052154910"></a>Type</p> | cp1y | number | Y-coordinate of the first parameter of the bezier curve. |
</th> | cp2x | number | X-coordinate of the second parameter of the bezier curve. |
<th class="cellrowborder" valign="top" width="33.333333333333336%" id="mcps1.1.4.1.3"><p id="p5241052114911"><a name="p5241052114911"></a><a name="p5241052114911"></a>Description</p> | cp2y | number | Y-coordinate of the second parameter of the bezier curve |
</th> | x | number | X-coordinate of the end point on the bezier curve. |
</tr> | y | number | Y-coordinate of the end point on the bezier curve. |
</thead>
<tbody><tr id="row624113524497"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p6241135213493"><a name="p6241135213493"></a><a name="p6241135213493"></a>cp1x</p> **Example**
</td> ```html
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p22422529499"><a name="p22422529499"></a><a name="p22422529499"></a>number</p> <!-- xxx.hml -->
</td> <div>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p172421052114919"><a name="p172421052114919"></a><a name="p172421052114919"></a>X-coordinate of the first parameter of the bezier curve</p> <canvas ref="canvas" style="width: 200px; height: 150px; background-color: #ffff00;"></canvas>
</td> </div>
</tr> ```
<tr id="row924225212492"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p4242115213499"><a name="p4242115213499"></a><a name="p4242115213499"></a>cp1y</p>
</td> ```js
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p7242195234910"><a name="p7242195234910"></a><a name="p7242195234910"></a>number</p> // xxx.js
</td> export default {
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p524211522496"><a name="p524211522496"></a><a name="p524211522496"></a>Y-coordinate of the first parameter of the bezier curve</p> onShow() {
</td> const el =this.$refs.canvas;
</tr> const ctx = el.getContext('2d');
<tr id="row1924210522498"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p624214522499"><a name="p624214522499"></a><a name="p624214522499"></a>cp2x</p> var path = ctx.createPath2D();
</td> path.moveTo(10, 10);
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p15242175214914"><a name="p15242175214914"></a><a name="p15242175214914"></a>number</p> path.bezierCurveTo(20, 100, 200, 100, 200, 20);
</td> ctx.stroke(path);
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p524275215490"><a name="p524275215490"></a><a name="p524275215490"></a>X-coordinate of the second parameter of the bezier curve</p> }
</td> }
</tr> ```
<tr id="row1024285214912"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p3242175211491"><a name="p3242175211491"></a><a name="p3242175211491"></a>cp2y</p>
</td> ![en-us_image_0000001173324783](figures/en-us_image_0000001173324783.png)
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p624205215497"><a name="p624205215497"></a><a name="p624205215497"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p124214527499"><a name="p124214527499"></a><a name="p124214527499"></a>Y-coordinate of the second parameter of the bezier curve</p> ## quadraticCurveTo
</td>
</tr> quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void
<tr id="row11242175210494"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p8242185217497"><a name="p8242185217497"></a><a name="p8242185217497"></a>x</p>
</td>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p11242125219493"><a name="p11242125219493"></a><a name="p11242125219493"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p122428527495"><a name="p122428527495"></a><a name="p122428527495"></a>X-coordinate of the end point on the bezier curve</p>
</td>
</tr>
<tr id="row02433524498"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p924345217491"><a name="p924345217491"></a><a name="p924345217491"></a>y</p>
</td>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p1243135224912"><a name="p1243135224912"></a><a name="p1243135224912"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p3243135254915"><a name="p3243135254915"></a><a name="p3243135254915"></a>Y-coordinate of the end point on the bezier curve</p>
</td>
</tr>
</tbody>
</table>
- Example
```
<!-- xxx.hml -->
<div>
<canvas ref="canvas" style="width: 200px; height: 150px; background-color: #ffff00;"></canvas>
</div>
```
```
//xxx.js
export default {
onShow() {
const el =this.$refs.canvas;
const ctx = el.getContext('2d');
var path = ctx.createPath2D();
path.moveTo(10, 10);
path.bezierCurveTo(20, 100, 200, 100, 200, 20);
ctx.stroke(path);
}
}
```
![](figures/en-us_image_0000001173324783.png)
## quadraticCurveTo<a name="section16154556165015"></a>
quadraticCurveTo\(cpx: number, cpy: number, x: number, y: number\): void
Draws a quadratic curve on the canvas. Draws a quadratic curve on the canvas.
- Parameters **Parameters**
<a name="table815416567500"></a> | Parameter | Type | Description |
<table><thead align="left"><tr id="row915445619508"><th class="cellrowborder" valign="top" width="33.333333333333336%" id="mcps1.1.4.1.1"><p id="p1815412561507"><a name="p1815412561507"></a><a name="p1815412561507"></a>Parameter</p> | --------- | ------ | -------------------------------------------------- |
</th> | cpx | number | X-coordinate of the bezier curve parameter. |
<th class="cellrowborder" valign="top" width="33.333333333333336%" id="mcps1.1.4.1.2"><p id="p3154195613509"><a name="p3154195613509"></a><a name="p3154195613509"></a>Type</p> | cpy | number | Y-coordinate of the bezier curve parameter. |
</th> | x | number | X-coordinate of the end point on the bezier curve. |
<th class="cellrowborder" valign="top" width="33.333333333333336%" id="mcps1.1.4.1.3"><p id="p6154456135016"><a name="p6154456135016"></a><a name="p6154456135016"></a>Description</p> | y | number | Y-coordinate of the end point on the bezier curve. |
</th>
</tr> **Example**
</thead> ```html
<tbody><tr id="row51543567505"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p111544569503"><a name="p111544569503"></a><a name="p111544569503"></a>cpx</p> <!-- xxx.hml -->
</td> <div>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p1315419563508"><a name="p1315419563508"></a><a name="p1315419563508"></a>number</p> <canvas ref="canvas" style="width: 200px; height: 150px; background-color: #ffff00;"></canvas>
</td> </div>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p10154105675010"><a name="p10154105675010"></a><a name="p10154105675010"></a>X-coordinate of the bezier curve parameter</p> ```
</td>
</tr> ```js
<tr id="row4154175618504"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p1615410566508"><a name="p1615410566508"></a><a name="p1615410566508"></a>cpy</p> // xxx.js
</td> export default {
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p31540568507"><a name="p31540568507"></a><a name="p31540568507"></a>number</p> onShow() {
</td> const el =this.$refs.canvas;
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p8154165685013"><a name="p8154165685013"></a><a name="p8154165685013"></a>Y-coordinate of the bezier curve parameter</p> const ctx = el.getContext('2d');
</td> var path = ctx.createPath2D();
</tr> path.moveTo(10, 10);
<tr id="row11548564504"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p41551856175018"><a name="p41551856175018"></a><a name="p41551856175018"></a>x</p> path.quadraticCurveTo(100, 100, 200, 20);
</td> ctx.stroke(path);
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p1515575685013"><a name="p1515575685013"></a><a name="p1515575685013"></a>number</p> }
</td> }
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p9155115610507"><a name="p9155115610507"></a><a name="p9155115610507"></a>X-coordinate of the end point on the bezier curve</p> ```
</td>
</tr> ![en-us_image_0000001173164871](figures/en-us_image_0000001173164871.png)
<tr id="row1115555665015"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p18155105685012"><a name="p18155105685012"></a><a name="p18155105685012"></a>y</p>
</td>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p20155856135019"><a name="p20155856135019"></a><a name="p20155856135019"></a>number</p> ## arc
</td>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p5155156125013"><a name="p5155156125013"></a><a name="p5155156125013"></a>Y-coordinate of the end point on the bezier curve</p> arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise: number): void
</td>
</tr>
</tbody>
</table>
- Example
```
<!-- xxx.hml -->
<div>
<canvas ref="canvas" style="width: 200px; height: 150px; background-color: #ffff00;"></canvas>
</div>
```
```
//xxx.js
export default {
onShow() {
const el =this.$refs.canvas;
const ctx = el.getContext('2d');
var path = ctx.createPath2D();
path.moveTo(10, 10);
path.quadraticCurveTo(100, 100, 200, 20);
ctx.stroke(path);
}
}
```
![](figures/en-us_image_0000001173164871.png)
## arc<a name="section950116919527"></a>
arc\(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise: number\): void
Draws an arc on the canvas. Draws an arc on the canvas.
- Parameters **Parameters**
<a name="table1050139185219"></a> | Parameter | Type | Description |
<table><thead align="left"><tr id="row250129165211"><th class="cellrowborder" valign="top" width="33.333333333333336%" id="mcps1.1.4.1.1"><p id="p185016935213"><a name="p185016935213"></a><a name="p185016935213"></a>Parameter</p> | ------------- | ------- | -------------------------------------------- |
</th> | x | number | X-coordinate of the center point of the arc. |
<th class="cellrowborder" valign="top" width="33.333333333333336%" id="mcps1.1.4.1.2"><p id="p250111935212"><a name="p250111935212"></a><a name="p250111935212"></a>Type</p> | y | number | Y-coordinate of the center point of the arc. |
</th> | radius | number | Radius of the arc. |
<th class="cellrowborder" valign="top" width="33.333333333333336%" id="mcps1.1.4.1.3"><p id="p7501997528"><a name="p7501997528"></a><a name="p7501997528"></a>Description</p> | startAngle | number | Start radian of the arc. |
</th> | endAngle | number | End radian of the arc. |
</tr> | anticlockwise | boolean | Whether to draw the arc counterclockwise. |
</thead>
<tbody><tr id="row850189195216"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p175011099524"><a name="p175011099524"></a><a name="p175011099524"></a>x</p> **Example**
</td> ```html
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p14501390521"><a name="p14501390521"></a><a name="p14501390521"></a>number</p> <!-- xxx.hml -->
</td> <div>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p85027935216"><a name="p85027935216"></a><a name="p85027935216"></a>X-coordinate of the center point of the arc</p> <canvas ref="canvas" style="width: 200px; height: 150px; background-color: #ffff00;"></canvas>
</td> </div>
</tr> ```
<tr id="row350216985214"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p55026925210"><a name="p55026925210"></a><a name="p55026925210"></a>y</p>
</td> ```js
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p75021291525"><a name="p75021291525"></a><a name="p75021291525"></a>number</p> // xxx.js
</td> export default {
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p18502193521"><a name="p18502193521"></a><a name="p18502193521"></a>Y-coordinate of the center point of the arc</p> onShow() {
</td> const el =this.$refs.canvas;
</tr> const ctx = el.getContext('2d');
<tr id="row2502169185215"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p150211925210"><a name="p150211925210"></a><a name="p150211925210"></a>radius</p> var path = ctx.createPath2D();
</td> path.arc(100, 75, 50, 0, 6.28);
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p550211913528"><a name="p550211913528"></a><a name="p550211913528"></a>number</p> ctx.stroke(path);
</td> }
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p13502169135212"><a name="p13502169135212"></a><a name="p13502169135212"></a>Radius of the arc</p> }
</td> ```
</tr>
<tr id="row550212975211"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p1350212985217"><a name="p1350212985217"></a><a name="p1350212985217"></a>startAngle</p> ![en-us_image_0000001173164867](figures/en-us_image_0000001173164867.png)
</td>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p85029985211"><a name="p85029985211"></a><a name="p85029985211"></a>number</p>
</td> ## arcTo
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p165021920526"><a name="p165021920526"></a><a name="p165021920526"></a>Start radian of the arc</p>
</td> arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void
</tr>
<tr id="row25022912524"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p105021912522"><a name="p105021912522"></a><a name="p105021912522"></a>endAngle</p>
</td>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p150219925218"><a name="p150219925218"></a><a name="p150219925218"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p550213945213"><a name="p550213945213"></a><a name="p550213945213"></a>End radian of the arc</p>
</td>
</tr>
<tr id="row250218913526"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p850216913520"><a name="p850216913520"></a><a name="p850216913520"></a>anticlockwise</p>
</td>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p1850219914524"><a name="p1850219914524"></a><a name="p1850219914524"></a>boolean</p>
</td>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p105031691522"><a name="p105031691522"></a><a name="p105031691522"></a>Whether to draw the arc counterclockwise</p>
</td>
</tr>
</tbody>
</table>
- Example
```
<!-- xxx.hml -->
<div>
<canvas ref="canvas" style="width: 200px; height: 150px; background-color: #ffff00;"></canvas>
</div>
```
```
//xxx.js
export default {
onShow() {
const el =this.$refs.canvas;
const ctx = el.getContext('2d');
var path = ctx.createPath2D();
path.arc(100, 75, 50, 0, 6.28);
ctx.stroke(path);
}
}
```
![](figures/en-us_image_0000001173164867.png)
## arcTo<a name="section98421358175219"></a>
arcTo\(x1: number, y1: number, x2: number, y2: number, radius: number\): void
Draws an arc based on the radius and points on the arc. Draws an arc based on the radius and points on the arc.
- Parameters **Parameters**
<a name="table584265819528"></a> | Parameter | Type | Description |
<table><thead align="left"><tr id="row198421584521"><th class="cellrowborder" valign="top" width="33.333333333333336%" id="mcps1.1.4.1.1"><p id="p12842115815217"><a name="p12842115815217"></a><a name="p12842115815217"></a>Parameter</p> | --------- | ------ | -------------------------------------------- |
</th> | x1 | number | X-coordinate of the first point on the arc. |
<th class="cellrowborder" valign="top" width="33.333333333333336%" id="mcps1.1.4.1.2"><p id="p38431558175217"><a name="p38431558175217"></a><a name="p38431558175217"></a>Type</p> | y1 | number | Y-coordinate of the first point on the arc. |
</th> | x2 | number | X-coordinate of the second point on the arc. |
<th class="cellrowborder" valign="top" width="33.333333333333336%" id="mcps1.1.4.1.3"><p id="p8843195812520"><a name="p8843195812520"></a><a name="p8843195812520"></a>Description</p> | y2 | number | Y-coordinate of the second point on the arc. |
</th> | radius | number | Radius of the arc. |
</tr>
</thead> **Example**
<tbody><tr id="row148431358115213"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p384345875215"><a name="p384345875215"></a><a name="p384345875215"></a>x1</p> ```html
</td> <!-- xxx.hml -->
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p984325805212"><a name="p984325805212"></a><a name="p984325805212"></a>number</p> <div>
</td> <canvas ref="canvas" style="width: 200px; height: 150px; background-color: #ffff00;"></canvas>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p178438582527"><a name="p178438582527"></a><a name="p178438582527"></a>X-coordinate of the first point on the arc</p> </div>
</td> ```
</tr>
<tr id="row1984385813525"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p16843958185217"><a name="p16843958185217"></a><a name="p16843958185217"></a>y1</p> ```js
</td> // xxx.js
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p168431058165216"><a name="p168431058165216"></a><a name="p168431058165216"></a>number</p> export default {
</td> onShow() {
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p12843205813522"><a name="p12843205813522"></a><a name="p12843205813522"></a>Y-coordinate of the first point on the arc</p> const el =this.$refs.canvas;
</td> const ctx = el.getContext('2d');
</tr> var path = ctx.createPath2D();
<tr id="row88431558115211"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p88431058105211"><a name="p88431058105211"></a><a name="p88431058105211"></a>x2</p> path.arcTo(150, 20, 150, 70, 50);
</td> ctx.stroke(path);
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p1984315875217"><a name="p1984315875217"></a><a name="p1984315875217"></a>number</p> }
</td> }
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p158431558185211"><a name="p158431558185211"></a><a name="p158431558185211"></a>X-coordinate of the second point on the arc</p> ```
</td>
</tr> ![en-us_image_0000001127125204](figures/en-us_image_0000001127125204.png)
<tr id="row198431858125217"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p1484420584525"><a name="p1484420584525"></a><a name="p1484420584525"></a>y2</p>
</td>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p084495885213"><a name="p084495885213"></a><a name="p084495885213"></a>number</p> ## ellipse
</td>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p1684418583522"><a name="p1684418583522"></a><a name="p1684418583522"></a>Y-coordinate of the second point on the arc</p> ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, anticlockwise: number): void
</td>
</tr>
<tr id="row11844358155211"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p8844155865219"><a name="p8844155865219"></a><a name="p8844155865219"></a>radius</p>
</td>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p1984410581525"><a name="p1984410581525"></a><a name="p1984410581525"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p17844155815220"><a name="p17844155815220"></a><a name="p17844155815220"></a>Radius of the arc</p>
</td>
</tr>
</tbody>
</table>
- Example
```
<!-- xxx.hml -->
<div>
<canvas ref="canvas" style="width: 200px; height: 150px; background-color: #ffff00;"></canvas>
</div>
```
```
//xxx.js
export default {
onShow() {
const el =this.$refs.canvas;
const ctx = el.getContext('2d');
var path = ctx.createPath2D();
path.arcTo(150, 20, 150, 70, 50);
ctx.stroke(path);
}
}
```
![](figures/en-us_image_0000001127125204.png)
## ellipse<a name="section8146160205420"></a>
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. Draws an ellipse in the specified rectangular region.
- Parameters **Parameters**
<a name="table51461805541"></a> | Parameter | Type | Description |
<table><thead align="left"><tr id="row181461109541"><th class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.1.4.1.1"><p id="p014716035415"><a name="p014716035415"></a><a name="p014716035415"></a>Parameter</p> | ------------- | ------ | ------------------------------------------------------------ |
</th> | x | number | X-coordinate of the ellipse center. |
<th class="cellrowborder" valign="top" width="31.34343434343434%" id="mcps1.1.4.1.2"><p id="p171472055413"><a name="p171472055413"></a><a name="p171472055413"></a>Type</p> | y | number | Y-coordinate of the ellipse center. |
</th> | radiusX | number | Ellipse radius on the x-axis. |
<th class="cellrowborder" valign="top" width="35.323232323232325%" id="mcps1.1.4.1.3"><p id="p1814718035418"><a name="p1814718035418"></a><a name="p1814718035418"></a>Description</p> | radiusY | number | Ellipse radius on the y-axis. |
</th> | rotation | number | Rotation angle of the ellipse. The unit is radian. |
</tr> | startAngle | number | Angle of the start point for drawing the ellipse. The unit is radian. |
</thead> | endAngle | number | Angle of the end point for drawing the ellipse. The angle is represented by radians. |
<tbody><tr id="row1114714015418"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p81478015543"><a name="p81478015543"></a><a name="p81478015543"></a>x</p> | anticlockwise | number | Whether to draw the ellipse in the anticlockwise direction. The value **0** indicates clockwise and the value **1** indicates anticlockwise. This parameter is optional. The default value is **0**. |
</td>
<td class="cellrowborder" valign="top" width="31.34343434343434%" headers="mcps1.1.4.1.2 "><p id="p71470013548"><a name="p71470013548"></a><a name="p71470013548"></a>number</p> **Example**
</td> ```html
<td class="cellrowborder" valign="top" width="35.323232323232325%" headers="mcps1.1.4.1.3 "><p id="p714720125410"><a name="p714720125410"></a><a name="p714720125410"></a>X-coordinate of the ellipse center</p> <!-- xxx.hml -->
</td> <div>
</tr> <canvas ref="canvas" style="width: 500px; height: 450px; background-color: #ffff00;"></canvas>
<tr id="row1114710018548"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p1214718010544"><a name="p1214718010544"></a><a name="p1214718010544"></a>y</p> </div>
</td> ```
<td class="cellrowborder" valign="top" width="31.34343434343434%" headers="mcps1.1.4.1.2 "><p id="p314760175411"><a name="p314760175411"></a><a name="p314760175411"></a>number</p>
</td> ```js
<td class="cellrowborder" valign="top" width="35.323232323232325%" headers="mcps1.1.4.1.3 "><p id="p014730105419"><a name="p014730105419"></a><a name="p014730105419"></a>Y-coordinate of the ellipse center</p> // xxx.js
</td> export default {
</tr> onShow() {
<tr id="row2147709540"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p201478045416"><a name="p201478045416"></a><a name="p201478045416"></a>radiusX</p> const el =this.$refs.canvas;
</td> const ctx =el.getContext('2d');
<td class="cellrowborder" valign="top" width="31.34343434343434%" headers="mcps1.1.4.1.2 "><p id="p14147205540"><a name="p14147205540"></a><a name="p14147205540"></a>number</p> var path = ctx.createPath2D();
</td> path.ellipse(200, 200, 50, 100, Math.PI * 0.25, Math.PI * 0.5, Math.PI, 1);
<td class="cellrowborder" valign="top" width="35.323232323232325%" headers="mcps1.1.4.1.3 "><p id="p151475013547"><a name="p151475013547"></a><a name="p151475013547"></a>Ellipse radius on the x-axis.</p> ctx.stroke(path);
</td> }
</tr> }
<tr id="row61474012544"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p51477018543"><a name="p51477018543"></a><a name="p51477018543"></a>radiusY</p> ```
</td>
<td class="cellrowborder" valign="top" width="31.34343434343434%" headers="mcps1.1.4.1.2 "><p id="p14148150205416"><a name="p14148150205416"></a><a name="p14148150205416"></a>number</p> ![en-us_image_0000001173324787](figures/en-us_image_0000001173324787.png)
</td>
<td class="cellrowborder" valign="top" width="35.323232323232325%" headers="mcps1.1.4.1.3 "><p id="p181481705544"><a name="p181481705544"></a><a name="p181481705544"></a>Ellipse radius on the y-axis.</p>
</td> ## rect
</tr>
<tr id="row201484005417"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p161483075416"><a name="p161483075416"></a><a name="p161483075416"></a>rotation</p> rect(x: number, y: number, width: number, height: number): void
</td>
<td class="cellrowborder" valign="top" width="31.34343434343434%" headers="mcps1.1.4.1.2 "><p id="p1148502548"><a name="p1148502548"></a><a name="p1148502548"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="35.323232323232325%" headers="mcps1.1.4.1.3 "><p id="p514820005414"><a name="p514820005414"></a><a name="p514820005414"></a>Rotation angle of the ellipse. The unit is radian.</p>
</td>
</tr>
<tr id="row181481704549"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p1814850165416"><a name="p1814850165416"></a><a name="p1814850165416"></a>startAngle</p>
</td>
<td class="cellrowborder" valign="top" width="31.34343434343434%" headers="mcps1.1.4.1.2 "><p id="p1914815025414"><a name="p1914815025414"></a><a name="p1914815025414"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="35.323232323232325%" headers="mcps1.1.4.1.3 "><p id="p51481906547"><a name="p51481906547"></a><a name="p51481906547"></a>Angle of the start point for drawing the ellipse. The unit is radian.</p>
</td>
</tr>
<tr id="row1148150125412"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p131483019542"><a name="p131483019542"></a><a name="p131483019542"></a>endAngle</p>
</td>
<td class="cellrowborder" valign="top" width="31.34343434343434%" headers="mcps1.1.4.1.2 "><p id="p14148190155418"><a name="p14148190155418"></a><a name="p14148190155418"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="35.323232323232325%" headers="mcps1.1.4.1.3 "><p id="p1114812095411"><a name="p1114812095411"></a><a name="p1114812095411"></a>Angle of the end point for drawing the ellipse. The angle is represented by radians.</p>
</td>
</tr>
<tr id="row4148206542"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p1114817035417"><a name="p1114817035417"></a><a name="p1114817035417"></a>anticlockwise</p>
</td>
<td class="cellrowborder" valign="top" width="31.34343434343434%" headers="mcps1.1.4.1.2 "><p id="p3148130105411"><a name="p3148130105411"></a><a name="p3148130105411"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="35.323232323232325%" headers="mcps1.1.4.1.3 "><p id="p914910015410"><a name="p914910015410"></a><a name="p914910015410"></a>Whether to draw the ellipse in the anticlockwise direction. The value <strong id="b148606837841113"><a name="b148606837841113"></a><a name="b148606837841113"></a>0</strong> indicates clockwise and the value <strong id="b64668246441113"><a name="b64668246441113"></a><a name="b64668246441113"></a>1</strong> indicates anticlockwise. This parameter is optional. The default value is <strong id="b137444197741113"><a name="b137444197741113"></a><a name="b137444197741113"></a>0</strong>.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
<!-- xxx.hml -->
<div>
<canvas ref="canvas" style="width: 500px; height: 450px; background-color: #ffff00;"></canvas>
</div>
```
```
//xxx.js
export default {
onShow() {
const el =this.$refs.canvas;
const ctx =el.getContext('2d');
var path = ctx.createPath2D();
path.ellipse(200, 200, 50, 100, Math.PI * 0.25, Math.PI * 0.5, Math.PI, 1);
ctx.stroke(path);
}
}
```
![](figures/en-us_image_0000001173324787.png)
## rect<a name="section18565225124518"></a>
rect\(x: number, y: number, width: number, height: number\): void
Creates a rectangle. Creates a rectangle.
- Parameters **Parameters**
<a name="table92131548185610"></a> | Parameter | Type | Description |
<table><thead align="left"><tr id="row9238348185613"><th class="cellrowborder" valign="top" width="33.333333333333336%" id="mcps1.1.4.1.1"><p id="p723854810561"><a name="p723854810561"></a><a name="p723854810561"></a>Parameter</p> | --------- | ------ | ------------------------------------------------------- |
</th> | x | number | X-coordinate of the upper left corner of the rectangle. |
<th class="cellrowborder" valign="top" width="33.333333333333336%" id="mcps1.1.4.1.2"><p id="p2238144885615"><a name="p2238144885615"></a><a name="p2238144885615"></a>Type</p> | y | number | Y-coordinate of the upper left corner of the rectangle. |
</th> | width | number | Width of the rectangle. |
<th class="cellrowborder" valign="top" width="33.333333333333336%" id="mcps1.1.4.1.3"><p id="p223814486561"><a name="p223814486561"></a><a name="p223814486561"></a>Description</p> | height | number | Height of the rectangle. |
</th>
</tr> **Example**
</thead> ```html
<tbody><tr id="row5238104813569"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p1423864816566"><a name="p1423864816566"></a><a name="p1423864816566"></a>x</p> <!-- xxx.hml -->
</td> <div>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p3238194814560"><a name="p3238194814560"></a><a name="p3238194814560"></a>number</p> <canvas ref="canvas" style="width: 500px; height: 450px; background-color: #ffff00;"></canvas>
</td> </div>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p9238204818566"><a name="p9238204818566"></a><a name="p9238204818566"></a>X-coordinate of the upper left corner of the rectangle.</p> ```
</td>
</tr> ```js
<tr id="row1423884816562"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p132383488563"><a name="p132383488563"></a><a name="p132383488563"></a>y</p> // xxx.js
</td> export default {
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p02395487560"><a name="p02395487560"></a><a name="p02395487560"></a>number</p> onShow() {
</td> const el =this.$refs.canvas;
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p523934819568"><a name="p523934819568"></a><a name="p523934819568"></a>Y-coordinate of the upper left corner of the rectangle.</p> const ctx = el.getContext('2d');
</td> var path = ctx.createPath2D();
</tr> path.rect(20, 20, 100, 100);
<tr id="row723954815563"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p182391481565"><a name="p182391481565"></a><a name="p182391481565"></a>width</p> ctx.stroke(path);
</td> }
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p142391648145610"><a name="p142391648145610"></a><a name="p142391648145610"></a>number</p> }
</td> ```
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p523919486569"><a name="p523919486569"></a><a name="p523919486569"></a>Width of the rectangle.</p>
</td> ![en-us_image_0000001127125212](figures/en-us_image_0000001127125212.png)
</tr>
<tr id="row1723924885618"><td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.1 "><p id="p1923934820561"><a name="p1923934820561"></a><a name="p1923934820561"></a>height</p>
</td>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.2 "><p id="p13239448135615"><a name="p13239448135615"></a><a name="p13239448135615"></a>number</p>
</td>
<td class="cellrowborder" valign="top" width="33.333333333333336%" headers="mcps1.1.4.1.3 "><p id="p523924819568"><a name="p523924819568"></a><a name="p523924819568"></a>Height of the rectangle.</p>
</td>
</tr>
</tbody>
</table>
- Example
```
<!-- xxx.hml -->
<div>
<canvas ref="canvas" style="width: 500px; height: 450px; background-color: #ffff00;"></canvas>
</div>
```
```
//xxx.js
export default {
onShow() {
const el =this.$refs.canvas;
const ctx = el.getContext('2d');
var path = ctx.createPath2D();
path.rect(20, 20, 100, 100);
ctx.stroke(path);
}
}
```
![](figures/en-us_image_0000001127125212.png)
...@@ -35,33 +35,35 @@ Obtains an image from the specified source for subsequent rendering and display. ...@@ -35,33 +35,35 @@ Obtains an image from the specified source for subsequent rendering and display.
**Parameters** **Parameters**
| Name| Type | Mandatory| Default Value| Description | | Name | Type | Mandatory | Default Value | Description |
| ------ | ------------------------------------------------------------ | ---- | ------ | ------------------------------------------------------------ | | ---- | ---------------------------------------- | ---- | ---- | ---------------------------------------- |
| src | string \| [PixelMap](../apis/js-apis-image.md#pixelmap7) \| [Resource](../../ui/ts-types.md) | Yes | - | Image source. Both local and online images are supported.<br>When using resources referenced using a relative path, for example, `Image("common/test.jpg")`, the **\<Image>** component cannot be called across bundles or modules. Therefore, you are advised to use `$r` to reference image resources that need to be used globally.<br>\- The following image formats are supported: PNG, JPG, BMP, SVG, GIF.<br>\- Base64 strings are supported. The value format is `data:image/[png\|jpeg\|bmp\|webp];base64,[base64 data]`, where `[base64 data]` is a Base64 string.<br/>\- The value can also be a path starting with `dataability://`, which is used to access the image path provided by a Data ability. | | src | string \| [PixelMap](../apis/js-apis-image.md#pixelmap7) \| [Resource](../../ui/ts-types.md#resource-type) | Yes | - | Image source. Both local and online images are supported.<br>When using resources referenced using a relative path, for example, `Image("common/test.jpg")`, the **\<Image>** component cannot be called across bundles or modules. Therefore, you are advised to use `$r` to reference image resources that need to be used globally.<br>- The following image formats are supported: PNG, JPG, BMP, SVG, GIF.<br>\- Base64 strings are supported. \ The value format is `data:image/[png\|jpeg\|bmp\|webp];base64,[base64 data]`, where `[base64 data]` is a Base64 string.<br/>\- The value can also be a path starting with `dataability://`, which is used to access the image path provided by a Data ability.|
## Attributes ## Attributes
In addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported. In addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported.
| Name | Type | Default Value | Description | | Name | Type | Default Value | Description |
| --------------------- | ---------------------------------------- | ------------------------ | ---------------------------------------- | | --------------------- | ------------------------------------------------------- | ------------------------ | ------------------------------------------------------------ |
| alt | string \| [Resource](../../ui/ts-types.md) | - | Placeholder image displayed during loading. Both local and Internet URIs are supported. | | alt | string \| [Resource](../../ui/ts-types.md#resource-type) | - | Placeholder image displayed during loading. Both local and Internet URIs are supported. |
| objectFit | [ImageFit](#imagefit-enums) | ImageFit.Cover | Image scale type. | | objectFit | ImageFit | ImageFit.Cover | Image scale type. |
| objectRepeat | [ImageRepeat](ts-appendix-enums.md#imagerepeat) | NoRepeat | Whether the image is repeated.<br>**NOTE**<br>This attribute is not applicable to SVG images. | | objectRepeat | [ImageRepeat](ts-appendix-enums.md#imagerepeat) | NoRepeat | Whether the image is repeated.<br>**NOTE**<br>This attribute is not applicable to SVG images. |
| interpolation | [ImageInterpolation](#imageinterpolation) | ImageInterpolation.None | Interpolation effect of the image. This attribute is valid only when the image is zoomed in.<br>**NOTE**<br>This attribute is not applicable to SVG images or **PixelMap** objects. | | interpolation | [ImageInterpolation](#imageinterpolation) | ImageInterpolation.None | Interpolation effect of the image. This attribute is intended to alleviate aliasing that occurs when a low-definition image is zoomed in.<br>**NOTE**<br>> This attribute is not applicable to SVG images.<br>> This attribute is not applicable to **PixelMap** objects. |
| renderMode | [ImageRenderMode](#imagerendermode) | ImageRenderMode.Original | Rendering mode of the image.<br>**NOTE**<br>This attribute is not applicable to SVG images. | | renderMode | [ImageRenderMode](#imagerendermode) | ImageRenderMode.Original | Rendering mode of the image.<br>**NOTE**<br>This attribute is not applicable to SVG images. |
| sourceSize | {<br>width: number,<br>height: number<br>} | - | Decoding size of the image. The original image is decoded into an image of the specified size, in px.<br>**NOTE**<br>This attribute is not applicable to **PixelMap** objects. | | sourceSize | {<br>width: number,<br>height: number<br>} | - | Decoding size of the image. The original image is decoded into an image of the specified size, in px.<br>**NOTE**<br>This attribute is not applicable to **PixelMap** objects. |
| syncLoad<sup>8+</sup> | boolean | false | Whether to load images synchronously. By default, images are loaded asynchronously. During synchronous loading, the UI thread is blocked and the placeholder diagram is not displayed. | | syncLoad<sup>8+</sup> | boolean | false | Whether to load images synchronously. By default, images are loaded asynchronously. During synchronous loading, the UI thread is blocked and the placeholder diagram is not displayed. |
| copyOption<sup>9+</sup> | [CopyOptions](#copyoptions) | CopyOptions.None | Whether the image can be copied. (SVG images cannot be copied.)|
| colorFilter<sup>9+</sup> | [ColorFilter](../../ui/ts-types.md) | - | Color filter of the image. |
### ImageFit ### ImageFit
| Name | Description | | Name | Description |
| --------- | -------------------------------- | | --------- | ------------------------------------------------------------ |
| Cover | The image is scaled with its aspect ratio retained for both sides to be greater than or equal to the display boundaries. | | Cover | The image is scaled with its aspect ratio retained for both sides to be greater than or equal to the display boundaries.|
| Contain | The image is scaled with its aspect ratio retained for the content to be completely displayed within the display boundaries. | | Contain | The image is scaled with its aspect ratio retained for the content to be completely displayed within the display boundaries. |
| Fill | The image is scaled to fill the display area, and its aspect ratio is not retained. | | Fill | The image is scaled to fill the display area, and its aspect ratio is not retained. |
| None | The image is displayed in its original size. Generally, this enum is used together with the **objectRepeat** attribute.| | None | The image is displayed in its original size. |
| ScaleDown | The image is displayed with its aspect ratio retained, in a size smaller than or equal to the original size. | | ScaleDown | The image is displayed with its aspect ratio retained, in a size smaller than or equal to the original size. |
### ImageInterpolation ### ImageInterpolation
...@@ -79,15 +81,24 @@ In addition to the [universal attributes](ts-universal-attributes-size.md), the ...@@ -79,15 +81,24 @@ In addition to the [universal attributes](ts-universal-attributes-size.md), the
| Original | The image is rendered based on the original image, including the color. | | Original | The image is rendered based on the original image, including the color. |
| Template | The image is rendered as a template image, and its color is ignored.| | Template | The image is rendered as a template image, and its color is ignored.|
### CopyOptions<sup>9+</sup>
| Name| Description|
| -------- | -------- |
| None | Copy and paste is not allowed.|
| InApp | Intra-application copy and paste is allowed.|
| LocalDevice | Intra-device copy and paste is allowed.|
| CrossDevice | Cross-device copy and paste is allowed.|
## Events ## Events
In addition to the universal events (ts-universal-events-click.md), the following events are supported. In addition to the universal events (ts-universal-events-click.md), the following events are supported.
| Name | Description | | Name | Description |
| ---------------------------------------- | ---------------------------------------- | | ------------------------------------------------------------ | ------------------------------------------------------------ |
| onComplete(callback: (event?: { width: number, height: number, componentWidth: number,<br> componentHeight: number, loadingStatus: number }) =&gt; void) | Triggered when an image is successfully loaded. The size of the loaded image is returned.<br>- **width**: width of the image, in pixels.<br>- **height**: height of the image, in pixels.<br>- **componentWidth**: width of the container component, in pixels.<br>- **componentHeight**: height of the container component, in pixels.<br>- **loadingStatus**: image loading status.<br>| | onComplete(callback: (event?: { width: number, height: number, componentWidth: number,<br> componentHeight: number, loadingStatus: number }) =&gt; void) | Triggered when an image is successfully loaded. The size of the loaded image is returned.<br>- **width**: width of the image, in pixels.<br>- **height**: height of the image, in pixels.<br>- **componentWidth**: width of the container component, in pixels.<br>- **componentHeight**: height of the container component, in pixels.<br>- **loadingStatus**: image loading status.<br> |
| onError(callback: (event?: { componentWidth: number, componentHeight: number }) =&gt; void) | Triggered when an exception occurs during image loading.<br>- **componentWidth**: width of the container component, in pixels.<br>- **componentHeight**: height of the container component, in pixels.<br>| | onError(callback: (event?: { componentWidth: number, componentHeight: number }) =&gt; void) | Triggered when an exception occurs during image loading.<br>- **componentWidth**: width of the container component, in pixels.<br>- **componentHeight**: height of the container component, in pixels. |
| onFinish(callback: () =&gt; void) | Triggered when the animation playback in the loaded SVG image is complete. If the animation is an infinite loop, this callback is not triggered.| | onFinish(callback: () =&gt; void) | Triggered when the animation playback in the loaded SVG image is complete. If the animation is an infinite loop, this callback is not triggered. |
## Example ## Example
...@@ -235,8 +246,8 @@ struct ImageExample2 { ...@@ -235,8 +246,8 @@ struct ImageExample2 {
@Entry @Entry
@Component @Component
struct ImageExample3 { struct ImageExample3 {
@State width: number = 0 @State widthValue: number = 0
@State height: number = 0 @State heightValue: number = 0
private on: Resource = $r('app.media.image_on') private on: Resource = $r('app.media.image_on')
private off: Resource = $r('app.media.image_off') private off: Resource = $r('app.media.image_off')
private on2off: Resource = $r('app.media.image_on2off') private on2off: Resource = $r('app.media.image_on2off')
...@@ -257,8 +268,8 @@ struct ImageExample3 { ...@@ -257,8 +268,8 @@ struct ImageExample3 {
.height(180).width(180) .height(180).width(180)
// Obtain the size of an image after the image loading is complete. // Obtain the size of an image after the image loading is complete.
.onComplete((msg: { width: number,height: number }) => { .onComplete((msg: { width: number,height: number }) => {
this.width = msg.width this.widthValue = msg.width
this.height = msg.height this.heightValue = msg.height
}) })
.onError(() => { .onError(() => {
console.log('load image fail') console.log('load image fail')
......
...@@ -31,6 +31,7 @@ Implements a target window, which is used to remotely control the animation. ...@@ -31,6 +31,7 @@ Implements a target window, which is used to remotely control the animation.
| bundleName | string | Process corresponding to the animation window.| | bundleName | string | Process corresponding to the animation window.|
| abilityName | string | Ability corresponding to the animation window.| | abilityName | string | Ability corresponding to the animation window.|
| windowBounds | [RRect](#rrect) | Actual size of the animation window.| | windowBounds | [RRect](#rrect) | Actual size of the animation window.|
| missionId | number | Mission ID. |
## RRect ## RRect
Implements a rounded rectangle. Implements a rounded rectangle.
......
# PinchGesture # PinchGesture
PinchGesture is used to trigger a pinch gesture, which requires two to five fingers with a minimum 3 vp distance between the fingers.
> **NOTE**<br> > **NOTE**
>
> This gesture is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. > This gesture is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
...@@ -41,25 +43,26 @@ PinchGesture(options?: { fingers?: number, distance?: number }) ...@@ -41,25 +43,26 @@ PinchGesture(options?: { fingers?: number, distance?: number })
## Example ## Example
``` ```ts
// xxx.ets
@Entry @Entry
@Component @Component
struct PinchGestureExample { struct PinchGestureExample {
@State scale: number = 1 @State scaleValue: number = 1
build() { build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Text('PinchGesture scale:' + this.scale) Text('PinchGesture scale:' + this.scale)
} }
.height(100).width(200).padding(20).border({ width: 1 }).margin(80) .height(100).width(200).padding(20).border({ width: 1 }).margin(80)
.scale({ x: this.scale, y: this.scale, z: this.scale }) .scale({ x: this.scaleValue, y: this.scaleValue, z: this.scaleValue })
.gesture( .gesture(
PinchGesture() PinchGesture()
.onActionStart((event: GestureEvent) => { .onActionStart((event: GestureEvent) => {
console.info('Pinch start') console.info('Pinch start')
}) })
.onActionUpdate((event: GestureEvent) => { .onActionUpdate((event: GestureEvent) => {
this.scale = event.scale this.scaleValue = event.scale
}) })
.onActionEnd(() => { .onActionEnd(() => {
console.info('Pinch end') console.info('Pinch end')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册