提交 48b5c7d7 编写于 作者: Z zhangchao 提交者: 章超123
上级 4c552445
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
- [拍照实现方案](camera-shooting-case.md) - [拍照实现方案](camera-shooting-case.md)
- [录像实现方案](camera-recording-case.md) - [录像实现方案](camera-recording-case.md)
- [使用人像模式拍照](camera-mode.md) - [使用人像模式拍照](camera-mode.md)
- [双路预览](dual-channel-preview.md) - [双路预览](camera-dual-channel-preview.md)
- [性能提升方案(仅对系统应用开放)](camera-performance-improvement.md) - [性能提升方案(仅对系统应用开放)](camera-performance-improvement.md)
- 图片 - 图片
- [图片开发概述](image-overview.md) - [图片开发概述](image-overview.md)
......
...@@ -23,23 +23,25 @@ ...@@ -23,23 +23,25 @@
创建双路预览流的SurfaceId,除XComponent组件的SurfaceId外,还需要使用ImageReceiver组件创建生成的SurfaceId,需要使用image模块提供的接口。 创建双路预览流的SurfaceId,除XComponent组件的SurfaceId外,还需要使用ImageReceiver组件创建生成的SurfaceId,需要使用image模块提供的接口。
```js ```ts
import image from '@ohos.multimedia.image'; import image from '@ohos.multimedia.image';
``` ```
2. 创建ImageReceiver组件Surface。 2. 创建ImageReceiver组件Surface。
```js ```ts
function getImageReceiverSurfaceId() { async function getImageReceiverSurfaceId(): Promise<string> {
let receiver = image.createImageReceiver(640, 480, 4, 8); let receiver: image.ImageReceiver = image.createImageReceiver(640, 480, 4, 8);
console.info('before ImageReceiver check'); console.info('before ImageReceiver check');
if (receiver !== undefined) { let ImageReceiverSurfaceId: string;
console.info('ImageReceiver is ok'); if (receiver !== undefined) {
let ImageReceiverSurfaceId = receiver.getReceivingSurfaceId(); console.info('ImageReceiver is ok');
console.info('ImageReceived id: ' + JSON.stringify(ImageReceiverSurfaceId)); let ImageReceiverSurfaceId: string = await receiver.getReceivingSurfaceId();
} else { console.info(`ImageReceived id: ${ImageReceiverSurfaceId}`);
console.info('ImageReceiver is not ok'); } else {
} console.info('ImageReceiver is not ok');
}
return ImageReceiverSurfaceId;
} }
``` ```
...@@ -47,27 +49,33 @@ ...@@ -47,27 +49,33 @@
可参考[相机预览指导文档](camera-preview.md) 可参考[相机预览指导文档](camera-preview.md)
```js ```ets
//xxx.ets
// 创建XComponentController // 创建XComponentController
mXComponentController: XComponentController = new XComponentController; @Component
build() { struct XComponentPage {
// 创建XComponentController
mXComponentController: XComponentController = new XComponentController;
build() {
Flex() { Flex() {
// 创建XComponent // 创建XComponent
XComponent({ XComponent({
id: '', id: '',
type: 'surface', type: 'surface',
libraryname: '', libraryname: '',
controller: this.mXComponentController controller: this.mXComponentController
}) })
.onLoad(() => { .onLoad(() => {
// 设置Surface宽高(1920*1080),预览尺寸设置参考前面 previewProfilesArray 获取的当前设备所支持的预览分辨率大小去设置 // 设置Surface宽高(1920*1080),预览尺寸设置参考前面 previewProfilesArray 获取的当前设备所支持的预览分辨率大小去设置
this.mXComponentController.setXComponentSurfaceSize({surfaceWidth:1920,surfaceHeight:1080}); this.mXComponentController.setXComponentSurfaceSize({surfaceWidth:1920,surfaceHeight:1080});
// 获取Surface ID // 获取Surface ID
globalThis.XComponentsurfaceId = this.mXComponentController.getXComponentSurfaceId(); let surfaceId: string = this.mXComponentController.getXComponentSurfaceId();
}) })
.width('100%') .width('1920px')
.height('100%') .height('1080px')
} }
}
} }
``` ```
...@@ -75,83 +83,84 @@ ...@@ -75,83 +83,84 @@
将步骤2、3生成的两路SurfaceId通过createPreviewOutput方法传递到相机服务,创建两路预览流,其余流程按照正常预览流程开发。 将步骤2、3生成的两路SurfaceId通过createPreviewOutput方法传递到相机服务,创建两路预览流,其余流程按照正常预览流程开发。
```js ```ts
let cameraManager = camera.getCameraManager(globalThis.abilityContext); import camera from '@ohos.multimedia.camera';
let CamerasDevices = cameraManager.getSupportedCameras(); // 获取支持的相机设备对象
async function createDualChannelPreview(cameraManager: camera.CameraManager, XComponentSurfaceId: string, receiver: image.ImageReceiver): Promise<void> {
// 正常写法通过下面方式获取实际情况下的profile对象 let camerasDevices: Array<camera.CameraDevice> = cameraManager.getSupportedCameras(); // 获取支持的相机设备对象
// let profiles = await this.cameraManager.getSupportedOutputCapability(CamerasDevices[cameraDeviceIndex]); // 获取对应相机设备profiles
// let previewProfiles = profiles.previewProfiles; // 获取profile对象
let profiles: camera.CameraOutputCapability = await this.cameraManager.getSupportedOutputCapability(camerasDevices[0]); // 获取对应相机设备profiles
// 预览流1 let previewProfiles: Array<camera.Profile> = profiles.previewProfiles;
let previewProfilesObj: camera.Profile;
previewProfilesObj.size.width = 640; // 预览流1
previewProfilesObj.size.height = 480; let previewProfilesObj: camera.Profile = previewProfiles[0];
previewProfilesObj.format = 3;
// 预览流2
// 预览流2 let previewProfilesObj2: camera.Profile = previewProfiles[0];
let previewProfilesObj2: camera.Profile;
previewProfilesObj2.size.width = 640; // 创建 预览流1 输出对象
previewProfilesObj2.size.height = 480; let previewOutput: camera.PreviewOutput = cameraManager.createPreviewOutput(previewProfilesObj, XComponentSurfaceId);
previewProfilesObj2.format = 3;
// 创建 预览流2 输出对象
// 创建 预览流1 输出对象 let imageReceiverSurfaceId: string = await receiver.getReceivingSurfaceId();
let previewOutput = cameraManager.createPreviewOutput(previewProfilesObj, XComponentsurfaceId); let previewOutput2: camera.PreviewOutput = cameraManager.createPreviewOutput(previewProfilesObj2, imageReceiverSurfaceId);
// 创建 预览流2 输出对象 // 创建cameraInput对象
let imageReceiverSurfaceId: string = await this.mReceiver.getReceivingSurfaceId(); let cameraInput: camera.CameraInput = cameraManager.createCameraInput(camerasDevices[0]);
let previewOutput2 = cameraManager.createPreviewOutput(previewProfilesObj2, imageReceiverSurfaceId);
// 打开相机
// 创建cameraInput输出对象 await cameraInput.open();
let cameraInput = cameraManager.createCameraInput(CamerasDevices[cameraDeviceIndex]);
// 会话流程
// 打开相机 let captureSession: camera.CaptureSession = cameraManager.createCaptureSession();
await cameraInput.open();
// 开始配置会话
// 会话流程 captureSession.beginConfig();
let captureSession = await cameraManager.createCaptureSession();
// 把CameraInput加入到会话
// 开始配置会话 captureSession.addInput(cameraInput);
captureSession.beginConfig();
// 把 预览流1 加入到会话
// 把CameraInput加入到会话 captureSession.addOutput(previewOutput)
captureSession.addInput(cameraInput);
// 把 预览流2 加入到会话
// 把 预览流1 加入到会话 captureSession.addOutput(previewOutput2);
captureSession.addOutput(previewOutput)
// 提交配置信息
// 把 预览流2 加入到会话 await captureSession.commitConfig();
captureSession.addOutput(previewOutput2);
// 会话开始
// 提交配置信息 await captureSession.start();
await captureSession.commitConfig(); }
// 会话开始
await captureSession.start();
``` ```
5. 通过ImageReceiver实时获取预览图像。 5. 通过ImageReceiver实时获取预览图像。
通过ImageReceiver组件中imageArrival事件监听获取底层返回的图像数据,详细的API说明请参考[Image API参考](../reference/apis/js-apis-image.md) 通过ImageReceiver组件中imageArrival事件监听获取底层返回的图像数据,详细的API说明请参考[Image API参考](../reference/apis/js-apis-image.md)
```js ```ts
this.receiver.on('imageArrival', () => { import { BusinessError } from '@ohos.base';
this.receiver.readNextImage((err, nextImage: image.Image) => {
if (err || nextImage === undefined) { function onImageArrival(receiver: image.ImageReceiver): void {
return; receiver.on('imageArrival', () => {
} receiver.readNextImage((err: BusinessError, nextImage: image.Image) => {
nextImage.getComponent(image.ComponentType.JPEG, (errMsg, img) => { if (err || nextImage === undefined) {
if (errMsg || img === undefined) { return;
return; }
nextImage.getComponent(image.ComponentType.JPEG, (err: BusinessError, imgComponent: image.Component) => {
if (err || imgComponent === undefined) {
return;
} }
let buffer; let buffer: ArrayBuffer;
if (img.byteBuffer) { if (imgComponent.byteBuffer) {
buffer = img.byteBuffer; buffer = imgComponent.byteBuffer;
} else { } else {
return; return;
} }
// do something...; // do something...;
}) })
}) })
}) })
}
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册