提交 1473cb4a 编写于 作者: G Gloria

Update docs against 10658+10945+11014+11190

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 d6eada90
...@@ -2,7 +2,13 @@ ...@@ -2,7 +2,13 @@
## When to Use ## When to Use
You can use the camera module to develop basic camera functions, including previewing, photographing, and video recording. With the APIs provided by the **Camera** module, you can access and operate camera devices and develop new functions. Common operations include preview, photographing, and video recording. You can also implement flash control, exposure time control, focus mode control, zooming control, and many others.
Before calling camera APIs, be familiar with the following concepts:
- **Static camera capabilities**: A series of parameters used to describe inherent capabilities of a camera, such as orientation and supported resolution.
- **Physical camera**: An independent camera device. The physical camera ID is a string that uniquely identifies a physical camera.
- **Asynchronous operation**: To prevent the UI thread from being blocked, most **Camera** calls are asynchronous. Each API provides the callback and promise functions.
## How to Develop ## How to Develop
...@@ -12,276 +18,253 @@ For details about the APIs, see [Camera Management](../reference/apis/js-apis-ca ...@@ -12,276 +18,253 @@ For details about the APIs, see [Camera Management](../reference/apis/js-apis-ca
### Full-Process Scenario ### Full-Process Scenario
The full process includes creating an instance, setting parameters, managing sessions, taking photos, recording videos, and releasing resources. The full process includes applying for permissions, creating an instance, setting parameters, managing sessions, taking photos, recording videos, and releasing resources.
#### Applying for Permissions
You must apply for the permission for your application to access the camera device and other functions. The following table lists camera-related permissions.
The method for creating an XComponent is also provided. For details, see [XComponent Creation](#xcomponent-creation). | Permission| Attribute Value |
| -------- | ------------------------------ |
| Camera| ohos.permission.CAMERA |
| Call recording| ohos.permission.MICROPHONE |
| Storage| ohos.permission.WRITE_MEDIA |
| Read| ohos.permission.READ_MEDIA |
| Location| ohos.permission.MEDIA_LOCATION |
For details about the APIs used to save images, see [Image Processing](../reference/apis/js-apis-image.md). The code snippet is as follows:
```typescript
const PERMISSIONS: Array<string> = [
'ohos.permission.CAMERA',
'ohos.permission.MICROPHONE',
'ohos.permission.MEDIA_LOCATION',
'ohos.permission.READ_MEDIA',
'ohos.permission.WRITE_MEDIA'
]
function applyPermission() {
console.info('[permission] get permission');
globalThis.abilityContext.requestPermissionFromUser(PERMISSIONS)
}
```
#### Creating an Instance #### Creating an Instance
```js You must create an independent **CameraManager** instance before performing camera operations. If this operation fails, the camera may be occupied or unusable. If the camera is occupied, wait until it is released. You can call **getSupportedCameras()** to obtain the list of cameras supported by the current device. The list stores all camera IDs of the current device. If the list is not empty, each ID in the list can be used to create an independent camera instance. If the list is empty, no camera is available for the current device and subsequent operations cannot be performed. The camera has preview, shooting, video recording, and metadata streams. You can use **getSupportedOutputCapability()** to obtain the output stream capabilities of the camera and configure them in the **profile** field in **CameraOutputCapability**. The procedure for creating a **CameraManager** instance is as follows:
```typescript
import camera from '@ohos.multimedia.camera' import camera from '@ohos.multimedia.camera'
import image from '@ohos.multimedia.image' import image from '@ohos.multimedia.image'
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
import featureAbility from '@ohos.ability.featureAbility'
// Create a CameraManager object. // Create a CameraManager object.
let cameraManager context: any = getContext(this)
await camera.getCameraManager(globalThis.Context, (err, manager) => { let cameraManager = await camera.getCameraManager(this.context)
if (err) { if (!cameraManager) {
console.error('Failed to get the CameraManager instance ${err.message}'); console.error('Failed to get the CameraManager instance');
return; }
}
console.log('Callback returned with the CameraManager instance');
cameraManager = manager
})
// Register a callback to listen for camera status changes and obtain the updated camera status information.
cameraManager.on('cameraStatus', (cameraStatusInfo) => {
console.log('camera : ' + cameraStatusInfo.camera.cameraId);
console.log('status: ' + cameraStatusInfo.status);
})
// Obtain the camera list. // Obtain the camera list.
let cameraArray let cameraArray = await cameraManager.getSupportedCameras()
await cameraManager.getCameras((err, cameras) => { if (!cameraArray) {
if (err) { console.error('Failed to get the cameras');
console.error('Failed to get the cameras. ${err.message}'); }
return;
}
console.log('Callback returned with an array of supported cameras: ' + cameras.length);
cameraArray = cameras
})
for(let cameraIndex = 0; cameraIndex < cameraArray.length; cameraIndex++) { for (let index = 0; index < cameraArray.length; index++) {
console.log('cameraId : ' + cameraArray[cameraIndex].cameraId) // Obtain the camera ID. console.log('cameraId : ' + cameraArray[index].cameraId) // Obtain the camera ID.
console.log('cameraPosition : ' + cameraArray[cameraIndex].cameraPosition) // Obtain the camera position. console.log('cameraPosition : ' + cameraArray[index].cameraPosition) // Obtain the camera position.
console.log('cameraType : ' + cameraArray[cameraIndex].cameraType) // Obtain the camera type. console.log('cameraType : ' + cameraArray[index].cameraType) // Obtain the camera type.
console.log('connectionType : ' + cameraArray[cameraIndex].connectionType) // Obtain the camera connection type. console.log('connectionType : ' + cameraArray[index].connectionType) // Obtain the camera connection type.
} }
// Create a camera input stream. // Create a camera input stream.
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'); // Obtain the output stream capabilities supported by the camera.
cameraInput = input let cameraOutputCap = await cameraManager.getSupportedOutputCapability(cameraArray[0]);
}) if (!cameraOutputCap) {
console.error("outputCapability outputCapability == null || undefined")
} else {
console.info("outputCapability: " + JSON.stringify(cameraOutputCap));
}
// Create a preview output stream. let previewProfilesArray = cameraOutputCap.GetPreviewProfiles();
let previewOutput if (!previewProfilesArray) {
camera.createPreviewOutput((globalThis.surfaceId), (err, output) => { console.error("createOutput previewProfilesArray == null || undefined")
if (err) { }
console.error('Failed to create the PreviewOutput instance. ${err.message}');
return; let photoProfilesArray = cameraOutputCap.GetPhotoProfiles();
} if (!photoProfilesArray) {
console.log('Callback returned with previewOutput instance'); console.error("createOutput photoProfilesArray == null || undefined")
previewOutput = output }
});
let videoProfilesArray = cameraOutputCap.GetVideoProfiles();
if (!videoProfilesArray) {
console.error("createOutput videoProfilesArray == null || undefined")
}
// Create an ImageReceiver object and set image parameters. let metadataObjectTypesArray = cameraOutputCap.GetSupportedMetadataObjectType();
if (!metadataObjectTypesArray) {
console.error("createOutput metadataObjectTypesArray == null || undefined")
}
// Create a preview stream. For details about the surfaceId parameter, see the XComponent section. The preview stream is the surface provided by the XComponent.
let previewOutput = await cameraManager.createPreviewOutput(previewProfilesArray[0], surfaceId)
if (!previewOutput) {
console.error("Failed to create the PreviewOutput instance.")
}
// Create an ImageReceiver object and set photo parameters. The resolution is set based on the photographing resolutions supported by the current device, which are obtained by photoProfilesArray.
let imageReceiver = await image.createImageReceiver(1920, 1080, 4, 8) let imageReceiver = await image.createImageReceiver(1920, 1080, 4, 8)
// Obtain the surface ID for displaying the photos. // Obtain the surface ID for displaying the photos.
let photoSurfaceId = await imageReceiver.getReceivingSurfaceId() let photoSurfaceId = await imageReceiver.getReceivingSurfaceId()
// Create a photographing output stream. // Create a photographing output stream.
let photoOutput let photoOutput = await cameraManager.createPhotoOutput(photoProfilesArray[0], photoSurfaceId)
camera.createPhotoOutput((photoSurfaceId), (err, output) => { if (!photoOutput) {
if (err) { console.error('Failed to create the PhotoOutput instance.');
console.error('Failed to create the PhotoOutput instance. ${err.message}');
return; return;
} }
console.log('Callback returned with the PhotoOutput instance.');
photoOutput = output
});
// Define video recording parameters. // Define video recording parameters.
let videoProfile = {
audioBitrate : 48000,
audioChannels : 2,
audioCodec : 'audio/mp4a-latm',
audioSampleRate : 48000,
fileFormat : 'mp4',
videoBitrate : 48000,
videoCodec : 'video/mp4v-es',
videoFrameWidth : 640,
videoFrameHeight : 480,
videoFrameRate : 30
}
let videoConfig = { let videoConfig = {
audioSourceType : 1, audioSourceType: 1,
videoSourceType : 0, videoSourceType: 1,
profile : videoProfile, profile: {
url : 'file:///data/media/01.mp4', audioBitrate: 48000,
orientationHint : 0, audioChannels: 2,
location : { latitude : 30, longitude : 130 }, audioCodec: 'audio/mp4v-es',
audioSampleRate: 48000,
durationTime: 1000,
fileFormat: 'mp4',
videoBitrate: 48000,
videoCodec: 'video/mp4v-es',
videoFrameWidth: 640,
videoFrameHeight: 480,
videoFrameRate: 30
},
url: 'file:///data/media/01.mp4',
orientationHint: 0,
maxSize: 100,
maxDuration: 500,
rotation: 0
} }
// Create a video recording output stream. // Create a video recording output stream.
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
}) })
// Set video recording parameters. // Set video recording parameters.
await videoRecorder.prepare(videoConfig) videoRecorder.prepare(videoConfig)
// Obtain the surface ID for video recording. // Obtain the surface ID for video recording.
await videoRecorder.getInputSurface().then((id) => { let videoSurfaceId
videoRecorder.getInputSurface().then((id) => {
console.log('getInputSurface called') console.log('getInputSurface called')
videoSurfaceId = id videoSurfaceId = id
}) })
```
For details about how to create a video recorder, see [Video Recording Development](./video-recorder.md).
```js
// Create a VideoOutput object. // Create a VideoOutput object.
let videoOutput let videoOutput = await cameraManager.createVideoOutput(videoProfilesArray[0], videoSurfaceId)
camera.createVideoOutput((surfaceId), (err, output) => { if (!videoOutput) {
if (err) { console.error('Failed to create the videoOutput instance.');
console.error('Failed to create the VideoOutput instance. ${err.message}');
return; return;
} }
console.log('Callback returned with the VideoOutput instance');
videoOutput = output
});
``` ```
Surfaces must be created in advance for the preview, shooting, and video recording stream. The preview stream is the surface provided by the **XComponent**, the shooting stream is the surface provided by **ImageReceiver**, and the video recording stream is the surface provided by **VideoRecorder**.
#### Setting Parameters **XComponent**
```js ```typescript
// Check whether the camera has flash. mXComponentController: XComponentController = new XComponentController // Create an XComponentController.
let flashStatus
await cameraInput.hasFlash().then((status) => { build() {
console.log('Promise returned with the flash light support status:' + status); Flex() {
flashStatus = status XComponent({ // Create an XComponent.
}) id: '',
if(flashStatus) { type: 'surface',
// Check whether the auto flash mode is supported. libraryname: '',
let flashModeStatus controller: this.mXComponentController
cameraInput.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO, (err, status) => {
if (err) {
console.error('Failed to check whether the flash mode is supported. ${err.message}');
return;
}
console.log('Callback returned with the flash mode support status: ' + status);
flashModeStatus = status
}) })
if(flashModeStatus) { .onload(() => { // Set the onload callback.
// Set the flash mode to auto. // Set the surface width and height (1920 x 1080). For details about how to set the preview size, see the preview resolutions supported by the current device, which are obtained by previewProfilesArray.
cameraInput.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO, (err) => { this.mXComponentController.setXComponentSurfaceSize({surfaceWidth:1920,surfaceHeight:1080})
if (err) { // Obtain the surface ID.
console.error('Failed to set the flash mode ${err.message}'); globalThis.surfaceId = mXComponentController.getXComponentSurfaceId()
return;
}
console.log('Callback returned with the successful execution of setFlashMode.');
}) })
.width('1920px') // Set the width of the XComponent.
.height('1080px') // Set the height of the XComponent.
} }
} }
```
// Check whether the continuous auto focus is supported. **ImageReceiver**
let focusModeStatus
cameraInput.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_CONTINUOUS_AUTO, (err, status) => {
if (err) {
console.error('Failed to check whether the focus mode is supported. ${err.message}');
return;
}
console.log('Callback returned with the focus mode support status: ' + status);
focusModeStatus = status
})
if(focusModeStatus) {
// Set the focus mode to continuous auto focus.
cameraInput.setFocusMode(camera.FocusMode.FOCUS_MODE_CONTINUOUS_AUTO, (err) => {
if (err) {
console.error('Failed to set the focus mode ${err.message}');
return;
}
console.log('Callback returned with the successful execution of setFocusMode.');
})
}
// Obtain the zoom ratio range supported by the camera. ```typescript
let zoomRatioRange function getImageReceiverSurfaceId() {
cameraInput.getZoomRatioRange((err, range) => { let receiver = image.createImageReceiver(640, 480, 4, 8)
if (err) { console.log(TAG + 'before ImageReceiver check')
console.error('Failed to get the zoom ratio range. ${err.message}'); if (receiver !== undefined) {
return; console.log('ImageReceiver is ok')
surfaceId1 = receiver.getReceivingSurfaceId()
console.log('ImageReceived id: ' + JSON.stringify(surfaceId1))
} else {
console.log('ImageReceiver is not ok')
} }
console.log('Callback returned with zoom ratio range: ' + range.length); }
zoomRatioRange = range ```
})
// Set a zoom ratio. **VideoRecorder**
cameraInput.setZoomRatio(zoomRatioRange[0], (err) => {
if (err) { ```typescript
console.error('Failed to set the zoom ratio value ${err.message}'); function getVideoRecorderSurface() {
return; await getFd('CameraManager.mp4');
mVideoConfig.url = mFdPath;
media.createVideoRecorder((err, recorder) => {
console.info('Entering create video receiver')
mVideoRecorder = recorder
console.info('videoRecorder is :' + JSON.stringify(mVideoRecorder))
console.info('videoRecorder.prepare called.')
mVideoRecorder.prepare(mVideoConfig, (err) => {
console.info('videoRecorder.prepare success.')
mVideoRecorder.getInputSurface((err, id) => {
console.info('getInputSurface called')
mVideoSurface = id
console.info('getInputSurface surfaceId: ' + JSON.stringify(mVideoSurface))
})
})
})
} }
console.log('Callback returned with the successful execution of setZoomRatio.');
})
``` ```
#### Managing Sessions #### Managing Sessions
##### Creating a Session ##### Creating a Session
```js ```typescript
// Create a Context object.
let context = featureAbility.getContext()
// Create a session. // Create a session.
let captureSession let captureSession = await camera.createCaptureSession()
await camera.createCaptureSession((context), (err, session) => { if (!captureSession) {
if (err) { console.error('Failed to create the CaptureSession instance.');
console.error('Failed to create the CaptureSession instance. ${err.message}');
return; return;
} }
console.log('Callback returned with the CaptureSession instance.' + session); console.log('Callback returned with the CaptureSession instance.' + session);
captureSession = session
});
// Start configuration for the session. // Start configuration for the session.
await captureSession.beginConfig((err) => { await captureSession.beginConfig()
if (err) {
console.error('Failed to start the configuration. ${err.message}');
return;
}
console.log('Callback invoked to indicate the begin config success.');
});
// Add the camera input stream to the session. // Add the camera input stream to the session.
await captureSession.addInput(cameraInput, (err) => { await captureSession.addInput(cameraInput)
if (err) {
console.error('Failed to add the CameraInput instance. ${err.message}');
return;
}
console.log('Callback invoked to indicate that the CameraInput instance is added.');
});
// Add the preview input stream to the session. // Add the preview input stream to the session.
await captureSession.addOutput(previewOutput, (err) => { await captureSession.addOutput(previewOutput)
if (err) {
console.error('Failed to add the PreviewOutput instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the PreviewOutput instance is added.');
});
// Add the photographing output stream to the session. // Add the photographing output stream to the session.
await captureSession.addOutput(photoOutput, (err) => { await captureSession.addOutput(photoOutput)
if (err) {
console.error('Failed to add the PhotoOutput instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the PhotoOutput instance is added.');
});
// Commit the session configuration. // Commit the session configuration.
await captureSession.commitConfig((err) => { await captureSession.commitConfig()
if (err) {
console.error('Failed to commit the configuration. ${err.message}');
return;
}
console.log('Callback invoked to indicate the commit config success.');
});
// Start the session. // Start the session.
await captureSession.start().then(() => { await captureSession.start().then(() => {
...@@ -291,67 +274,108 @@ await captureSession.start().then(() => { ...@@ -291,67 +274,108 @@ await captureSession.start().then(() => {
##### Switching a Session ##### Switching a Session
```js ```typescript
// Stop the session. // Stop the session.
await captureSession.stop((err) => { await captureSession.stop()
// Start configuration for the session.
await captureSession.beginConfig()
// Remove the photographing output stream from the session.
await captureSession.removeOutput(photoOutput)
// Add a video recording output stream to the session.
await captureSession.addOutput(videoOutput)
// Commit the session configuration.
await captureSession.commitConfig()
// Start the session.
await captureSession.start().then(() => {
console.log('Promise returned to indicate the session start success.');
})
```
#### Setting Parameters
```typescript
// Check whether the camera has flash.
let flashStatus = await captureSession.hasFlash()
if (!flashStatus) {
console.error('Failed to check whether the device has the flash mode.');
}
console.log('Promise returned with the flash light support status:' + flashStatus);
if (flashStatus) {
// Check whether the auto flash mode is supported.
let flashModeStatus
captureSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO, async (err, status) => {
if (err) { if (err) {
console.error('Failed to stop the session ${err.message}'); console.error('Failed to check whether the flash mode is supported. ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate the session stop success.'); console.log('Callback returned with the flash mode support status: ' + status);
}); flashModeStatus = status
})
// Start configuration for the session. if(flashModeStatus) {
await captureSession.beginConfig((err) => { // Set the flash mode to auto.
captureSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO, async (err) => {
if (err) { if (err) {
console.error('Failed to start the configuration. ${err.message}'); console.error('Failed to set the flash mode ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate the begin config success.'); console.log('Callback returned with the successful execution of setFlashMode.');
}); })
}
}
// Remove the photographing output stream from the session. // Check whether the continuous auto focus is supported.
await captureSession.removeOutput(photoOutput, (err) => { let focusModeStatus
captureSession.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_CONTINUOUS_AUTO, async (err, status) => {
if (err) { if (err) {
console.error('Failed to remove the PhotoOutput instance. ${err.message}'); console.error('Failed to check whether the focus mode is supported. ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate that the PhotoOutput instance is removed.'); console.log('Callback returned with the focus mode support status: ' + status);
}); focusModeStatus = status
})
// Add a video recording output stream to the session. if (focusModeStatus) {
await captureSession.addOutput(videoOutput, (err) => { // Set the focus mode to continuous auto focus.
captureSession.setFocusMode(camera.FocusMode.FOCUS_MODE_CONTINUOUS_AUTO, async (err) => {
if (err) { if (err) {
console.error('Failed to add the VideoOutput instance ${err.message}'); console.error('Failed to set the focus mode ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate that the VideoOutput instance is added.'); console.log('Callback returned with the successful execution of setFocusMode.');
}); })
}
// Commit the session configuration. // Obtain the zoom ratio range supported by the camera.
await captureSession.commitConfig((err) => { let zoomRatioRange = await captureSession.getZoomRatioRange()
if (!zoomRatioRange) {
console.error('Failed to get the zoom ratio range.');
return;
}
// Set a zoom ratio.
captureSession.setZoomRatio(zoomRatioRange[0], async (err) => {
if (err) { if (err) {
console.error('Failed to commit the configuration. ${err.message}'); console.error('Failed to set the zoom ratio value ${err.message}');
return; return;
} }
console.log('Callback invoked to indicate the commit config success.'); console.log('Callback returned with the successful execution of setZoomRatio.');
});
// Start the session.
await captureSession.start().then(() => {
console.log('Promise returned to indicate the session start success.');
}) })
``` ```
#### Taking Photos #### Taking Photos
```js ```typescript
let settings = { let settings = {
quality: camera.QualityLevel.QUALITY_LEVEL_HIGH, // Set the image quality to high. quality: camera.QualityLevel.QUALITY_LEVEL_HIGH, // Set the image quality to high.
rotation: camera.ImageRotation.ROTATION_0 // Set the image rotation angle to 0. rotation: camera.ImageRotation.ROTATION_0 // Set the image rotation angle to 0.
} }
// Use the current photographing settings to take photos. // Use the current photographing settings to take photos.
photoOutput.capture(settings, (err) => { photoOutput.capture(settings, async (err) => {
if (err) { if (err) {
console.error('Failed to capture the photo ${err.message}'); console.error('Failed to capture the photo ${err.message}');
return; return;
...@@ -362,9 +386,9 @@ photoOutput.capture(settings, (err) => { ...@@ -362,9 +386,9 @@ photoOutput.capture(settings, (err) => {
#### Recording Videos #### Recording Videos
```js ```typescript
// Start the video recording output stream. // Start the video recording output stream.
videoOutput.start((err) => { videoOutput.start(async (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}');
return; return;
...@@ -373,17 +397,17 @@ videoOutput.start((err) => { ...@@ -373,17 +397,17 @@ videoOutput.start((err) => {
}); });
// Start video recording. // Start video recording.
await videoRecorder.start().then(() => { videoRecorder.start().then(() => {
console.info('videoRecorder start success'); console.info('videoRecorder start success');
} }
// Stop video recording. // Stop video recording.
await videoRecorder.stop().then(() => { videoRecorder.stop().then(() => {
console.info('stop success'); console.info('stop success');
} }
// Stop the video recording output stream. // Stop the video recording output stream.
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;
...@@ -392,81 +416,34 @@ await videoOutput.stop((err) => { ...@@ -392,81 +416,34 @@ await videoOutput.stop((err) => {
}); });
``` ```
For details about the APIs used for saving photos, see [Image Processing](image.md#using-imagereceiver).
#### Releasing Resources #### Releasing Resources
```js ```typescript
// Stop the session. // Stop the session.
await captureSession.stop((err) => { captureSession.stop()
if (err) {
console.error('Failed to stop the session ${err.message}');
return;
}
console.log('Callback invoked to indicate the session stop success.');
});
// Release the camera input stream. // Release the camera input stream.
await cameraInput.release((err) => { cameraInput.release()
if (err) {
console.error('Failed to release the CameraInput instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the CameraInput instance is released successfully.');
});
// Release the preview output stream. // Release the preview output stream.
await previewOutput.release((err) => { previewOutput.release()
if (err) {
console.error('Failed to release the PreviewOutput instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.');
});
// Release the photographing output stream. // Release the photographing output stream.
await photoOutput.release((err) => { photoOutput.release()
if (err) {
console.error('Failed to release the PhotoOutput instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the PhotoOutput instance is released successfully.');
});
// Release the video recording output stream. // Release the video recording output stream.
await videoOutput.release((err) => { videoOutput.release()
if (err) {
console.error('Failed to release the VideoOutput instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the VideoOutput instance is released successfully.');
});
// Release the session. // Release the session.
await captureSession.release((err) => { captureSession.release()
if (err) {
console.error('Failed to release the CaptureSession instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the CaptureSession instance is released successfully.');
});
```
#### XComponent Creation // Set the session to null.
The surface ID must be obtained for image preview. captureSession = null
```
```js ## Process Flowchart
mXComponentController: XComponentController = new XComponentController // Create an XComponentController.
build() { The following figure shows the process of using the camera.
Flex() { ![camera_framework process](figures/camera_framework_process.jpg)
XComponent({ // Create an XComponent.
id: '',
type: 'surface',
libraryname: '',
controller: this.mXComponentController
})
.onload(() => { // Set the onload callback.
// Set the width and height of the surface to 1920 and 1080, respectively.
this.mXComponentController.setXComponentSurfaceSize({surfaceWidth:1920,surfaceHeight:1080})
// Obtain the surface ID.
globalThis.surfaceId = mXComponentController.getXComponentSurfaceId()
})
.width('1920px') // Set the width of the XComponent.
.height('1080px') // Set the height of the XComponent.
}
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册