Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
170c14bd
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
170c14bd
编写于
10月 08, 2022
作者:
F
fengzewu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix code bug
Signed-off-by:
N
fengzewu
<
fengzewu@huawei.com
>
上级
fe671774
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
64 addition
and
100 deletion
+64
-100
zh-cn/application-dev/media/image.md
zh-cn/application-dev/media/image.md
+64
-100
未找到文件。
zh-cn/application-dev/media/image.md
浏览文件 @
170c14bd
...
...
@@ -21,45 +21,43 @@ let opts = { alphaType: 0, editable: true, pixelFormat: 4, scaleMode: 1, size: {
// 创建pixelmap对象
const
color
=
new
ArrayBuffer
(
96
);
let
opts
=
{
alphaType
:
0
,
editable
:
true
,
pixelFormat
:
4
,
scaleMode
:
1
,
size
:
{
height
:
2
,
width
:
3
}
}
image
.
createPixelMap
(
color
,
opts
,
pixelmap
=>
{
expect
(
pixelmap
!==
null
).
assertTrue
();
console
.
info
(
'
TC_001-1 success
'
);
done
();
})
image
.
createPixelMap
(
color
,
opts
,
pixelmap
=>
{
console
.
log
(
'
Succeeded in creating pixelmap.
'
);
})
// 用于读像素
pixelmap
.
readPixels
(
area
,(
data
)
=>
{
if
(
data
!==
null
)
{
var
bufferArr
=
new
Uint8Array
(
area
.
pixels
);
if
(
data
!==
null
)
{
var
bufferArr
=
new
Uint8Array
(
area
.
pixels
);
var
res
=
true
;
for
(
var
i
=
0
;
i
<
bufferArr
.
length
;
i
++
)
{
console
.
info
(
'
TC_021-1 buffer
'
+
bufferArr
[
i
]);
if
(
res
)
{
if
(
bufferArr
[
i
]
==
0
)
{
res
=
false
;
console
.
info
(
'
TC_021-1 Success
'
);
expect
(
true
).
assertTrue
();
done
();
break
;
}
}
console
.
info
(
'
buffer
'
+
bufferArr
[
i
]);
if
(
res
)
{
if
(
bufferArr
[
i
]
==
0
)
{
res
=
false
;
console
.
log
(
'
readPixels end.
'
);
break
;
}
}
}
}
})
// 用于存像素
const
readBuffer
=
new
ArrayBuffer
(
96
);
pixelmap
.
readPixelsToBuffer
(
readBuffer
,()
=>
{
var
bufferArr
=
new
Uint8Array
(
readBuffer
);
var
res
=
true
;
for
(
var
i
=
0
;
i
<
bufferArr
.
length
;
i
++
)
{
if
(
res
)
{
if
(
bufferArr
[
i
]
!==
0
)
{
res
=
false
;
console
.
info
(
'
TC_020-1 Success
'
);
expect
(
true
).
assertTrue
();
done
();
break
;
var
bufferArr
=
new
Uint8Array
(
readBuffer
);
var
res
=
true
;
for
(
var
i
=
0
;
i
<
bufferArr
.
length
;
i
++
)
{
if
(
res
)
{
if
(
bufferArr
[
i
]
!==
0
)
{
res
=
false
;
console
.
log
(
'
readPixelsToBuffer end.
'
);
break
;
}
}
}
}
}
)
// 用于写像素
pixelmap
.
writePixels
(
area
,()
=>
{
...
...
@@ -71,56 +69,49 @@ pixelmap.writePixels(area,() => {
if
(
res
)
{
if
(
readArr
[
i
]
!==
0
)
{
res
=
false
;
console
.
info
(
'
TC_022-1 Success
'
);
expect
(
true
).
assertTrue
();
done
();
console
.
log
(
'
readPixels end.please check buffer
'
);
break
;
}
}
}
})
})
// 用于写像素到缓冲区
pixelmap
.
writeBufferToPixels
(
writeColor
).
then
(()
=>
{
const
readBuffer
=
new
ArrayBuffer
(
96
);
pixelmap
.
readPixelsToBuffer
(
readBuffer
).
then
(()
=>
{
var
bufferArr
=
new
Uint8Array
(
readBuffer
);
var
res
=
true
;
for
(
var
i
=
0
;
i
<
bufferArr
.
length
;
i
++
)
{
if
(
res
)
{
if
(
bufferArr
[
i
]
!==
i
)
{
res
=
false
;
console
.
info
(
'
TC_023 Success
'
);
expect
(
true
).
assertTrue
()
done
();
var
bufferArr
=
new
Uint8Array
(
readBuffer
);
var
res
=
true
;
for
(
var
i
=
0
;
i
<
bufferArr
.
length
;
i
++
)
{
if
(
res
)
{
if
(
bufferArr
[
i
]
!==
i
)
{
res
=
false
;
console
.
log
(
'
readPixels end.please check buffer
'
);
break
;
}
}
}
})
})
// 用于获取图片信息
pixelmap
.
getImageInfo
(
imageInfo
=>
{
if
(
imageInfo
!==
null
)
{
console
.
info
(
'
TC_024-1 imageInfo is ready
'
);
expect
(
imageInfo
.
size
.
height
==
4
).
assertTrue
();
expect
(
imageInfo
.
size
.
width
==
6
).
assertTrue
();
expect
(
imageInfo
.
pixelFormat
==
4
).
assertTrue
();
done
();
console
.
log
(
'
Succeeded in getting imageInfo
'
);
}
})
// 用于释放pixelmap
pixelmap
.
release
(()
=>
{
expect
(
true
).
assertTrue
();
console
.
log
(
'
TC_027-1 suc
'
);
done
();
console
.
log
(
'
Succeeded in releasing pixelmap
'
);
})
let
path
=
'
/data/local/tmp/test.jpg
'
;
// 用于创建imagesource(uri)
const
imageSourceApi
=
image
.
createImageSource
(
path
);
// '/data/local/tmp/test.jpg'
const
imageSourceApi
=
image
.
createImageSource
(
path
);
// 用于创建imagesource(fd)
const
imageSourceApi
=
image
.
createImageSource
(
29
);
const
imageSourceApi
=
image
.
createImageSource
(
fd
);
// 用于创建imagesource(data)
const
data
=
new
ArrayBuffer
(
96
);
...
...
@@ -128,15 +119,15 @@ const imageSourceApi = image.createImageSource(data);
// 用于释放imagesource
imageSourceApi
.
release
(()
=>
{
console
.
info
(
'
TC_044-1 Success
'
);
})
console
.
log
(
'
Succeeded in releasing imagesource
'
);
})
// 用于编码
const
imagePackerApi
=
image
.
createImagePacker
();
const
imageSourceApi
=
image
.
createImageSource
(
0
);
let
packOpts
=
{
format
:
"
image/jpeg
"
,
quality
:
98
};
imagePackerApi
.
packing
(
imageSourceApi
,
packOpts
,
data
=>
{
console
.
info
(
'
TC_062-1 finished
'
);
expect
(
data
!==
null
).
assertTrue
();
done
();
console
.
log
(
'
Succeeded in packing
'
);
})
// 用于释放imagepacker
...
...
@@ -146,7 +137,7 @@ imagePackerApi.release();
### 解码场景
```
js
let
path
=
'
/data/local/tmp/test.jpg
'
;
// 设置创建imagesource的路径
/
data
/
local
/
tmp
/
test
.
jpg
// 设置创建imagesource的路径
// 用路径创建imagesource
const
imageSourceApi
=
image
.
createImageSource
(
path
);
// '/data/local/tmp/test.jpg'
...
...
@@ -164,75 +155,54 @@ let decodingOptions = {
// 用于回调方式创建pixelmap
imageSourceApi
.
createPixelMap
(
decodingOptions
,
pixelmap
=>
{
console
.
info
(
'
TC_050 createPixelMap
'
);
expect
(
pixelmap
!==
null
).
assertTrue
();
done
();
})
}
console
.
log
(
'
Succeeded in creating pixelmap.
'
);
})
// 用于promise创建pixelmap
imageSourceApi
.
createPixelMap
().
then
(
pixelmap
=>
{
console
.
info
(
'
TC_050-11 createPixelMap
'
);
expect
(
pixelmap
!==
null
).
assertTrue
();
done
();
console
.
log
(
'
Succeeded in creating pixelmap.
'
);
})
// 函数调用发生异常时,捕捉错误信息
catch
(
error
=>
{
console
.
log
(
'
TC_050-11 error:
'
+
error
);
expect
().
assertFail
();
done
();
console
.
log
(
'
Failed in creating pixelmap.
'
+
error
);
})
// 用于获取像素每行字节数
pixelmap
.
getBytesNumberPerRow
(
num
=>
{
console
.
info
(
'
TC_025-1 num is
'
+
num
);
expect
(
num
==
expectNum
).
assertTrue
();
done
();
console
.
log
(
'
Succeeded in getting BytesNumber PerRow.
'
);
})
// 用于获取像素总字节数
pixelmap
.
getPixelBytesNumber
(
num
=>
{
console
.
info
(
'
TC_026-1 num is
'
+
num
);
expect
(
num
==
expectNum
).
assertTrue
();
done
();
console
.
log
(
'
Succeeded in getting PixelBytesNumber.
'
);
})
// 用于获取pixelmap信息
pixelmap
.
getImageInfo
(
imageInfo
=>
{})
// 用于打印获取失败信息
console
.
info
(
'
TC_024-1 imageInfo is empty
'
);
expect
(
false
).
assertTrue
()
// 用于释放pixelmap
pixelmap
.
release
(()
=>
{
expect
(
true
).
assertTrue
();
console
.
log
(
'
TC_027-1 suc
'
);
done
();
console
.
log
(
'
Succeeded in releasing pixelmap
'
);
})
// 用于捕捉释放失败信息
catch
(
error
=>
{
console
.
log
(
'
TC_027-1 error:
'
+
error
);
expect
().
assertFail
();
done
();
console
.
log
(
'
Failed in releasing pixelmap.
'
+
error
);
})
```
### 编码场景
```
js
let
path
=
'
/data/local/tmp/test.png
'
// 设置创建imagesource的路径
/
data
/
local
/
tmp
/
test
.
png
// 设置创建imagesource的路径
// 用于设置imagesource
const
imageSourceApi
=
image
.
createImageSource
(
path
);
// '/data/local/tmp/test.png'
// 如果创建imagesource失败,打印错误信息
if
(
imageSourceApi
==
null
)
{
console
.
info
(
'
TC_062 create image source failed
'
);
expect
(
false
).
assertTrue
();
done
();
console
.
log
(
'
Failed in creating imageSource.
'
);
}
// 如果创建imagesource成功,则创建imagepacker
...
...
@@ -240,9 +210,7 @@ const imagePackerApi = image.createImagePacker();
// 如果创建失败,打印错误信息
if
(
imagePackerApi
==
null
)
{
console
.
info
(
'
TC_062 create image packer failed
'
);
expect
(
false
).
assertTrue
();
done
();
console
.
log
(
'
Failed in creating imagePacker.
'
);
}
// 如果创建imagepacker成功,则设置编码参数
...
...
@@ -252,23 +220,19 @@ let packOpts = { format:["image/jpeg"], // 支持编码的格式为jpg
// 用于编码
imagePackerApi
.
packing
(
imageSourceApi
,
packOpts
)
.
then
(
data
=>
{
console
.
info
(
'
TC_062 finished
'
);
expect
(
data
!==
null
).
assertTrue
();
done
();
console
.
log
(
'
Succeeded in packing
'
);
})
// 编码完成,释放imagepacker
imagePackerApi
.
release
();
// 用于获取imagesource信息
imageSourceApi
.
getImageInfo
(
imageInfo
=>
{
console
.
info
(
'
TC_045 imageInfo
'
);
expect
(
imageInfo
!==
null
).
assertTrue
();
done
();
console
.
log
(
'
Succeeded in getting imageInfo
'
);
})
// 用于更新增量数据
imageSourceIncrementalSApi
.
updateData
(
array
,
false
,
0
,
10
,(
error
,
data
)
=>
{})
imageSourceIncrementalSApi
.
updateData
(
array
,
false
,
0
,
10
,(
error
,
data
)
=>
{})
```
...
...
@@ -285,7 +249,7 @@ public async init(surfaceId: any) {
// 获取Surface ID
var
surfaceId
=
await
receiver
.
getReceivingSurfaceId
();
// 注册Surface的监听,在su
r
face的buffer准备好后触发
// 注册Surface的监听,在suface的buffer准备好后触发
receiver
.
on
(
'
imageArrival
'
,
()
=>
{
// 去获取Surface中最新的buffer
receiver
.
readNextImage
((
err
,
img
)
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录