Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
a64c6ca8
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a64c6ca8
编写于
3月 17, 2023
作者:
L
lanyill
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Canvas 文档格式整改
Signed-off-by:
N
lanyill
<
lanyi3@huawei.com
>
上级
150dcb48
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
322 addition
and
301 deletion
+322
-301
zh-cn/application-dev/reference/arkui-ts/ts-canvasrenderingcontext2d.md
...ion-dev/reference/arkui-ts/ts-canvasrenderingcontext2d.md
+97
-97
zh-cn/application-dev/reference/arkui-ts/ts-components-canvas-canvasgradient.md
...reference/arkui-ts/ts-components-canvas-canvasgradient.md
+1
-1
zh-cn/application-dev/reference/arkui-ts/ts-components-canvas-imagedata.md
...-dev/reference/arkui-ts/ts-components-canvas-imagedata.md
+21
-21
zh-cn/application-dev/reference/arkui-ts/ts-components-canvas-path2d.md
...ion-dev/reference/arkui-ts/ts-components-canvas-path2d.md
+1
-1
zh-cn/application-dev/reference/arkui-ts/ts-offscreencanvasrenderingcontext2d.md
...eference/arkui-ts/ts-offscreencanvasrenderingcontext2d.md
+202
-181
未找到文件。
zh-cn/application-dev/reference/arkui-ts/ts-canvasrenderingcontext2d.md
浏览文件 @
a64c6ca8
...
...
@@ -77,7 +77,7 @@ struct FillStyleExample {
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
this
.
context
.
fillStyle
=
'
#0000ff
'
this
.
context
.
fillRect
(
20
,
16
0
,
150
,
100
)
this
.
context
.
fillRect
(
20
,
2
0
,
150
,
100
)
})
}
.
width
(
'
100%
'
)
...
...
@@ -1653,35 +1653,35 @@ clip(path: Path2D, fillRule?: CanvasFillRule): void
```
ts
// xxx.ets
@
Entry
@
Component
struct
Clip
{
private
settings
:
RenderingContextSettings
=
new
RenderingContextSettings
(
true
)
private
context
:
CanvasRenderingContext2D
=
new
CanvasRenderingContext2D
(
this
.
settings
)
build
()
{
Flex
({
direction
:
FlexDirection
.
Column
,
alignItems
:
ItemAlign
.
Center
,
justifyContent
:
FlexAlign
.
Center
})
{
Canvas
(
this
.
context
)
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
let
region
=
new
Path2D
()
region
.
moveTo
(
30
,
90
)
region
.
lineTo
(
110
,
20
)
region
.
lineTo
(
240
,
130
)
region
.
lineTo
(
60
,
130
)
region
.
lineTo
(
190
,
20
)
region
.
lineTo
(
270
,
90
)
region
.
closePath
()
this
.
context
.
clip
(
region
,
"
evenodd
"
)
this
.
context
.
fillStyle
=
"
rgb(0,255,0)
"
this
.
context
.
fillRect
(
0
,
0
,
this
.
context
.
width
,
this
.
context
.
height
)
})
@
Entry
@
Component
struct
Clip
{
private
settings
:
RenderingContextSettings
=
new
RenderingContextSettings
(
true
)
private
context
:
CanvasRenderingContext2D
=
new
CanvasRenderingContext2D
(
this
.
settings
)
build
()
{
Flex
({
direction
:
FlexDirection
.
Column
,
alignItems
:
ItemAlign
.
Center
,
justifyContent
:
FlexAlign
.
Center
})
{
Canvas
(
this
.
context
)
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
let
region
=
new
Path2D
()
region
.
moveTo
(
30
,
90
)
region
.
lineTo
(
110
,
20
)
region
.
lineTo
(
240
,
130
)
region
.
lineTo
(
60
,
130
)
region
.
lineTo
(
190
,
20
)
region
.
lineTo
(
270
,
90
)
region
.
closePath
()
this
.
context
.
clip
(
region
,
"
evenodd
"
)
this
.
context
.
fillStyle
=
"
rgb(0,255,0)
"
this
.
context
.
fillRect
(
0
,
0
,
this
.
context
.
width
,
this
.
context
.
height
)
})
}
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
}
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
}
}
```
!
[
zh-cn_image_000000127777779
](
figures/zh-cn_image_000000127777779.png
)
...
...
@@ -2104,29 +2104,29 @@ getImageData(sx: number, sy: number, sw: number, sh: number): ImageData
```
ts
// xxx.ets
@
Entry
@
Component
struct
GetImageData
{
private
settings
:
RenderingContextSettings
=
new
RenderingContextSettings
(
true
)
private
context
:
CanvasRenderingContext2D
=
new
CanvasRenderingContext2D
(
this
.
settings
)
private
img
:
ImageBitmap
=
new
ImageBitmap
(
"
/common/images/1234.png
"
)
@
Entry
@
Component
struct
GetImageData
{
private
settings
:
RenderingContextSettings
=
new
RenderingContextSettings
(
true
)
private
context
:
CanvasRenderingContext2D
=
new
CanvasRenderingContext2D
(
this
.
settings
)
private
img
:
ImageBitmap
=
new
ImageBitmap
(
"
/common/images/1234.png
"
)
build
()
{
Flex
({
direction
:
FlexDirection
.
Column
,
alignItems
:
ItemAlign
.
Center
,
justifyContent
:
FlexAlign
.
Center
})
{
Canvas
(
this
.
context
)
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
this
.
context
.
drawImage
(
this
.
img
,
0
,
0
,
130
,
130
)
var
imagedata
=
this
.
context
.
getImageData
(
50
,
50
,
130
,
130
)
this
.
context
.
putImageData
(
imagedata
,
150
,
150
)
})
build
()
{
Flex
({
direction
:
FlexDirection
.
Column
,
alignItems
:
ItemAlign
.
Center
,
justifyContent
:
FlexAlign
.
Center
})
{
Canvas
(
this
.
context
)
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
this
.
context
.
drawImage
(
this
.
img
,
0
,
0
,
130
,
130
)
var
imagedata
=
this
.
context
.
getImageData
(
50
,
50
,
130
,
130
)
this
.
context
.
putImageData
(
imagedata
,
150
,
150
)
})
}
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
}
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
}
}
```
!
[
zh-cn_image_000000127777780
](
figures/zh-cn_image_000000127777780.png
)
...
...
@@ -2248,40 +2248,40 @@ getLineDash(): number[]
```
ts
// xxx.ets
@
Entry
@
Component
struct
CanvasGetLineDash
{
@
State
message
:
string
=
'
Hello World
'
private
settings
:
RenderingContextSettings
=
new
RenderingContextSettings
(
true
)
private
context
:
CanvasRenderingContext2D
=
new
CanvasRenderingContext2D
(
this
.
settings
)
@
Entry
@
Component
struct
CanvasGetLineDash
{
@
State
message
:
string
=
'
Hello World
'
private
settings
:
RenderingContextSettings
=
new
RenderingContextSettings
(
true
)
private
context
:
CanvasRenderingContext2D
=
new
CanvasRenderingContext2D
(
this
.
settings
)
build
()
{
Row
()
{
Column
()
{
Text
(
this
.
message
)
.
fontSize
(
50
)
.
fontWeight
(
FontWeight
.
Bold
)
.
onClick
(()
=>
{
console
.
error
(
'
before getlinedash clicked
'
)
let
res
=
this
.
context
.
getLineDash
()
console
.
error
(
JSON
.
stringify
(
res
))
})
Canvas
(
this
.
context
)
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
this
.
context
.
arc
(
100
,
75
,
50
,
0
,
6.28
)
this
.
context
.
setLineDash
([
10
,
20
])
this
.
context
.
stroke
()
let
res
=
this
.
context
.
getLineDash
()
})
build
()
{
Row
()
{
Column
()
{
Text
(
this
.
message
)
.
fontSize
(
50
)
.
fontWeight
(
FontWeight
.
Bold
)
.
onClick
(()
=>
{
console
.
error
(
'
before getlinedash clicked
'
)
let
res
=
this
.
context
.
getLineDash
()
console
.
error
(
JSON
.
stringify
(
res
))
})
Canvas
(
this
.
context
)
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
this
.
context
.
arc
(
100
,
75
,
50
,
0
,
6.28
)
this
.
context
.
setLineDash
([
10
,
20
])
this
.
context
.
stroke
()
let
res
=
this
.
context
.
getLineDash
()
})
}
.
width
(
'
100%
'
)
}
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
}
.
height
(
'
100%
'
)
}
}
```
![
zh-cn_image_000000127777778
](
figures/zh-cn_image_000000127777778.png
)
...
...
@@ -2376,26 +2376,26 @@ toDataURL(type?: string, quality?: number): string
```
ts
// xxx.ets
@
Entry
@
Component
struct
ToDataURL
{
private
settings
:
RenderingContextSettings
=
new
RenderingContextSettings
(
true
)
private
context
:
CanvasRenderingContext2D
=
new
CanvasRenderingContext2D
(
this
.
settings
)
@
Entry
@
Component
struct
ToDataURL
{
private
settings
:
RenderingContextSettings
=
new
RenderingContextSettings
(
true
)
private
context
:
CanvasRenderingContext2D
=
new
CanvasRenderingContext2D
(
this
.
settings
)
build
()
{
Flex
({
direction
:
FlexDirection
.
Column
,
alignItems
:
ItemAlign
.
Center
,
justifyContent
:
FlexAlign
.
Center
})
{
Canvas
(
this
.
context
)
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
var
dataURL
=
this
.
context
.
toDataURL
()
})
build
()
{
Flex
({
direction
:
FlexDirection
.
Column
,
alignItems
:
ItemAlign
.
Center
,
justifyContent
:
FlexAlign
.
Center
})
{
Canvas
(
this
.
context
)
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
var
dataURL
=
this
.
context
.
toDataURL
()
})
}
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
}
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
}
}
```
...
...
@@ -2512,7 +2512,7 @@ createLinearGradient(x0: number, y0: number, x1: number, y1: number): void
grad
.
addColorStop
(
0.5
,
'
#ffffff
'
)
grad
.
addColorStop
(
1.0
,
'
#00ff00
'
)
this
.
context
.
fillStyle
=
grad
this
.
context
.
fillRect
(
0
,
0
,
500
,
5
00
)
this
.
context
.
fillRect
(
0
,
0
,
400
,
4
00
)
})
}
.
width
(
'
100%
'
)
...
...
@@ -2563,7 +2563,7 @@ createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number,
grad
.
addColorStop
(
0.5
,
'
#ffffff
'
)
grad
.
addColorStop
(
1.0
,
'
#00ff00
'
)
this
.
context
.
fillStyle
=
grad
this
.
context
.
fillRect
(
0
,
0
,
500
,
50
0
)
this
.
context
.
fillRect
(
0
,
0
,
440
,
44
0
)
})
}
.
width
(
'
100%
'
)
...
...
zh-cn/application-dev/reference/arkui-ts/ts-components-canvas-canvasgradient.md
浏览文件 @
a64c6ca8
...
...
@@ -47,7 +47,7 @@ struct Page45 {
grad
.
addColorStop
(
0.5
,
'
#ffffff
'
)
grad
.
addColorStop
(
1.0
,
'
#00ff00
'
)
this
.
context
.
fillStyle
=
grad
this
.
context
.
fillRect
(
0
,
0
,
500
,
5
00
)
this
.
context
.
fillRect
(
0
,
0
,
400
,
4
00
)
})
}
.
width
(
'
100%
'
)
...
...
zh-cn/application-dev/reference/arkui-ts/ts-components-canvas-imagedata.md
浏览文件 @
a64c6ca8
...
...
@@ -24,29 +24,29 @@ ImageData对象可以存储canvas渲染的像素数据。
```
ts
// xxx.ets
@
Entry
@
Component
struct
Translate
{
private
settings
:
RenderingContextSettings
=
new
RenderingContextSettings
(
true
)
private
context
:
CanvasRenderingContext2D
=
new
CanvasRenderingContext2D
(
this
.
settings
)
private
img
:
ImageBitmap
=
new
ImageBitmap
(
"
/common/images/1234.png
"
)
build
()
{
Flex
({
direction
:
FlexDirection
.
Column
,
alignItems
:
ItemAlign
.
Center
,
justifyContent
:
FlexAlign
.
Center
})
{
Canvas
(
this
.
context
)
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
this
.
context
.
drawImage
(
this
.
img
,
0
,
0
,
130
,
130
)
var
imagedata
=
this
.
context
.
getImageData
(
50
,
50
,
130
,
130
)
this
.
context
.
putImageData
(
imagedata
,
150
,
150
)
})
@
Entry
@
Component
struct
Translate
{
private
settings
:
RenderingContextSettings
=
new
RenderingContextSettings
(
true
)
private
context
:
CanvasRenderingContext2D
=
new
CanvasRenderingContext2D
(
this
.
settings
)
private
img
:
ImageBitmap
=
new
ImageBitmap
(
"
common/images/1234.png
"
)
build
()
{
Flex
({
direction
:
FlexDirection
.
Column
,
alignItems
:
ItemAlign
.
Center
,
justifyContent
:
FlexAlign
.
Center
})
{
Canvas
(
this
.
context
)
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
this
.
context
.
drawImage
(
this
.
img
,
0
,
0
,
130
,
130
)
var
imagedata
=
this
.
context
.
getImageData
(
50
,
50
,
130
,
130
)
this
.
context
.
putImageData
(
imagedata
,
150
,
150
)
})
}
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
}
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
}
}
```
!
[
zh-cn_image_000000127777780
](
figures/zh-cn_image_000000127777780.png
)
...
...
zh-cn/application-dev/reference/arkui-ts/ts-components-canvas-path2d.md
浏览文件 @
a64c6ca8
# Path2D对象
路径对象,支持通过对象的接口进行路径的描述,并通过Canvas的stroke接口进行绘制。
路径对象,支持通过对象的接口进行路径的描述,并通过Canvas的stroke接口
或者fill接口
进行绘制。
> **说明:**
>
...
...
zh-cn/application-dev/reference/arkui-ts/ts-offscreencanvasrenderingcontext2d.md
浏览文件 @
a64c6ca8
...
...
@@ -66,7 +66,7 @@ struct FillStyleExample {
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
this
.
offContext
.
fillStyle
=
'
#0000ff
'
this
.
offContext
.
fillRect
(
20
,
16
0
,
150
,
100
)
this
.
offContext
.
fillRect
(
20
,
2
0
,
150
,
100
)
var
image
=
this
.
offContext
.
transferToImageBitmap
()
this
.
context
.
transferFromImageBitmap
(
image
)
})
...
...
@@ -1752,39 +1752,39 @@ clip(path:Path2D, fillRule?: CanvasFillRule): void
```
ts
// xxx.ets
@
Entry
@
Component
struct
Clip
{
private
settings
:
RenderingContextSettings
=
new
RenderingContextSettings
(
true
)
private
context
:
CanvasRenderingContext2D
=
new
CanvasRenderingContext2D
(
this
.
settings
)
private
offContext
:
OffscreenCanvasRenderingContext2D
=
new
OffscreenCanvasRenderingContext2D
(
600
,
600
,
this
.
settings
)
@
Entry
@
Component
struct
Clip
{
private
settings
:
RenderingContextSettings
=
new
RenderingContextSettings
(
true
)
private
context
:
CanvasRenderingContext2D
=
new
CanvasRenderingContext2D
(
this
.
settings
)
private
offContext
:
OffscreenCanvasRenderingContext2D
=
new
OffscreenCanvasRenderingContext2D
(
600
,
600
,
this
.
settings
)
build
()
{
Flex
({
direction
:
FlexDirection
.
Column
,
alignItems
:
ItemAlign
.
Center
,
justifyContent
:
FlexAlign
.
Center
})
{
Canvas
(
this
.
context
)
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
let
region
=
new
Path2D
()
region
.
moveTo
(
30
,
90
)
region
.
lineTo
(
110
,
20
)
region
.
lineTo
(
240
,
130
)
region
.
lineTo
(
60
,
130
)
region
.
lineTo
(
190
,
20
)
region
.
lineTo
(
270
,
90
)
region
.
closePath
()
this
.
offContext
.
clip
(
region
,
"
evenodd
"
)
this
.
offContext
.
fillStyle
=
"
rgb(0,255,0)
"
this
.
offContext
.
fillRect
(
0
,
0
,
600
,
600
)
var
image
=
this
.
offContext
.
transferToImageBitmap
()
this
.
context
.
transferFromImageBitmap
(
image
)
})
build
()
{
Flex
({
direction
:
FlexDirection
.
Column
,
alignItems
:
ItemAlign
.
Center
,
justifyContent
:
FlexAlign
.
Center
})
{
Canvas
(
this
.
context
)
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
let
region
=
new
Path2D
()
region
.
moveTo
(
30
,
90
)
region
.
lineTo
(
110
,
20
)
region
.
lineTo
(
240
,
130
)
region
.
lineTo
(
60
,
130
)
region
.
lineTo
(
190
,
20
)
region
.
lineTo
(
270
,
90
)
region
.
closePath
()
this
.
offContext
.
clip
(
region
,
"
evenodd
"
)
this
.
offContext
.
fillStyle
=
"
rgb(0,255,0)
"
this
.
offContext
.
fillRect
(
0
,
0
,
600
,
600
)
var
image
=
this
.
offContext
.
transferToImageBitmap
()
this
.
context
.
transferFromImageBitmap
(
image
)
})
}
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
}
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
}
}
```
!
[
zh-cn_image_000000127777779
](
figures/zh-cn_image_000000127777779.png
)
...
...
@@ -2189,6 +2189,27 @@ getPixelMap(sx: number, sy: number, sw: number, sh: number): PixelMap
| ---------------------------------------- | ------------ |
|
[
PixelMap
](
../apis/js-apis-image.md#pixelmap7
)
| 新的PixelMap对象 |
### setPixelMap
setPixelMap(value?: PixelMap): void
将当前传入
[
PixelMap
](
../apis/js-apis-image.md#pixelmap7
)
对象绘制在画布上。
**参数:**
| 参数 | 类型 | 必填 | 默认值 | 描述 |
| ---- | ------ | ---- | ---- | --------------- |
| sx | number | 是 | 0 | 需要输出的区域的左上角x坐标。 |
| sy | number | 是 | 0 | 需要输出的区域的左上角y坐标。 |
| sw | number | 是 | 0 | 需要输出的区域的宽度。 |
| sh | number | 是 | 0 | 需要输出的区域的高度。 |
**返回值:**
| 类型 | 说明 |
| ---------------------------------------- | ------------ |
|
[
PixelMap
](
../apis/js-apis-image.md#pixelmap7
)
| 新的PixelMap对象 |
### getImageData
...
...
@@ -2216,32 +2237,32 @@ getImageData(sx: number, sy: number, sw: number, sh: number): ImageData
```
ts
// xxx.ets
@
Entry
@
Component
struct
GetImageData
{
private
settings
:
RenderingContextSettings
=
new
RenderingContextSettings
(
true
)
private
context
:
CanvasRenderingContext2D
=
new
CanvasRenderingContext2D
(
this
.
settings
)
private
offContext
:
OffscreenCanvasRenderingContext2D
=
new
OffscreenCanvasRenderingContext2D
(
600
,
600
,
this
.
settings
)
private
img
:
ImageBitmap
=
new
ImageBitmap
(
"
/common/images/1234.png
"
)
@
Entry
@
Component
struct
GetImageData
{
private
settings
:
RenderingContextSettings
=
new
RenderingContextSettings
(
true
)
private
context
:
CanvasRenderingContext2D
=
new
CanvasRenderingContext2D
(
this
.
settings
)
private
offContext
:
OffscreenCanvasRenderingContext2D
=
new
OffscreenCanvasRenderingContext2D
(
600
,
600
,
this
.
settings
)
private
img
:
ImageBitmap
=
new
ImageBitmap
(
"
/common/images/1234.png
"
)
build
()
{
Flex
({
direction
:
FlexDirection
.
Column
,
alignItems
:
ItemAlign
.
Center
,
justifyContent
:
FlexAlign
.
Center
})
{
Canvas
(
this
.
context
)
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
this
.
offContext
.
drawImage
(
this
.
img
,
0
,
0
,
130
,
130
)
var
imagedata
=
this
.
offContext
.
getImageData
(
50
,
50
,
130
,
130
)
this
.
offContext
.
putImageData
(
imagedata
,
150
,
150
)
var
image
=
this
.
offContext
.
transferToImageBitmap
()
this
.
context
.
transferFromImageBitmap
(
image
)
})
build
()
{
Flex
({
direction
:
FlexDirection
.
Column
,
alignItems
:
ItemAlign
.
Center
,
justifyContent
:
FlexAlign
.
Center
})
{
Canvas
(
this
.
context
)
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
this
.
offContext
.
drawImage
(
this
.
img
,
0
,
0
,
130
,
130
)
var
imagedata
=
this
.
offContext
.
getImageData
(
50
,
50
,
130
,
130
)
this
.
offContext
.
putImageData
(
imagedata
,
150
,
150
)
var
image
=
this
.
offContext
.
transferToImageBitmap
()
this
.
context
.
transferFromImageBitmap
(
image
)
})
}
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
}
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
}
}
```
!
[
zh-cn_image_000000127777780
](
figures/zh-cn_image_000000127777780.png
)
...
...
@@ -2319,31 +2340,31 @@ setLineDash(segments: number[]): void
**示例:**
```
ts
@
Entry
@
Component
struct
SetLineDash
{
private
settings
:
RenderingContextSettings
=
new
RenderingContextSettings
(
true
)
private
context
:
CanvasRenderingContext2D
=
new
CanvasRenderingContext2D
(
this
.
settings
)
private
offContext
:
OffscreenCanvasRenderingContext2D
=
new
OffscreenCanvasRenderingContext2D
(
600
,
600
,
this
.
settings
)
build
()
{
Flex
({
direction
:
FlexDirection
.
Column
,
alignItems
:
ItemAlign
.
Center
,
justifyContent
:
FlexAlign
.
Center
})
{
Canvas
(
this
.
context
)
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
this
.
offContext
.
arc
(
100
,
75
,
50
,
0
,
6.28
)
this
.
offContext
.
setLineDash
([
10
,
20
])
this
.
offContext
.
stroke
()
var
image
=
this
.
offContext
.
transferToImageBitmap
()
this
.
context
.
transferFromImageBitmap
(
image
)
})
@
Entry
@
Component
struct
SetLineDash
{
private
settings
:
RenderingContextSettings
=
new
RenderingContextSettings
(
true
)
private
context
:
CanvasRenderingContext2D
=
new
CanvasRenderingContext2D
(
this
.
settings
)
private
offContext
:
OffscreenCanvasRenderingContext2D
=
new
OffscreenCanvasRenderingContext2D
(
600
,
600
,
this
.
settings
)
build
()
{
Flex
({
direction
:
FlexDirection
.
Column
,
alignItems
:
ItemAlign
.
Center
,
justifyContent
:
FlexAlign
.
Center
})
{
Canvas
(
this
.
context
)
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
this
.
offContext
.
arc
(
100
,
75
,
50
,
0
,
6.28
)
this
.
offContext
.
setLineDash
([
10
,
20
])
this
.
offContext
.
stroke
()
var
image
=
this
.
offContext
.
transferToImageBitmap
()
this
.
context
.
transferFromImageBitmap
(
image
)
})
}
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
}
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
}
}
```
!
[
zh-cn_image_000000127777772
](
figures/zh-cn_image_000000127777772.png
)
...
...
@@ -2364,42 +2385,42 @@ getLineDash(): number[]
```
ts
// xxx.ets
@
Entry
@
Component
struct
OffscreenCanvasGetLineDash
{
@
State
message
:
string
=
'
Hello World
'
private
settings
:
RenderingContextSettings
=
new
RenderingContextSettings
(
true
)
private
context
:
CanvasRenderingContext2D
=
new
CanvasRenderingContext2D
(
this
.
settings
)
private
offContext
:
OffscreenCanvasRenderingContext2D
=
new
OffscreenCanvasRenderingContext2D
(
600
,
600
,
this
.
settings
)
build
()
{
Row
()
{
Column
()
{
Text
(
this
.
message
)
.
fontSize
(
50
)
.
fontWeight
(
FontWeight
.
Bold
)
.
onClick
(()
=>
{
console
.
error
(
'
before getlinedash clicked
'
)
let
res
=
this
.
offContext
.
getLineDash
()
console
.
error
(
JSON
.
stringify
(
res
))
})
Canvas
(
this
.
context
)
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
this
.
offContext
.
arc
(
100
,
75
,
50
,
0
,
6.28
)
this
.
offContext
.
setLineDash
([
10
,
20
])
this
.
offContext
.
stroke
()
let
res
=
this
.
offContext
.
getLineDash
()
var
image
=
this
.
offContext
.
transferToImageBitmap
()
this
.
context
.
transferFromImageBitmap
(
image
)
})
@
Entry
@
Component
struct
OffscreenCanvasGetLineDash
{
@
State
message
:
string
=
'
Hello World
'
private
settings
:
RenderingContextSettings
=
new
RenderingContextSettings
(
true
)
private
context
:
CanvasRenderingContext2D
=
new
CanvasRenderingContext2D
(
this
.
settings
)
private
offContext
:
OffscreenCanvasRenderingContext2D
=
new
OffscreenCanvasRenderingContext2D
(
600
,
600
,
this
.
settings
)
build
()
{
Row
()
{
Column
()
{
Text
(
this
.
message
)
.
fontSize
(
50
)
.
fontWeight
(
FontWeight
.
Bold
)
.
onClick
(()
=>
{
console
.
error
(
'
before getlinedash clicked
'
)
let
res
=
this
.
offContext
.
getLineDash
()
console
.
error
(
JSON
.
stringify
(
res
))
})
Canvas
(
this
.
context
)
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
this
.
offContext
.
arc
(
100
,
75
,
50
,
0
,
6.28
)
this
.
offContext
.
setLineDash
([
10
,
20
])
this
.
offContext
.
stroke
()
let
res
=
this
.
offContext
.
getLineDash
()
var
image
=
this
.
offContext
.
transferToImageBitmap
()
this
.
context
.
transferFromImageBitmap
(
image
)
})
}
.
width
(
'
100%
'
)
}
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
}
.
height
(
'
100%
'
)
}
}
```
![
zh-cn_image_000000127777778
](
figures/zh-cn_image_000000127777778.png
)
...
...
@@ -2429,28 +2450,28 @@ toDataURL(type?: string, quality?: number): string
**示例:**
```
ts
// xxx.ets
@
Entry
@
Component
struct
ToDataURL
{
private
settings
:
RenderingContextSettings
=
new
RenderingContextSettings
(
true
)
private
context
:
CanvasRenderingContext2D
=
new
CanvasRenderingContext2D
(
this
.
settings
)
private
offContext
:
OffscreenCanvasRenderingContext2D
=
new
OffscreenCanvasRenderingContext2D
(
600
,
600
,
this
.
settings
)
// xxx.ets
@
Entry
@
Component
struct
ToDataURL
{
private
settings
:
RenderingContextSettings
=
new
RenderingContextSettings
(
true
)
private
context
:
CanvasRenderingContext2D
=
new
CanvasRenderingContext2D
(
this
.
settings
)
private
offContext
:
OffscreenCanvasRenderingContext2D
=
new
OffscreenCanvasRenderingContext2D
(
600
,
600
,
this
.
settings
)
build
()
{
Flex
({
direction
:
FlexDirection
.
Column
,
alignItems
:
ItemAlign
.
Center
,
justifyContent
:
FlexAlign
.
Center
})
{
Canvas
(
this
.
context
)
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
var
dataURL
=
this
.
offContext
.
toDataURL
()
})
build
()
{
Flex
({
direction
:
FlexDirection
.
Column
,
alignItems
:
ItemAlign
.
Center
,
justifyContent
:
FlexAlign
.
Center
})
{
Canvas
(
this
.
context
)
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
var
dataURL
=
this
.
offContext
.
toDataURL
()
})
}
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
}
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
}
}
```
...
...
@@ -2527,33 +2548,33 @@ restore(): void
```
ts
// xxx.ets
@
Entry
@
Component
struct
CanvasExample
{
private
settings
:
RenderingContextSettings
=
new
RenderingContextSettings
(
true
)
private
context
:
CanvasRenderingContext2D
=
new
CanvasRenderingContext2D
(
this
.
settings
)
private
offContext
:
OffscreenCanvasRenderingContext2D
=
new
OffscreenCanvasRenderingContext2D
(
600
,
600
,
this
.
settings
)
build
()
{
Flex
({
direction
:
FlexDirection
.
Column
,
alignItems
:
ItemAlign
.
Center
,
justifyContent
:
FlexAlign
.
Center
})
{
Canvas
(
this
.
context
)
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
this
.
offContext
.
save
()
// save the default state
this
.
offContext
.
fillStyle
=
"
#00ff00
"
this
.
offContext
.
fillRect
(
20
,
20
,
100
,
100
)
this
.
offContext
.
restore
()
// restore to the default state
this
.
offContext
.
fillRect
(
150
,
75
,
100
,
100
)
var
image
=
this
.
offContext
.
transferToImageBitmap
()
this
.
context
.
transferFromImageBitmap
(
image
)
})
@
Entry
@
Component
struct
CanvasExample
{
private
settings
:
RenderingContextSettings
=
new
RenderingContextSettings
(
true
)
private
context
:
CanvasRenderingContext2D
=
new
CanvasRenderingContext2D
(
this
.
settings
)
private
offContext
:
OffscreenCanvasRenderingContext2D
=
new
OffscreenCanvasRenderingContext2D
(
600
,
600
,
this
.
settings
)
build
()
{
Flex
({
direction
:
FlexDirection
.
Column
,
alignItems
:
ItemAlign
.
Center
,
justifyContent
:
FlexAlign
.
Center
})
{
Canvas
(
this
.
context
)
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
this
.
offContext
.
save
()
// save the default state
this
.
offContext
.
fillStyle
=
"
#00ff00
"
this
.
offContext
.
fillRect
(
20
,
20
,
100
,
100
)
this
.
offContext
.
restore
()
// restore to the default state
this
.
offContext
.
fillRect
(
150
,
75
,
100
,
100
)
var
image
=
this
.
offContext
.
transferToImageBitmap
()
this
.
context
.
transferFromImageBitmap
(
image
)
})
}
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
}
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
}
}
```
![
zh-cn_image_000000127777781
](
figures/zh-cn_image_000000127777781.png
)
...
...
@@ -2568,33 +2589,33 @@ save(): void
```
ts
// xxx.ets
@
Entry
@
Component
struct
CanvasExample
{
private
settings
:
RenderingContextSettings
=
new
RenderingContextSettings
(
true
)
private
context
:
CanvasRenderingContext2D
=
new
CanvasRenderingContext2D
(
this
.
settings
)
private
offContext
:
OffscreenCanvasRenderingContext2D
=
new
OffscreenCanvasRenderingContext2D
(
600
,
600
,
this
.
settings
)
build
()
{
Flex
({
direction
:
FlexDirection
.
Column
,
alignItems
:
ItemAlign
.
Center
,
justifyContent
:
FlexAlign
.
Center
})
{
Canvas
(
this
.
context
)
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
this
.
offContext
.
save
()
// save the default state
this
.
offContext
.
fillStyle
=
"
#00ff00
"
this
.
offContext
.
fillRect
(
20
,
20
,
100
,
100
)
this
.
offContext
.
restore
()
// restore to the default state
this
.
offContext
.
fillRect
(
150
,
75
,
100
,
100
)
var
image
=
this
.
offContext
.
transferToImageBitmap
()
this
.
context
.
transferFromImageBitmap
(
image
)
})
@
Entry
@
Component
struct
CanvasExample
{
private
settings
:
RenderingContextSettings
=
new
RenderingContextSettings
(
true
)
private
context
:
CanvasRenderingContext2D
=
new
CanvasRenderingContext2D
(
this
.
settings
)
private
offContext
:
OffscreenCanvasRenderingContext2D
=
new
OffscreenCanvasRenderingContext2D
(
600
,
600
,
this
.
settings
)
build
()
{
Flex
({
direction
:
FlexDirection
.
Column
,
alignItems
:
ItemAlign
.
Center
,
justifyContent
:
FlexAlign
.
Center
})
{
Canvas
(
this
.
context
)
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
.
backgroundColor
(
'
#ffff00
'
)
.
onReady
(()
=>
{
this
.
offContext
.
save
()
// save the default state
this
.
offContext
.
fillStyle
=
"
#00ff00
"
this
.
offContext
.
fillRect
(
20
,
20
,
100
,
100
)
this
.
offContext
.
restore
()
// restore to the default state
this
.
offContext
.
fillRect
(
150
,
75
,
100
,
100
)
var
image
=
this
.
offContext
.
transferToImageBitmap
()
this
.
context
.
transferFromImageBitmap
(
image
)
})
}
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
}
.
width
(
'
100%
'
)
.
height
(
'
100%
'
)
}
}
```
![
zh-cn_image_000000127777781
](
figures/zh-cn_image_000000127777781.png
)
...
...
@@ -2637,7 +2658,7 @@ createLinearGradient(x0: number, y0: number, x1: number, y1: number): void
grad
.
addColorStop
(
0.5
,
'
#ffffff
'
)
grad
.
addColorStop
(
1.0
,
'
#00ff00
'
)
this
.
offContext
.
fillStyle
=
grad
this
.
offContext
.
fillRect
(
0
,
0
,
500
,
5
00
)
this
.
offContext
.
fillRect
(
0
,
0
,
400
,
4
00
)
var
image
=
this
.
offContext
.
transferToImageBitmap
()
this
.
context
.
transferFromImageBitmap
(
image
)
})
...
...
@@ -2691,7 +2712,7 @@ createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number,
grad
.
addColorStop
(
0.5
,
'
#ffffff
'
)
grad
.
addColorStop
(
1.0
,
'
#00ff00
'
)
this
.
offContext
.
fillStyle
=
grad
this
.
offContext
.
fillRect
(
0
,
0
,
500
,
50
0
)
this
.
offContext
.
fillRect
(
0
,
0
,
440
,
44
0
)
var
image
=
this
.
offContext
.
transferToImageBitmap
()
this
.
context
.
transferFromImageBitmap
(
image
)
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录