Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
fe08de73
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,发现更多精彩内容 >>
未验证
提交
fe08de73
编写于
9月 19, 2022
作者:
H
hanyingjun
提交者:
Gitee
9月 19, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
【OpenHarmony开源贡献者计划2022】update zh-cn/application-dev/media/camera.md.
Signed-off-by:
N
hanyingjun
<
965011183@qq.com
>
上级
df7e7793
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
56 addition
and
56 deletion
+56
-56
zh-cn/application-dev/media/camera.md
zh-cn/application-dev/media/camera.md
+56
-56
未找到文件。
zh-cn/application-dev/media/camera.md
浏览文件 @
fe08de73
...
@@ -26,7 +26,7 @@ import image from '@ohos.multimedia.image'
...
@@ -26,7 +26,7 @@ import image from '@ohos.multimedia.image'
import
media
from
'
@ohos.multimedia.media
'
import
media
from
'
@ohos.multimedia.media
'
import
featureAbility
from
'
@ohos.ability.featureAbility
'
import
featureAbility
from
'
@ohos.ability.featureAbility
'
//创建CameraManager对象
//
创建CameraManager对象
let
cameraManager
let
cameraManager
await
camera
.
getCameraManager
(
globalThis
.
Context
,
(
err
,
manager
)
=>
{
await
camera
.
getCameraManager
(
globalThis
.
Context
,
(
err
,
manager
)
=>
{
if
(
err
)
{
if
(
err
)
{
...
@@ -37,13 +37,13 @@ await camera.getCameraManager(globalThis.Context, (err, manager) => {
...
@@ -37,13 +37,13 @@ await camera.getCameraManager(globalThis.Context, (err, manager) => {
cameraManager
=
manager
cameraManager
=
manager
})
})
//注册回调函数监听相机状态变化,获取状态变化的相机信息
//
注册回调函数监听相机状态变化,获取状态变化的相机信息
cameraManager
.
on
(
'
cameraStatus
'
,
(
cameraStatusInfo
)
=>
{
cameraManager
.
on
(
'
cameraStatus
'
,
(
cameraStatusInfo
)
=>
{
console
.
log
(
'
camera :
'
+
cameraStatusInfo
.
camera
.
cameraId
);
console
.
log
(
'
camera :
'
+
cameraStatusInfo
.
camera
.
cameraId
);
console
.
log
(
'
status:
'
+
cameraStatusInfo
.
status
);
console
.
log
(
'
status:
'
+
cameraStatusInfo
.
status
);
})
})
//获取相机列表
//
获取相机列表
let
cameraArray
let
cameraArray
await
cameraManager
.
getCameras
((
err
,
cameras
)
=>
{
await
cameraManager
.
getCameras
((
err
,
cameras
)
=>
{
if
(
err
)
{
if
(
err
)
{
...
@@ -55,20 +55,20 @@ await cameraManager.getCameras((err, cameras) => {
...
@@ -55,20 +55,20 @@ await cameraManager.getCameras((err, cameras) => {
})
})
for
(
let
cameraIndex
=
0
;
cameraIndex
<
cameraArray
.
length
;
cameraIndex
++
)
{
for
(
let
cameraIndex
=
0
;
cameraIndex
<
cameraArray
.
length
;
cameraIndex
++
)
{
console
.
log
(
'
cameraId :
'
+
cameraArray
[
cameraIndex
].
cameraId
)
//获取相机ID
console
.
log
(
'
cameraId :
'
+
cameraArray
[
cameraIndex
].
cameraId
)
//
获取相机ID
console
.
log
(
'
cameraPosition :
'
+
cameraArray
[
cameraIndex
].
cameraPosition
)
//获取相机位置
console
.
log
(
'
cameraPosition :
'
+
cameraArray
[
cameraIndex
].
cameraPosition
)
//
获取相机位置
console
.
log
(
'
cameraType :
'
+
cameraArray
[
cameraIndex
].
cameraType
)
//获取相机类型
console
.
log
(
'
cameraType :
'
+
cameraArray
[
cameraIndex
].
cameraType
)
//
获取相机类型
console
.
log
(
'
connectionType :
'
+
cameraArray
[
cameraIndex
].
connectionType
)
//获取相机连接类型
console
.
log
(
'
connectionType :
'
+
cameraArray
[
cameraIndex
].
connectionType
)
//
获取相机连接类型
}
}
//创建相机输入流
//
创建相机输入流
let
cameraInput
let
cameraInput
await
cameraManager
.
createCameraInput
(
cameraArray
[
0
].
cameraId
).
then
((
input
)
=>
{
await
cameraManager
.
createCameraInput
(
cameraArray
[
0
].
cameraId
).
then
((
input
)
=>
{
console
.
log
(
'
Promise returned with the CameraInput instance
'
);
console
.
log
(
'
Promise returned with the CameraInput instance
'
);
cameraInput
=
input
cameraInput
=
input
})
})
//创建预览输出流
//
创建预览输出流
let
previewOutput
let
previewOutput
camera
.
createPreviewOutput
((
globalThis
.
surfaceId
),
(
err
,
output
)
=>
{
camera
.
createPreviewOutput
((
globalThis
.
surfaceId
),
(
err
,
output
)
=>
{
if
(
err
)
{
if
(
err
)
{
...
@@ -79,11 +79,11 @@ camera.createPreviewOutput((globalThis.surfaceId), (err, output) => {
...
@@ -79,11 +79,11 @@ camera.createPreviewOutput((globalThis.surfaceId), (err, output) => {
previewOutput
=
output
previewOutput
=
output
});
});
//创建ImageReceiver对象,并设置照片参数
//
创建ImageReceiver对象,并设置照片参数
let
imageReceiver
=
await
image
.
createImageReceiver
(
1920
,
1080
,
4
,
8
)
let
imageReceiver
=
await
image
.
createImageReceiver
(
1920
,
1080
,
4
,
8
)
//获取照片显示SurfaceId
//
获取照片显示SurfaceId
let
photoSurfaceId
=
await
imageReceiver
.
getReceivingSurfaceId
()
let
photoSurfaceId
=
await
imageReceiver
.
getReceivingSurfaceId
()
//创建拍照输出流
//
创建拍照输出流
let
photoOutput
let
photoOutput
camera
.
createPhotoOutput
((
photoSurfaceId
),
(
err
,
output
)
=>
{
camera
.
createPhotoOutput
((
photoSurfaceId
),
(
err
,
output
)
=>
{
if
(
err
)
{
if
(
err
)
{
...
@@ -94,7 +94,7 @@ camera.createPhotoOutput((photoSurfaceId), (err, output) => {
...
@@ -94,7 +94,7 @@ camera.createPhotoOutput((photoSurfaceId), (err, output) => {
photoOutput
=
output
photoOutput
=
output
});
});
//创建视频录制的参数
//
创建视频录制的参数
let
videoProfile
=
{
let
videoProfile
=
{
audioBitrate
:
48000
,
audioBitrate
:
48000
,
audioChannels
:
2
,
audioChannels
:
2
,
...
@@ -116,13 +116,13 @@ let videoConfig = {
...
@@ -116,13 +116,13 @@ let videoConfig = {
location
:
{
latitude
:
30
,
longitude
:
130
},
location
:
{
latitude
:
30
,
longitude
:
130
},
}
}
//创建录像输出流
//
创建录像输出流
let
videoRecorder
let
videoRecorder
await
media
.
createVideoRecorder
().
then
((
recorder
)
=>
{
await
media
.
createVideoRecorder
().
then
((
recorder
)
=>
{
console
.
log
(
'
createVideoRecorder called
'
)
console
.
log
(
'
createVideoRecorder called
'
)
videoRecorder
=
recorder
videoRecorder
=
recorder
})
})
//设置视频录制的参数
//
设置视频录制的参数
await
videoRecorder
.
prepare
(
videoConfig
)
await
videoRecorder
.
prepare
(
videoConfig
)
//获取录像SurfaceId
//获取录像SurfaceId
await
videoRecorder
.
getInputSurface
().
then
((
id
)
=>
{
await
videoRecorder
.
getInputSurface
().
then
((
id
)
=>
{
...
@@ -132,7 +132,7 @@ await videoRecorder.getInputSurface().then((id) => {
...
@@ -132,7 +132,7 @@ await videoRecorder.getInputSurface().then((id) => {
```
```
videoRecorder详细创建方法可参考:
[
视频录制开发指导
](
./video-recorder.md
)
videoRecorder详细创建方法可参考:
[
视频录制开发指导
](
./video-recorder.md
)
```
js
```
js
//创建VideoOutput对象
//
创建VideoOutput对象
let
videoOutput
let
videoOutput
camera
.
createVideoOutput
((
surfaceId
),
(
err
,
output
)
=>
{
camera
.
createVideoOutput
((
surfaceId
),
(
err
,
output
)
=>
{
if
(
err
)
{
if
(
err
)
{
...
@@ -148,14 +148,14 @@ camera.createVideoOutput((surfaceId), (err, output) => {
...
@@ -148,14 +148,14 @@ camera.createVideoOutput((surfaceId), (err, output) => {
#### 参数设置
#### 参数设置
```
js
```
js
//判断设备是否支持闪光灯
//
判断设备是否支持闪光灯
let
flashStatus
let
flashStatus
await
cameraInput
.
hasFlash
().
then
((
status
)
=>
{
await
cameraInput
.
hasFlash
().
then
((
status
)
=>
{
console
.
log
(
'
Promise returned with the flash light support status:
'
+
status
);
console
.
log
(
'
Promise returned with the flash light support status:
'
+
status
);
flashStatus
=
status
flashStatus
=
status
})
})
if
(
flashStatus
)
{
if
(
flashStatus
)
{
//判断是否支持自动闪光灯模式
//
判断是否支持自动闪光灯模式
let
flashModeStatus
let
flashModeStatus
cameraInput
.
isFlashModeSupported
(
camera
.
FlashMode
.
FLASH_MODE_AUTO
,
(
err
,
status
)
=>
{
cameraInput
.
isFlashModeSupported
(
camera
.
FlashMode
.
FLASH_MODE_AUTO
,
(
err
,
status
)
=>
{
if
(
err
)
{
if
(
err
)
{
...
@@ -166,7 +166,7 @@ if(flashStatus) {
...
@@ -166,7 +166,7 @@ if(flashStatus) {
flashModeStatus
=
status
flashModeStatus
=
status
})
})
if
(
flashModeStatus
)
{
if
(
flashModeStatus
)
{
//设置自动闪光灯模式
//
设置自动闪光灯模式
cameraInput
.
setFlashMode
(
camera
.
FlashMode
.
FLASH_MODE_AUTO
,
(
err
)
=>
{
cameraInput
.
setFlashMode
(
camera
.
FlashMode
.
FLASH_MODE_AUTO
,
(
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
Failed to set the flash mode ${err.message}
'
);
console
.
error
(
'
Failed to set the flash mode ${err.message}
'
);
...
@@ -177,7 +177,7 @@ if(flashStatus) {
...
@@ -177,7 +177,7 @@ if(flashStatus) {
}
}
}
}
//判断是否支持连续自动变焦模式
//
判断是否支持连续自动变焦模式
let
focusModeStatus
let
focusModeStatus
cameraInput
.
isFocusModeSupported
(
camera
.
FocusMode
.
FOCUS_MODE_CONTINUOUS_AUTO
,
(
err
,
status
)
=>
{
cameraInput
.
isFocusModeSupported
(
camera
.
FocusMode
.
FOCUS_MODE_CONTINUOUS_AUTO
,
(
err
,
status
)
=>
{
if
(
err
)
{
if
(
err
)
{
...
@@ -188,7 +188,7 @@ cameraInput.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_CONTINUOUS_AUTO, (e
...
@@ -188,7 +188,7 @@ cameraInput.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_CONTINUOUS_AUTO, (e
focusModeStatus
=
status
focusModeStatus
=
status
})
})
if
(
focusModeStatus
)
{
if
(
focusModeStatus
)
{
//设置连续自动变焦模式
//
设置连续自动变焦模式
cameraInput
.
setFocusMode
(
camera
.
FocusMode
.
FOCUS_MODE_CONTINUOUS_AUTO
,
(
err
)
=>
{
cameraInput
.
setFocusMode
(
camera
.
FocusMode
.
FOCUS_MODE_CONTINUOUS_AUTO
,
(
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
Failed to set the focus mode ${err.message}
'
);
console
.
error
(
'
Failed to set the focus mode ${err.message}
'
);
...
@@ -198,7 +198,7 @@ if(focusModeStatus) {
...
@@ -198,7 +198,7 @@ if(focusModeStatus) {
})
})
}
}
//获取相机支持的可变焦距比范围
//
获取相机支持的可变焦距比范围
let
zoomRatioRange
let
zoomRatioRange
cameraInput
.
getZoomRatioRange
((
err
,
range
)
=>
{
cameraInput
.
getZoomRatioRange
((
err
,
range
)
=>
{
if
(
err
)
{
if
(
err
)
{
...
@@ -209,7 +209,7 @@ cameraInput.getZoomRatioRange((err, range) => {
...
@@ -209,7 +209,7 @@ cameraInput.getZoomRatioRange((err, range) => {
zoomRatioRange
=
range
zoomRatioRange
=
range
})
})
//设置可变焦距比
//
设置可变焦距比
cameraInput
.
setZoomRatio
(
zoomRatioRange
[
0
],
(
err
)
=>
{
cameraInput
.
setZoomRatio
(
zoomRatioRange
[
0
],
(
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
Failed to set the zoom ratio value ${err.message}
'
);
console
.
error
(
'
Failed to set the zoom ratio value ${err.message}
'
);
...
@@ -224,7 +224,7 @@ cameraInput.setZoomRatio(zoomRatioRange[0], (err) => {
...
@@ -224,7 +224,7 @@ cameraInput.setZoomRatio(zoomRatioRange[0], (err) => {
##### 创建会话
##### 创建会话
```
js
```
js
//创建Context对象
//
创建Context对象
let
context
=
featureAbility
.
getContext
()
let
context
=
featureAbility
.
getContext
()
//创建会话
//创建会话
...
@@ -238,7 +238,7 @@ await camera.createCaptureSession((context), (err, session) => {
...
@@ -238,7 +238,7 @@ await camera.createCaptureSession((context), (err, session) => {
captureSession
=
session
captureSession
=
session
});
});
//开始配置会话
//
开始配置会话
await
captureSession
.
beginConfig
((
err
)
=>
{
await
captureSession
.
beginConfig
((
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
Failed to start the configuration. ${err.message}
'
);
console
.
error
(
'
Failed to start the configuration. ${err.message}
'
);
...
@@ -247,7 +247,7 @@ await captureSession.beginConfig((err) => {
...
@@ -247,7 +247,7 @@ await captureSession.beginConfig((err) => {
console
.
log
(
'
Callback invoked to indicate the begin config success.
'
);
console
.
log
(
'
Callback invoked to indicate the begin config success.
'
);
});
});
//向会话中添加相机输入流
//
向会话中添加相机输入流
await
captureSession
.
addInput
(
cameraInput
,
(
err
)
=>
{
await
captureSession
.
addInput
(
cameraInput
,
(
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
Failed to add the CameraInput instance. ${err.message}
'
);
console
.
error
(
'
Failed to add the CameraInput instance. ${err.message}
'
);
...
@@ -256,7 +256,7 @@ await captureSession.addInput(cameraInput, (err) => {
...
@@ -256,7 +256,7 @@ await captureSession.addInput(cameraInput, (err) => {
console
.
log
(
'
Callback invoked to indicate that the CameraInput instance is added.
'
);
console
.
log
(
'
Callback invoked to indicate that the CameraInput instance is added.
'
);
});
});
//向会话中添加预览输入流
//
向会话中添加预览输入流
await
captureSession
.
addOutput
(
previewOutput
,
(
err
)
=>
{
await
captureSession
.
addOutput
(
previewOutput
,
(
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
Failed to add the PreviewOutput instance ${err.message}
'
);
console
.
error
(
'
Failed to add the PreviewOutput instance ${err.message}
'
);
...
@@ -265,7 +265,7 @@ await captureSession.addOutput(previewOutput, (err) => {
...
@@ -265,7 +265,7 @@ await captureSession.addOutput(previewOutput, (err) => {
console
.
log
(
'
Callback invoked to indicate that the PreviewOutput instance is added.
'
);
console
.
log
(
'
Callback invoked to indicate that the PreviewOutput instance is added.
'
);
});
});
//向会话中添加拍照输出流
//
向会话中添加拍照输出流
await
captureSession
.
addOutput
(
photoOutput
,
(
err
)
=>
{
await
captureSession
.
addOutput
(
photoOutput
,
(
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
Failed to add the PhotoOutput instance ${err.message}
'
);
console
.
error
(
'
Failed to add the PhotoOutput instance ${err.message}
'
);
...
@@ -274,7 +274,7 @@ await captureSession.addOutput(photoOutput, (err) => {
...
@@ -274,7 +274,7 @@ await captureSession.addOutput(photoOutput, (err) => {
console
.
log
(
'
Callback invoked to indicate that the PhotoOutput instance is added.
'
);
console
.
log
(
'
Callback invoked to indicate that the PhotoOutput instance is added.
'
);
});
});
//提交会话配置
//
提交会话配置
await
captureSession
.
commitConfig
((
err
)
=>
{
await
captureSession
.
commitConfig
((
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
Failed to commit the configuration. ${err.message}
'
);
console
.
error
(
'
Failed to commit the configuration. ${err.message}
'
);
...
@@ -283,7 +283,7 @@ await captureSession.commitConfig((err) => {
...
@@ -283,7 +283,7 @@ await captureSession.commitConfig((err) => {
console
.
log
(
'
Callback invoked to indicate the commit config success.
'
);
console
.
log
(
'
Callback invoked to indicate the commit config success.
'
);
});
});
//启动会话
//
启动会话
await
captureSession
.
start
().
then
(()
=>
{
await
captureSession
.
start
().
then
(()
=>
{
console
.
log
(
'
Promise returned to indicate the session start success.
'
);
console
.
log
(
'
Promise returned to indicate the session start success.
'
);
})
})
...
@@ -292,7 +292,7 @@ await captureSession.start().then(() => {
...
@@ -292,7 +292,7 @@ await captureSession.start().then(() => {
##### 切换会话
##### 切换会话
```
js
```
js
//停止当前会话
//
停止当前会话
await
captureSession
.
stop
((
err
)
=>
{
await
captureSession
.
stop
((
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
Failed to stop the session ${err.message}
'
);
console
.
error
(
'
Failed to stop the session ${err.message}
'
);
...
@@ -301,7 +301,7 @@ await captureSession.stop((err) => {
...
@@ -301,7 +301,7 @@ await captureSession.stop((err) => {
console
.
log
(
'
Callback invoked to indicate the session stop success.
'
);
console
.
log
(
'
Callback invoked to indicate the session stop success.
'
);
});
});
//开始配置会话
//
开始配置会话
await
captureSession
.
beginConfig
((
err
)
=>
{
await
captureSession
.
beginConfig
((
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
Failed to start the configuration. ${err.message}
'
);
console
.
error
(
'
Failed to start the configuration. ${err.message}
'
);
...
@@ -310,7 +310,7 @@ await captureSession.beginConfig((err) => {
...
@@ -310,7 +310,7 @@ await captureSession.beginConfig((err) => {
console
.
log
(
'
Callback invoked to indicate the begin config success.
'
);
console
.
log
(
'
Callback invoked to indicate the begin config success.
'
);
});
});
//从会话中移除拍照输出流
//
从会话中移除拍照输出流
await
captureSession
.
removeOutput
(
photoOutput
,
(
err
)
=>
{
await
captureSession
.
removeOutput
(
photoOutput
,
(
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
Failed to remove the PhotoOutput instance. ${err.message}
'
);
console
.
error
(
'
Failed to remove the PhotoOutput instance. ${err.message}
'
);
...
@@ -319,7 +319,7 @@ await captureSession.removeOutput(photoOutput, (err) => {
...
@@ -319,7 +319,7 @@ await captureSession.removeOutput(photoOutput, (err) => {
console
.
log
(
'
Callback invoked to indicate that the PhotoOutput instance is removed.
'
);
console
.
log
(
'
Callback invoked to indicate that the PhotoOutput instance is removed.
'
);
});
});
//向会话中添加录像输出流
//
向会话中添加录像输出流
await
captureSession
.
addOutput
(
videoOutput
,
(
err
)
=>
{
await
captureSession
.
addOutput
(
videoOutput
,
(
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
Failed to add the VideoOutput instance ${err.message}
'
);
console
.
error
(
'
Failed to add the VideoOutput instance ${err.message}
'
);
...
@@ -328,7 +328,7 @@ await captureSession.addOutput(videoOutput, (err) => {
...
@@ -328,7 +328,7 @@ await captureSession.addOutput(videoOutput, (err) => {
console
.
log
(
'
Callback invoked to indicate that the VideoOutput instance is added.
'
);
console
.
log
(
'
Callback invoked to indicate that the VideoOutput instance is added.
'
);
});
});
//提交会话配置
//
提交会话配置
await
captureSession
.
commitConfig
((
err
)
=>
{
await
captureSession
.
commitConfig
((
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
Failed to commit the configuration. ${err.message}
'
);
console
.
error
(
'
Failed to commit the configuration. ${err.message}
'
);
...
@@ -337,7 +337,7 @@ await captureSession.commitConfig((err) => {
...
@@ -337,7 +337,7 @@ await captureSession.commitConfig((err) => {
console
.
log
(
'
Callback invoked to indicate the commit config success.
'
);
console
.
log
(
'
Callback invoked to indicate the commit config success.
'
);
});
});
//启动会话
//
启动会话
await
captureSession
.
start
().
then
(()
=>
{
await
captureSession
.
start
().
then
(()
=>
{
console
.
log
(
'
Promise returned to indicate the session start success.
'
);
console
.
log
(
'
Promise returned to indicate the session start success.
'
);
})
})
...
@@ -347,10 +347,10 @@ await captureSession.start().then(() => {
...
@@ -347,10 +347,10 @@ await captureSession.start().then(() => {
```
js
```
js
let
settings
=
{
let
settings
=
{
quality
:
camera
.
QualityLevel
.
QUALITY_LEVEL_HIGH
,
//设置图片质量高
quality
:
camera
.
QualityLevel
.
QUALITY_LEVEL_HIGH
,
//
设置图片质量高
rotation
:
camera
.
ImageRotation
.
ROTATION_0
//设置图片旋转角度0
rotation
:
camera
.
ImageRotation
.
ROTATION_0
//
设置图片旋转角度0
}
}
//使用当前拍照设置进行拍照
//
使用当前拍照设置进行拍照
photoOutput
.
capture
(
settings
,
(
err
)
=>
{
photoOutput
.
capture
(
settings
,
(
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
Failed to capture the photo ${err.message}
'
);
console
.
error
(
'
Failed to capture the photo ${err.message}
'
);
...
@@ -363,7 +363,7 @@ photoOutput.capture(settings, (err) => {
...
@@ -363,7 +363,7 @@ photoOutput.capture(settings, (err) => {
#### 录像
#### 录像
```
js
```
js
//启动录像输出流
//
启动录像输出流
videoOutput
.
start
((
err
)
=>
{
videoOutput
.
start
((
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
Failed to start the video output ${err.message}
'
);
console
.
error
(
'
Failed to start the video output ${err.message}
'
);
...
@@ -372,17 +372,17 @@ videoOutput.start((err) => {
...
@@ -372,17 +372,17 @@ videoOutput.start((err) => {
console
.
log
(
'
Callback invoked to indicate the video output start success.
'
);
console
.
log
(
'
Callback invoked to indicate the video output start success.
'
);
});
});
//开始录像
//
开始录像
await
videoRecorder
.
start
().
then
(()
=>
{
await
videoRecorder
.
start
().
then
(()
=>
{
console
.
info
(
'
videoRecorder start success
'
);
console
.
info
(
'
videoRecorder start success
'
);
}
}
//停止录像
//
停止录像
await
videoRecorder
.
stop
().
then
(()
=>
{
await
videoRecorder
.
stop
().
then
(()
=>
{
console
.
info
(
'
stop success
'
);
console
.
info
(
'
stop success
'
);
}
}
//停止录像输出流
//
停止录像输出流
await
videoOutput
.
stop
((
err
)
=>
{
await
videoOutput
.
stop
((
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
Failed to stop the video output ${err.message}
'
);
console
.
error
(
'
Failed to stop the video output ${err.message}
'
);
...
@@ -395,7 +395,7 @@ await videoOutput.stop((err) => {
...
@@ -395,7 +395,7 @@ await videoOutput.stop((err) => {
#### 释放资源
#### 释放资源
```
js
```
js
//停止当前会话
//
停止当前会话
await
captureSession
.
stop
((
err
)
=>
{
await
captureSession
.
stop
((
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
Failed to stop the session ${err.message}
'
);
console
.
error
(
'
Failed to stop the session ${err.message}
'
);
...
@@ -403,7 +403,7 @@ await captureSession.stop((err) => {
...
@@ -403,7 +403,7 @@ await captureSession.stop((err) => {
}
}
console
.
log
(
'
Callback invoked to indicate the session stop success.
'
);
console
.
log
(
'
Callback invoked to indicate the session stop success.
'
);
});
});
//释放相机输入流
//
释放相机输入流
await
cameraInput
.
release
((
err
)
=>
{
await
cameraInput
.
release
((
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
Failed to release the CameraInput instance ${err.message}
'
);
console
.
error
(
'
Failed to release the CameraInput instance ${err.message}
'
);
...
@@ -411,7 +411,7 @@ await cameraInput.release((err) => {
...
@@ -411,7 +411,7 @@ await cameraInput.release((err) => {
}
}
console
.
log
(
'
Callback invoked to indicate that the CameraInput instance is released successfully.
'
);
console
.
log
(
'
Callback invoked to indicate that the CameraInput instance is released successfully.
'
);
});
});
//释放预览输出流
//
释放预览输出流
await
previewOutput
.
release
((
err
)
=>
{
await
previewOutput
.
release
((
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
Failed to release the PreviewOutput instance ${err.message}
'
);
console
.
error
(
'
Failed to release the PreviewOutput instance ${err.message}
'
);
...
@@ -419,7 +419,7 @@ await previewOutput.release((err) => {
...
@@ -419,7 +419,7 @@ await previewOutput.release((err) => {
}
}
console
.
log
(
'
Callback invoked to indicate that the PreviewOutput instance is released successfully.
'
);
console
.
log
(
'
Callback invoked to indicate that the PreviewOutput instance is released successfully.
'
);
});
});
//释放拍照输出流
//
释放拍照输出流
await
photoOutput
.
release
((
err
)
=>
{
await
photoOutput
.
release
((
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
Failed to release the PhotoOutput instance ${err.message}
'
);
console
.
error
(
'
Failed to release the PhotoOutput instance ${err.message}
'
);
...
@@ -427,7 +427,7 @@ await photoOutput.release((err) => {
...
@@ -427,7 +427,7 @@ await photoOutput.release((err) => {
}
}
console
.
log
(
'
Callback invoked to indicate that the PhotoOutput instance is released successfully.
'
);
console
.
log
(
'
Callback invoked to indicate that the PhotoOutput instance is released successfully.
'
);
});
});
//释放录像输出流
//
释放录像输出流
await
videoOutput
.
release
((
err
)
=>
{
await
videoOutput
.
release
((
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
Failed to release the VideoOutput instance ${err.message}
'
);
console
.
error
(
'
Failed to release the VideoOutput instance ${err.message}
'
);
...
@@ -435,7 +435,7 @@ await videoOutput.release((err) => {
...
@@ -435,7 +435,7 @@ await videoOutput.release((err) => {
}
}
console
.
log
(
'
Callback invoked to indicate that the VideoOutput instance is released successfully.
'
);
console
.
log
(
'
Callback invoked to indicate that the VideoOutput instance is released successfully.
'
);
});
});
//释放会话
//
释放会话
await
captureSession
.
release
((
err
)
=>
{
await
captureSession
.
release
((
err
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
Failed to release the CaptureSession instance ${err.message}
'
);
console
.
error
(
'
Failed to release the CaptureSession instance ${err.message}
'
);
...
@@ -449,24 +449,24 @@ await captureSession.release((err) => {
...
@@ -449,24 +449,24 @@ await captureSession.release((err) => {
预览画面显示需要获取SurfaceId
预览画面显示需要获取SurfaceId
```
js
```
js
mXComponentController
:
XComponentController
=
new
XComponentController
//创建XComponentController
mXComponentController
:
XComponentController
=
new
XComponentController
//
创建XComponentController
build
()
{
build
()
{
Flex
()
{
Flex
()
{
XComponent
({
//创建XComponent
XComponent
({
//
创建XComponent
id
:
''
,
id
:
''
,
type
:
'
surface
'
,
type
:
'
surface
'
,
libraryname
:
''
,
libraryname
:
''
,
controller
:
this
.
mXComponentController
controller
:
this
.
mXComponentController
})
})
.
onload
(()
=>
{
//设置onload回调
.
onload
(()
=>
{
//
设置onload回调
//设置Surface宽高(1920*1080)
//
设置Surface宽高(1920*1080)
this
.
mXComponentController
.
setXComponentSurfaceSize
({
surfaceWidth
:
1920
,
surfaceHeight
:
1080
})
this
.
mXComponentController
.
setXComponentSurfaceSize
({
surfaceWidth
:
1920
,
surfaceHeight
:
1080
})
//获取Surface ID
//
获取Surface ID
globalThis
.
surfaceId
=
mXComponentController
.
getXComponentSurfaceId
()
globalThis
.
surfaceId
=
mXComponentController
.
getXComponentSurfaceId
()
})
})
.
width
(
'
1920px
'
)
//设置XComponent宽度
.
width
(
'
1920px
'
)
//
设置XComponent宽度
.
height
(
'
1080px
'
)
//设置XComponent高度
.
height
(
'
1080px
'
)
//
设置XComponent高度
}
}
}
}
```
```
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录