Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
6a257b2c
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看板
提交
6a257b2c
编写于
9月 27, 2022
作者:
F
fengzewu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test check
Signed-off-by:
N
fengzewu
<
fengzewu@huawei.com
>
上级
45324053
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
93 addition
and
60 deletion
+93
-60
zh-cn/application-dev/reference/apis/js-apis-image.md
zh-cn/application-dev/reference/apis/js-apis-image.md
+93
-60
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-image.md
浏览文件 @
6a257b2c
...
...
@@ -260,12 +260,7 @@ image.createPixelMap(color, opts)
}
pixelmap
.
writePixels
(
area
).
then
(()
=>
{
const
readArea
=
{
pixels
:
new
ArrayBuffer
(
8
),
offset
:
0
,
stride
:
8
,
// region.size.width + x < opts.width, region.size.height + y < opts.height
region
:
{
size
:
{
height
:
1
,
width
:
2
},
x
:
0
,
y
:
0
}
}
console
.
info
(
'
Succeeded to write pixelmap into the specified area.
'
);
})
}).
catch
(
error
=>
{
console
.
log
(
'
error:
'
+
error
);
...
...
@@ -290,17 +285,20 @@ writePixels(area: PositionArea, callback: AsyncCallback\<void>): void
**示例:**
```
js
const
area
=
new
ArrayBuffer
(
400
);
const
area
=
{
pixels
:
new
ArrayBuffer
(
8
),
offset
:
0
,
stride
:
8
,
region
:
{
size
:
{
height
:
1
,
width
:
2
},
x
:
0
,
y
:
0
}
}
let
bufferArr
=
new
Uint8Array
(
area
.
pixels
);
for
(
var
i
=
0
;
i
<
bufferArr
.
length
;
i
++
)
{
bufferArr
[
i
]
=
i
+
1
;
}
pixelmap
.
writePixels
(
area
,
(
error
)
=>
{
if
(
error
!=
undefined
)
{
console
.
info
(
'
Failed to write pixelmap into the specified area.
'
);
}
else
{
const
readArea
=
{
pixels
:
new
ArrayBuffer
(
20
),
offset
:
0
,
stride
:
8
,
region
:
{
size
:
{
height
:
1
,
width
:
2
},
x
:
0
,
y
:
0
},
}
console
.
info
(
'
Succeeded to write pixelmap into the specified area.
'
);
}
})
```
...
...
@@ -329,9 +327,11 @@ writeBufferToPixels(src: ArrayBuffer): Promise\<void>
```
js
const
color
=
new
ArrayBuffer
(
96
);
const
pixelMap
=
new
ArrayBuffer
(
400
);
let
bufferArr
=
new
Uint8Array
(
color
);
pixelMap
.
writeBufferToPixels
(
color
).
then
(()
=>
{
for
(
var
i
=
0
;
i
<
bufferArr
.
length
;
i
++
)
{
bufferArr
[
i
]
=
i
+
1
;
}
pixelmap
.
writeBufferToPixels
(
color
).
then
(()
=>
{
console
.
log
(
"
Succeeded in writing data from a buffer to a PixelMap.
"
);
}).
catch
((
err
)
=>
{
console
.
error
(
"
Failed to write data from a buffer to a PixelMap.
"
);
...
...
@@ -357,9 +357,11 @@ writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback\<void>): void
```
js
const
color
=
new
ArrayBuffer
(
96
);
const
pixelMap
=
new
ArrayBuffer
(
400
);
let
bufferArr
=
new
Uint8Array
(
color
);
pixelMap
.
writeBufferToPixels
(
color
,
function
(
err
)
{
for
(
var
i
=
0
;
i
<
bufferArr
.
length
;
i
++
)
{
bufferArr
[
i
]
=
i
+
1
;
}
pixelmap
.
writeBufferToPixels
(
color
,
function
(
err
)
{
if
(
err
)
{
console
.
error
(
"
Failed to write data from a buffer to a PixelMap.
"
);
return
;
...
...
@@ -386,12 +388,22 @@ getImageInfo(): Promise\<ImageInfo>
**示例:**
```
js
const
pixelMap
=
new
ArrayBuffer
(
400
);
pixelMap
.
getImageInfo
().
then
(
function
(
info
)
{
console
.
log
(
"
Succeeded in obtaining the image pixel map information.
"
);
}).
catch
((
err
)
=>
{
console
.
error
(
"
Failed to obtain the image pixel map information.
"
);
});
const
color
=
new
ArrayBuffer
(
96
);
let
opts
=
{
editable
:
true
,
pixelFormat
:
2
,
size
:
{
height
:
6
,
width
:
8
}
}
image
.
createPixelMap
(
color
,
opts
).
then
(
pixelmap
=>
{
globalpixelmap
=
pixelmap
;
if
(
pixelmap
==
undefined
)
{
console
.
error
(
"
Failed to obtain the image pixel map information.
"
);
}
pixelmap
.
getImageInfo
().
then
(
imageInfo
=>
{
if
(
imageInfo
==
undefined
)
{
console
.
error
(
"
Failed to obtain the image pixel map information.
"
);
}
if
(
imageInfo
.
size
.
height
==
4
&&
imageInfo
.
size
.
width
==
6
)
{
console
.
log
(
"
Succeeded in obtaining the image pixel map information.
"
);
}
})
})
```
### getImageInfo<sup>7+</sup>
...
...
@@ -411,8 +423,21 @@ getImageInfo(callback: AsyncCallback\<ImageInfo>): void
**示例:**
```
js
pixelmap
.
getImageInfo
((
imageInfo
)
=>
{
console
.
log
(
"
Succeeded in obtaining the image pixel map information.
"
);
const
color
=
new
ArrayBuffer
(
96
);
let
opts
=
{
editable
:
true
,
pixelFormat
:
3
,
size
:
{
height
:
4
,
width
:
6
}
}
image
.
createPixelMap
(
color
,
opts
,
(
err
,
pixelmap
)
=>
{
if
(
pixelmap
==
undefined
)
{
globalpixelmap
=
pixelmap
;
console
.
error
(
"
Failed to obtain the image pixel map information.
"
);
}
pixelmap
.
getImageInfo
((
err
,
imageInfo
)
=>
{
if
(
imageInfo
==
undefined
)
{
console
.
error
(
"
Failed to obtain the image pixel map information.
"
);
}
if
(
imageInfo
.
size
.
height
==
4
&&
imageInfo
.
size
.
width
==
6
)
{
console
.
log
(
"
Succeeded in obtaining the image pixel map information.
"
);
}
})
})
```
...
...
@@ -499,9 +524,15 @@ opacity(rate: number, callback: AsyncCallback\<void>): void
**示例:**
```
js
async
function
()
{
await
pixelMap
.
opacity
(
0.5
);
}
var
rate
=
0.5
;
pixelmap
.
opacity
(
rate
,
(
err
)
=>
{
if
(
err
)
{
console
.
error
(
"
Failed to set opacity.
"
);
return
;
}
else
{
console
.
log
(
"
Succeeded in setting opacity.
"
);
}
})
```
### opacity<sup>9+</sup>
...
...
@@ -528,7 +559,8 @@ opacity(rate: number): Promise\<void>
```
js
async
function
()
{
await
pixelMap
.
opacity
(
0.5
);
var
rate
=
0.5
;
await
pixelmap
.
opacity
(
rate
);
}
```
...
...
@@ -549,12 +581,8 @@ createAlphaPixelmap(): Promise\<PixelMap>
**示例:**
```
js
pixelMap
.
createAlphaPixelmap
(
async
(
err
,
alphaPixelMap
)
=>
{
if
(
alphaPixelMap
==
undefined
)
{
console
.
info
(
'
Failed to obtain new pixel map.
'
);
}
else
{
console
.
info
(
'
Succeed in obtaining new pixel map.
'
);
}
async
function
()
{
await
pixelmap
.
createAlphaPixelmap
();
})
```
...
...
@@ -575,14 +603,13 @@ createAlphaPixelmap(callback: AsyncCallback\<PixelMap>): void
**示例:**
```
js
let
pixelMap
=
await
imageSource
.
createPixelMap
();
if
(
pixelMap
!=
undefined
)
{
pixelMap
.
createAlphaPixelmap
(
async
(
err
,
alphaPixelMap
)
=>
{
console
.
info
(
'
Failed to obtain new pixel map.
'
);
})
}
else
{
console
.
info
(
'
Succeed in obtaining new pixel map.
'
);
}
pixelmap
.
createAlphaPixelmap
((
err
,
alphaPixelMap
)
=>
{
if
(
alphaPixelMap
==
undefined
)
{
console
.
info
(
'
Failed to obtain new pixel map.
'
);
}
else
{
console
.
info
(
'
Succeed in obtaining new pixel map.
'
);
}
})
```
### scale<sup>9+</sup>
...
...
@@ -605,7 +632,7 @@ scale(x: number, y: number, callback: AsyncCallback\<void>): void
```
js
async
function
()
{
await
pixel
M
ap
.
scale
(
2.0
,
1.0
);
await
pixel
m
ap
.
scale
(
2.0
,
1.0
);
}
```
...
...
@@ -634,7 +661,7 @@ scale(x: number, y: number): Promise\<void>
```
js
async
function
()
{
await
pixel
M
ap
.
scale
(
2.0
,
1.0
);
await
pixel
m
ap
.
scale
(
2.0
,
1.0
);
}
```
...
...
@@ -658,7 +685,7 @@ translate(x: number, y: number, callback: AsyncCallback\<void>): void
```
js
async
function
()
{
await
pixel
M
ap
.
translate
(
3.0
,
1.0
);
await
pixel
m
ap
.
translate
(
3.0
,
1.0
);
}
```
...
...
@@ -687,7 +714,7 @@ translate(x: number, y: number): Promise\<void>
```
js
async
function
()
{
await
pixel
M
ap
.
translate
(
3.0
,
1.0
);
await
pixel
m
ap
.
translate
(
3.0
,
1.0
);
}
```
...
...
@@ -710,7 +737,7 @@ rotate(angle: number, callback: AsyncCallback\<void>): void
```
js
async
function
()
{
await
pixel
M
ap
.
rotate
(
90.0
);
await
pixel
m
ap
.
rotate
(
90.0
);
}
```
...
...
@@ -738,7 +765,7 @@ rotate(angle: number): Promise\<void>
```
js
async
function
()
{
await
pixel
M
ap
.
rotate
(
90.0
);
await
pixel
m
ap
.
rotate
(
90.0
);
}
```
...
...
@@ -762,7 +789,7 @@ flip(horizontal: boolean, vertical: boolean, callback: AsyncCallback\<void>): vo
```
js
async
function
()
{
await
pixel
M
ap
.
flip
(
false
,
true
);
await
pixel
m
ap
.
flip
(
false
,
true
);
}
```
...
...
@@ -791,7 +818,7 @@ flip(horizontal: boolean, vertical: boolean): Promise\<void>
```
js
async
function
()
{
await
pixel
M
ap
.
flip
(
false
,
true
);
await
pixel
m
ap
.
flip
(
false
,
true
);
}
```
...
...
@@ -814,7 +841,7 @@ crop(region: Region, callback: AsyncCallback\<void>): void
```
js
async
function
()
{
await
pixel
M
ap
.
crop
({
x
:
0
,
y
:
0
,
size
:
{
height
:
100
,
width
:
100
}
});
await
pixel
m
ap
.
crop
({
x
:
0
,
y
:
0
,
size
:
{
height
:
100
,
width
:
100
}
});
}
```
...
...
@@ -842,7 +869,7 @@ crop(region: Region): Promise\<void>
```
js
async
function
()
{
await
pixel
M
ap
.
crop
({
x
:
0
,
y
:
0
,
size
:
{
height
:
100
,
width
:
100
}
});
await
pixel
m
ap
.
crop
({
x
:
0
,
y
:
0
,
size
:
{
height
:
100
,
width
:
100
}
});
}
```
...
...
@@ -1006,7 +1033,7 @@ createImageSource(fd: number, options: SourceOptions): ImageSource
**示例:**
```
js
const
imageSourceApi
=
image
.
createImageSource
(
fd
);
const
imageSourceApi
=
image
.
createImageSource
(
0
);
```
## image.createImageSource<sup>9+</sup>
...
...
@@ -1082,7 +1109,7 @@ CreateIncrementalSource(buf: ArrayBuffer): ImageSource
```
js
const
buf
=
new
ArrayBuffer
(
96
);
const
imageSourceApi
=
image
.
CreateIncrementalSource
(
buf
);
const
imageSource
IncrementalS
Api
=
image
.
CreateIncrementalSource
(
buf
);
```
## image.CreateIncrementalSource<sup>9+</sup>
...
...
@@ -1110,7 +1137,7 @@ CreateIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource
```
js
const
buf
=
new
ArrayBuffer
(
96
);
const
imageSourceApi
=
image
.
CreateIncrementalSource
(
buf
);
const
imageSource
IncrementalS
Api
=
image
.
CreateIncrementalSource
(
buf
);
```
## ImageSource
...
...
@@ -1281,7 +1308,7 @@ getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCa
**示例:**
```
js
const
property
=
new
ArrayBuffer
(
400
);
let
property
=
{
index
:
0
,
defaultValue
:
'
9999
'
}
imageSourceApi
.
getImageProperty
(
"
BitsPerSample
"
,
property
,(
error
,
data
)
=>
{
if
(
error
)
{
console
.
log
(
'
Failed to get the value of the specified attribute key of the image.
'
);
...
...
@@ -1476,7 +1503,15 @@ createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): vo
**示例:**
```
js
const
decodingOptions
=
new
ArrayBuffer
(
400
);
let
decodingOptions
=
{
sampleSize
:
1
,
editable
:
true
,
desiredSize
:
{
width
:
1
,
height
:
2
},
rotate
:
10
,
desiredPixelFormat
:
3
,
desiredRegion
:
{
size
:
{
height
:
1
,
width
:
2
},
x
:
0
,
y
:
0
},
index
:
0
};
imageSourceApi
.
createPixelMap
(
decodingOptions
,
pixelmap
=>
{
console
.
log
(
'
Succeeded in creating pixelmap object.
'
);
})
...
...
@@ -1580,7 +1615,6 @@ packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<Arr
```
js
let
packOpts
=
{
format
:
"
image/jpeg
"
,
quality
:
98
};
const
imageSourceApi
=
new
ArrayBuffer
(
400
);
imagePackerApi
.
packing
(
imageSourceApi
,
packOpts
,
data
=>
{})
```
...
...
@@ -1609,7 +1643,6 @@ packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer>
```
js
let
packOpts
=
{
format
:
"
image/jpeg
"
,
quality
:
98
}
const
imageSourceApi
=
new
ArrayBuffer
(
400
);
imagePackerApi
.
packing
(
imageSourceApi
,
packOpts
)
.
then
(
data
=>
{
console
.
log
(
'
packing succeeded.
'
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录