Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
c14b44a6
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看板
提交
c14b44a6
编写于
9月 06, 2023
作者:
Z
zhangchao
1
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ArkTs整改
Signed-off-by:
N
zhangchao
<
zhangchao338@huawei.com
>
上级
72cd2a35
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
107 addition
and
98 deletion
+107
-98
zh-cn/application-dev/media/Readme-CN.md
zh-cn/application-dev/media/Readme-CN.md
+1
-1
zh-cn/application-dev/media/camera-dual-channel-preview.md
zh-cn/application-dev/media/camera-dual-channel-preview.md
+106
-97
未找到文件。
zh-cn/application-dev/media/Readme-CN.md
浏览文件 @
c14b44a6
...
...
@@ -63,7 +63,7 @@
-
[
拍照实现方案
](
camera-shooting-case.md
)
-
[
录像实现方案
](
camera-recording-case.md
)
-
[
使用人像模式拍照
](
camera-mode.md
)
-
[
双路预览
](
dual-channel-preview.md
)
-
[
双路预览
](
camera-
dual-channel-preview.md
)
-
[
性能提升方案(仅对系统应用开放)
](
camera-performance-improvement.md
)
-
图片
-
[
图片开发概述
](
image-overview.md
)
...
...
zh-cn/application-dev/media/camera-dual-channel-preview.md
浏览文件 @
c14b44a6
...
...
@@ -23,23 +23,25 @@
创建双路预览流的SurfaceId,除XComponent组件的SurfaceId外,还需要使用ImageReceiver组件创建生成的SurfaceId,需要使用image模块提供的接口。
```
j
s
```
t
s
import
image
from
'
@ohos.multimedia.image
'
;
```
2.
创建ImageReceiver组件Surface。
```
js
function
getImageReceiverSurfaceId
()
{
let
receiver
=
image
.
createImageReceiver
(
640
,
480
,
4
,
8
);
console
.
info
(
'
before ImageReceiver check
'
);
if
(
receiver
!==
undefined
)
{
console
.
info
(
'
ImageReceiver is ok
'
);
let
ImageReceiverSurfaceId
=
receiver
.
getReceivingSurfaceId
();
console
.
info
(
'
ImageReceived id:
'
+
JSON
.
stringify
(
ImageReceiverSurfaceId
));
}
else
{
console
.
info
(
'
ImageReceiver is not ok
'
);
}
```
ts
async
function
getImageReceiverSurfaceId
():
Promise
<
string
>
{
let
receiver
:
image
.
ImageReceiver
=
image
.
createImageReceiver
(
640
,
480
,
4
,
8
);
console
.
info
(
'
before ImageReceiver check
'
);
let
ImageReceiverSurfaceId
:
string
;
if
(
receiver
!==
undefined
)
{
console
.
info
(
'
ImageReceiver is ok
'
);
let
ImageReceiverSurfaceId
:
string
=
await
receiver
.
getReceivingSurfaceId
();
console
.
info
(
`ImageReceived id:
${
ImageReceiverSurfaceId
}
`
);
}
else
{
console
.
info
(
'
ImageReceiver is not ok
'
);
}
return
ImageReceiverSurfaceId
;
}
```
...
...
@@ -47,27 +49,33 @@
可参考
[
相机预览指导文档
](
camera-preview.md
)
。
```
js
```
ets
//xxx.ets
// 创建XComponentController
mXComponentController
:
XComponentController
=
new
XComponentController
;
build
()
{
@Component
struct XComponentPage {
// 创建XComponentController
mXComponentController: XComponentController = new XComponentController;
build() {
Flex() {
// 创建XComponent
XComponent
({
id
:
''
,
type
:
'
surface
'
,
libraryname
:
''
,
controller
:
this
.
mXComponentController
})
.
onLoad
(()
=>
{
// 设置Surface宽高(1920*1080),预览尺寸设置参考前面 previewProfilesArray 获取的当前设备所支持的预览分辨率大小去设置
this
.
mXComponentController
.
setXComponentSurfaceSize
({
surfaceWidth
:
1920
,
surfaceHeight
:
1080
});
// 获取Surface ID
globalThis
.
XComponentsurfaceId
=
this
.
mXComponentController
.
getXComponentSurfaceId
();
// 创建XComponent
XComponent({
id: '',
type: 'surface',
libraryname: '',
controller: this.mXComponentController
})
.onLoad(() => {
// 设置Surface宽高(1920*1080),预览尺寸设置参考前面 previewProfilesArray 获取的当前设备所支持的预览分辨率大小去设置
this.mXComponentController.setXComponentSurfaceSize({surfaceWidth:1920,surfaceHeight:1080});
// 获取Surface ID
let surfaceId: string
= this.mXComponentController.getXComponentSurfaceId();
})
.
width
(
'
1
00%
'
)
.
height
(
'
10
0%
'
)
.width('1
920px')
.height('10
80px')
}
}
}
```
...
...
@@ -75,83 +83,84 @@
将步骤2、3生成的两路SurfaceId通过createPreviewOutput方法传递到相机服务,创建两路预览流,其余流程按照正常预览流程开发。
```
js
let
cameraManager
=
camera
.
getCameraManager
(
globalThis
.
abilityContext
);
let
CamerasDevices
=
cameraManager
.
getSupportedCameras
();
// 获取支持的相机设备对象
// 正常写法通过下面方式获取实际情况下的profile对象
// let profiles = await this.cameraManager.getSupportedOutputCapability(CamerasDevices[cameraDeviceIndex]); // 获取对应相机设备profiles
// let previewProfiles = profiles.previewProfiles;
// 预览流1
let
previewProfilesObj
:
camera
.
Profile
;
previewProfilesObj
.
size
.
width
=
640
;
previewProfilesObj
.
size
.
height
=
480
;
previewProfilesObj
.
format
=
3
;
// 预览流2
let
previewProfilesObj2
:
camera
.
Profile
;
previewProfilesObj2
.
size
.
width
=
640
;
previewProfilesObj2
.
size
.
height
=
480
;
previewProfilesObj2
.
format
=
3
;
// 创建 预览流1 输出对象
let
previewOutput
=
cameraManager
.
createPreviewOutput
(
previewProfilesObj
,
XComponentsurfaceId
);
// 创建 预览流2 输出对象
let
imageReceiverSurfaceId
:
string
=
await
this
.
mReceiver
.
getReceivingSurfaceId
();
let
previewOutput2
=
cameraManager
.
createPreviewOutput
(
previewProfilesObj2
,
imageReceiverSurfaceId
);
// 创建cameraInput输出对象
let
cameraInput
=
cameraManager
.
createCameraInput
(
CamerasDevices
[
cameraDeviceIndex
]);
// 打开相机
await
cameraInput
.
open
();
// 会话流程
let
captureSession
=
await
cameraManager
.
createCaptureSession
();
// 开始配置会话
captureSession
.
beginConfig
();
// 把CameraInput加入到会话
captureSession
.
addInput
(
cameraInput
);
// 把 预览流1 加入到会话
captureSession
.
addOutput
(
previewOutput
)
// 把 预览流2 加入到会话
captureSession
.
addOutput
(
previewOutput2
);
// 提交配置信息
await
captureSession
.
commitConfig
();
// 会话开始
await
captureSession
.
start
();
```
ts
import
camera
from
'
@ohos.multimedia.camera
'
;
async
function
createDualChannelPreview
(
cameraManager
:
camera
.
CameraManager
,
XComponentSurfaceId
:
string
,
receiver
:
image
.
ImageReceiver
):
Promise
<
void
>
{
let
camerasDevices
:
Array
<
camera
.
CameraDevice
>
=
cameraManager
.
getSupportedCameras
();
// 获取支持的相机设备对象
// 获取profile对象
let
profiles
:
camera
.
CameraOutputCapability
=
await
this
.
cameraManager
.
getSupportedOutputCapability
(
camerasDevices
[
0
]);
// 获取对应相机设备profiles
let
previewProfiles
:
Array
<
camera
.
Profile
>
=
profiles
.
previewProfiles
;
// 预览流1
let
previewProfilesObj
:
camera
.
Profile
=
previewProfiles
[
0
];
// 预览流2
let
previewProfilesObj2
:
camera
.
Profile
=
previewProfiles
[
0
];
// 创建 预览流1 输出对象
let
previewOutput
:
camera
.
PreviewOutput
=
cameraManager
.
createPreviewOutput
(
previewProfilesObj
,
XComponentSurfaceId
);
// 创建 预览流2 输出对象
let
imageReceiverSurfaceId
:
string
=
await
receiver
.
getReceivingSurfaceId
();
let
previewOutput2
:
camera
.
PreviewOutput
=
cameraManager
.
createPreviewOutput
(
previewProfilesObj2
,
imageReceiverSurfaceId
);
// 创建cameraInput对象
let
cameraInput
:
camera
.
CameraInput
=
cameraManager
.
createCameraInput
(
camerasDevices
[
0
]);
// 打开相机
await
cameraInput
.
open
();
// 会话流程
let
captureSession
:
camera
.
CaptureSession
=
cameraManager
.
createCaptureSession
();
// 开始配置会话
captureSession
.
beginConfig
();
// 把CameraInput加入到会话
captureSession
.
addInput
(
cameraInput
);
// 把 预览流1 加入到会话
captureSession
.
addOutput
(
previewOutput
)
// 把 预览流2 加入到会话
captureSession
.
addOutput
(
previewOutput2
);
// 提交配置信息
await
captureSession
.
commitConfig
();
// 会话开始
await
captureSession
.
start
();
}
```
5.
通过ImageReceiver实时获取预览图像。
通过ImageReceiver组件中imageArrival事件监听获取底层返回的图像数据,详细的API说明请参考
[
Image API参考
](
../reference/apis/js-apis-image.md
)
。
```
js
this
.
receiver
.
on
(
'
imageArrival
'
,
()
=>
{
this
.
receiver
.
readNextImage
((
err
,
nextImage
:
image
.
Image
)
=>
{
if
(
err
||
nextImage
===
undefined
)
{
return
;
}
nextImage
.
getComponent
(
image
.
ComponentType
.
JPEG
,
(
errMsg
,
img
)
=>
{
if
(
errMsg
||
img
===
undefined
)
{
return
;
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
function
onImageArrival
(
receiver
:
image
.
ImageReceiver
):
void
{
receiver
.
on
(
'
imageArrival
'
,
()
=>
{
receiver
.
readNextImage
((
err
:
BusinessError
,
nextImage
:
image
.
Image
)
=>
{
if
(
err
||
nextImage
===
undefined
)
{
return
;
}
nextImage
.
getComponent
(
image
.
ComponentType
.
JPEG
,
(
err
:
BusinessError
,
imgComponent
:
image
.
Component
)
=>
{
if
(
err
||
imgComponent
===
undefined
)
{
return
;
}
let
buffer
;
if
(
img
.
byteBuffer
)
{
buffer
=
img
.
byteBuffer
;
let
buffer
:
ArrayBuffer
;
if
(
img
Component
.
byteBuffer
)
{
buffer
=
imgComponent
.
byteBuffer
;
}
else
{
return
;
return
;
}
// do something...;
})
})
})
})
})
}
```
Miykael_xxm
🚴
@xiongjiamu
mentioned in commit
48b5c7d7
·
9月 07, 2023
mentioned in commit
48b5c7d7
mentioned in commit 48b5c7d76bebb40340b1e02104b381b5c567ff86
开关提交列表
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录