Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
09e25b96
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看板
未验证
提交
09e25b96
编写于
11月 01, 2022
作者:
O
openharmony_ci
提交者:
Gitee
11月 01, 2022
浏览文件
操作
浏览文件
下载
差异文件
!11190 Correction of errors in camera development documents
Merge pull request !11190 from 马利/master
上级
b55b5094
8707bde0
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
23 addition
and
25 deletion
+23
-25
zh-cn/application-dev/media/camera.md
zh-cn/application-dev/media/camera.md
+23
-25
未找到文件。
zh-cn/application-dev/media/camera.md
浏览文件 @
09e25b96
...
...
@@ -59,7 +59,8 @@ import image from '@ohos.multimedia.image'
import
media
from
'
@ohos.multimedia.media
'
// 创建CameraManager对象
let
cameraManager
=
await
camera
.
getCameraManager
(
null
)
context
:
any
=
getContext
(
this
)
let
cameraManager
=
await
camera
.
getCameraManager
(
this
.
context
)
if
(
!
cameraManager
)
{
console
.
error
(
'
Failed to get the CameraManager instance
'
);
}
...
...
@@ -78,14 +79,10 @@ for (let index = 0; index < cameraArray.length; index++) {
}
// 创建相机输入流
let
cameraInput
await
cameraManager
.
createCameraInput
(
cameraArray
[
0
].
cameraId
).
then
((
input
)
=>
{
console
.
log
(
'
Promise returned with the CameraInput instance
'
);
cameraInput
=
input
})
let
cameraInput
=
await
cameraManager
.
createCameraInput
(
cameraArray
[
0
])
// 获取相机设备支持的输出流能力
let
cameraOutputCap
=
await
camera
.
getSupportedOutputCapability
(
cameraInput
);
let
cameraOutputCap
=
await
camera
Manager
.
getSupportedOutputCapability
(
cameraArray
[
0
]
);
if
(
!
cameraOutputCap
)
{
console
.
error
(
"
outputCapability outputCapability == null || undefined
"
)
}
else
{
...
...
@@ -112,8 +109,8 @@ if (!metadataObjectTypesArray) {
console
.
error
(
"
createOutput metadataObjectTypesArray == null || undefined
"
)
}
// 创建预览输出流
let
previewOutput
=
await
camera
.
createPreviewOutput
(
previewProfilesArray
[
0
],
surfaceId
)
// 创建预览输出流
,其中参数 surfaceId 参考下面 XComponent 组件,预览流为XComponent组件提供的surface
let
previewOutput
=
await
camera
Manager
.
createPreviewOutput
(
previewProfilesArray
[
0
],
surfaceId
)
if
(
!
previewOutput
)
{
console
.
error
(
"
Failed to create the PreviewOutput instance.
"
)
}
...
...
@@ -123,7 +120,7 @@ let imageReceiver = await image.createImageReceiver(1920, 1080, 4, 8)
// 获取照片显示SurfaceId
let
photoSurfaceId
=
await
imageReceiver
.
getReceivingSurfaceId
()
// 创建拍照输出流
let
photoOutput
=
await
this
.
camera
.
createPhotoOutput
(
photoProfilesArray
[
0
],
photoSurfaceId
)
let
photoOutput
=
await
cameraManager
.
createPhotoOutput
(
photoProfilesArray
[
0
],
photoSurfaceId
)
if
(
!
photoOutput
)
{
console
.
error
(
'
Failed to create the PhotoOutput instance.
'
);
return
;
...
...
@@ -155,20 +152,21 @@ let videoConfig = {
// 创建录像输出流
let
videoRecorder
await
media
.
createVideoRecorder
().
then
((
recorder
)
=>
{
media
.
createVideoRecorder
().
then
((
recorder
)
=>
{
console
.
log
(
'
createVideoRecorder called
'
)
videoRecorder
=
recorder
})
// 设置视频录制的参数
await
videoRecorder
.
prepare
(
videoConfig
)
videoRecorder
.
prepare
(
videoConfig
)
//获取录像SurfaceId
await
videoRecorder
.
getInputSurface
().
then
((
id
)
=>
{
let
videoSurfaceId
videoRecorder
.
getInputSurface
().
then
((
id
)
=>
{
console
.
log
(
'
getInputSurface called
'
)
videoSurfaceId
=
id
})
// 创建VideoOutput对象
let
videoOutput
=
camera
.
createVideoOutput
(
videoProfilesArray
[
0
],
videoSurfaceId
)
let
videoOutput
=
await
cameraManager
.
createVideoOutput
(
videoProfilesArray
[
0
],
videoSurfaceId
)
if
(
!
videoOutput
)
{
console
.
error
(
'
Failed to create the videoOutput instance.
'
);
return
;
...
...
@@ -205,11 +203,11 @@ build() {
```
typescript
function
getImageReceiverSurfaceId
()
{
var
receiver
=
image
.
createImageReceiver
(
640
,
480
,
4
,
8
)
let
receiver
=
image
.
createImageReceiver
(
640
,
480
,
4
,
8
)
console
.
log
(
TAG
+
'
before ImageReceiver check
'
)
if
(
receiver
!==
undefined
)
{
console
.
log
(
'
ImageReceiver is ok
'
)
surfaceId1
=
await
receiver
.
getReceivingSurfaceId
()
surfaceId1
=
receiver
.
getReceivingSurfaceId
()
console
.
log
(
'
ImageReceived id:
'
+
JSON
.
stringify
(
surfaceId1
))
}
else
{
console
.
log
(
'
ImageReceiver is not ok
'
)
...
...
@@ -399,17 +397,17 @@ videoOutput.start(async (err) => {
});
// 开始录像
await
videoRecorder
.
start
().
then
(()
=>
{
videoRecorder
.
start
().
then
(()
=>
{
console
.
info
(
'
videoRecorder start success
'
);
}
// 停止录像
await
videoRecorder
.
stop
().
then
(()
=>
{
videoRecorder
.
stop
().
then
(()
=>
{
console
.
info
(
'
stop success
'
);
}
// 停止录像输出流
await
videoOutput
.
stop
((
err
)
=>
{
videoOutput
.
stop
((
err
)
=>
{
if
(
err
)
{
console
.
error
(
'
Failed to stop the video output ${err.message}
'
);
return
;
...
...
@@ -424,22 +422,22 @@ await videoOutput.stop((err) => {
```
typescript
// 停止当前会话
await
captureSession
.
stop
()
captureSession
.
stop
()
// 释放相机输入流
await
cameraInput
.
release
()
cameraInput
.
release
()
// 释放预览输出流
await
previewOutput
.
release
()
previewOutput
.
release
()
// 释放拍照输出流
await
photoOutput
.
release
()
photoOutput
.
release
()
// 释放录像输出流
await
videoOutput
.
release
()
videoOutput
.
release
()
// 释放会话
await
captureSession
.
release
()
captureSession
.
release
()
// 会话置空
captureSession
=
null
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录