未验证 提交 09e25b96 编写于 作者: O openharmony_ci 提交者: Gitee

!11190 Correction of errors in camera development documents

Merge pull request !11190 from 马利/master
...@@ -59,7 +59,8 @@ import image from '@ohos.multimedia.image' ...@@ -59,7 +59,8 @@ import image from '@ohos.multimedia.image'
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
// 创建CameraManager对象 // 创建CameraManager对象
let cameraManager = await camera.getCameraManager(null) context: any = getContext(this)
let cameraManager = await camera.getCameraManager(this.context)
if (!cameraManager) { if (!cameraManager) {
console.error('Failed to get the CameraManager instance'); console.error('Failed to get the CameraManager instance');
} }
...@@ -78,14 +79,10 @@ for (let index = 0; index < cameraArray.length; index++) { ...@@ -78,14 +79,10 @@ for (let index = 0; index < cameraArray.length; index++) {
} }
// 创建相机输入流 // 创建相机输入流
let cameraInput let cameraInput = await cameraManager.createCameraInput(cameraArray[0])
await cameraManager.createCameraInput(cameraArray[0].cameraId).then((input) => {
console.log('Promise returned with the CameraInput instance');
cameraInput = input
})
// 获取相机设备支持的输出流能力 // 获取相机设备支持的输出流能力
let cameraOutputCap = await camera.getSupportedOutputCapability(cameraInput); let cameraOutputCap = await cameraManager.getSupportedOutputCapability(cameraArray[0]);
if (!cameraOutputCap) { if (!cameraOutputCap) {
console.error("outputCapability outputCapability == null || undefined") console.error("outputCapability outputCapability == null || undefined")
} else { } else {
...@@ -112,8 +109,8 @@ if (!metadataObjectTypesArray) { ...@@ -112,8 +109,8 @@ if (!metadataObjectTypesArray) {
console.error("createOutput metadataObjectTypesArray == null || undefined") console.error("createOutput metadataObjectTypesArray == null || undefined")
} }
// 创建预览输出流 // 创建预览输出流,其中参数 surfaceId 参考下面 XComponent 组件,预览流为XComponent组件提供的surface
let previewOutput = await camera.createPreviewOutput(previewProfilesArray[0], surfaceId) let previewOutput = await cameraManager.createPreviewOutput(previewProfilesArray[0], surfaceId)
if (!previewOutput) { if (!previewOutput) {
console.error("Failed to create the PreviewOutput instance.") console.error("Failed to create the PreviewOutput instance.")
} }
...@@ -123,7 +120,7 @@ let imageReceiver = await image.createImageReceiver(1920, 1080, 4, 8) ...@@ -123,7 +120,7 @@ let imageReceiver = await image.createImageReceiver(1920, 1080, 4, 8)
// 获取照片显示SurfaceId // 获取照片显示SurfaceId
let photoSurfaceId = await imageReceiver.getReceivingSurfaceId() let photoSurfaceId = await imageReceiver.getReceivingSurfaceId()
// 创建拍照输出流 // 创建拍照输出流
let photoOutput = await this.camera.createPhotoOutput(photoProfilesArray[0], photoSurfaceId) let photoOutput = await cameraManager.createPhotoOutput(photoProfilesArray[0], photoSurfaceId)
if (!photoOutput) { if (!photoOutput) {
console.error('Failed to create the PhotoOutput instance.'); console.error('Failed to create the PhotoOutput instance.');
return; return;
...@@ -155,20 +152,21 @@ let videoConfig = { ...@@ -155,20 +152,21 @@ let videoConfig = {
// 创建录像输出流 // 创建录像输出流
let videoRecorder let videoRecorder
await media.createVideoRecorder().then((recorder) => { media.createVideoRecorder().then((recorder) => {
console.log('createVideoRecorder called') console.log('createVideoRecorder called')
videoRecorder = recorder videoRecorder = recorder
}) })
// 设置视频录制的参数 // 设置视频录制的参数
await videoRecorder.prepare(videoConfig) videoRecorder.prepare(videoConfig)
//获取录像SurfaceId //获取录像SurfaceId
await videoRecorder.getInputSurface().then((id) => { let videoSurfaceId
videoRecorder.getInputSurface().then((id) => {
console.log('getInputSurface called') console.log('getInputSurface called')
videoSurfaceId = id videoSurfaceId = id
}) })
// 创建VideoOutput对象 // 创建VideoOutput对象
let videoOutput = camera.createVideoOutput(videoProfilesArray[0], videoSurfaceId) let videoOutput = await cameraManager.createVideoOutput(videoProfilesArray[0], videoSurfaceId)
if (!videoOutput) { if (!videoOutput) {
console.error('Failed to create the videoOutput instance.'); console.error('Failed to create the videoOutput instance.');
return; return;
...@@ -205,11 +203,11 @@ build() { ...@@ -205,11 +203,11 @@ build() {
```typescript ```typescript
function getImageReceiverSurfaceId() { function getImageReceiverSurfaceId() {
var receiver = image.createImageReceiver(640, 480, 4, 8) let receiver = image.createImageReceiver(640, 480, 4, 8)
console.log(TAG + 'before ImageReceiver check') console.log(TAG + 'before ImageReceiver check')
if (receiver !== undefined) { if (receiver !== undefined) {
console.log('ImageReceiver is ok') console.log('ImageReceiver is ok')
surfaceId1 = await receiver.getReceivingSurfaceId() surfaceId1 = receiver.getReceivingSurfaceId()
console.log('ImageReceived id: ' + JSON.stringify(surfaceId1)) console.log('ImageReceived id: ' + JSON.stringify(surfaceId1))
} else { } else {
console.log('ImageReceiver is not ok') console.log('ImageReceiver is not ok')
...@@ -399,17 +397,17 @@ videoOutput.start(async (err) => { ...@@ -399,17 +397,17 @@ videoOutput.start(async (err) => {
}); });
// 开始录像 // 开始录像
await videoRecorder.start().then(() => { videoRecorder.start().then(() => {
console.info('videoRecorder start success'); console.info('videoRecorder start success');
} }
// 停止录像 // 停止录像
await videoRecorder.stop().then(() => { videoRecorder.stop().then(() => {
console.info('stop success'); console.info('stop success');
} }
// 停止录像输出流 // 停止录像输出流
await videoOutput.stop((err) => { 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}');
return; return;
...@@ -424,22 +422,22 @@ await videoOutput.stop((err) => { ...@@ -424,22 +422,22 @@ await videoOutput.stop((err) => {
```typescript ```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 captureSession = null
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册