1e41f4b71Sopenharmony_ci# Depth Data (for System Applications Only) (ArkTS) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciDepth data reflects the spatial arrangement of image pixels in relation to the camera lens. It facilitates enhanced focus precision, background blurring effects, and the like. Depth data can be reported in the preview, photographing, and video scenarios of camera applications. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci## How to Develop 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciRead [Camera](../../reference/apis-camera-kit/js-apis-camera.md) for the API reference. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci1. Import the camera module, which provides camera-related attributes and methods. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci ```ts 12e41f4b71Sopenharmony_ci import { camera } from '@kit.CameraKit'; 13e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 14e41f4b71Sopenharmony_ci ``` 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci2. Use **depthProfiles** in the [CameraOutputCapability](../../reference/apis-camera-kit/js-apis-camera.md#cameraoutputcapability) class to obtain the depth data capabilities, in the format of an **depthProfilesArray** array, supported by the current device. Call [createDepthDataOutput](../../reference/apis-camera-kit/js-apis-camera-sys.md#createdepthdataoutput) to create a depth data stream. 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci ```ts 19e41f4b71Sopenharmony_ci function getDepthDataOutput(cameraManager: camera.CameraManager, cameraOutputCapability: camera.CameraOutputCapability): camera.DepthDataOutput | undefined { 20e41f4b71Sopenharmony_ci let depthProfilesArray: Array<camera.Profile> = cameraOutputCapability.depthProfiles; 21e41f4b71Sopenharmony_ci let depthDataOutput: camera.DepthDataOutput | undefined = undefined; 22e41f4b71Sopenharmony_ci try { 23e41f4b71Sopenharmony_ci depthDataOutput = cameraManager.createDepthDataOutput(depthProfilesArray[0]); 24e41f4b71Sopenharmony_ci } catch (error) { 25e41f4b71Sopenharmony_ci let err = error as BusinessError; 26e41f4b71Sopenharmony_ci console.error(`Failed to create the DepthDataOutput instance. error: ${JSON.stringify(err)}`); 27e41f4b71Sopenharmony_ci } 28e41f4b71Sopenharmony_ci return depthDataOutput; 29e41f4b71Sopenharmony_ci } 30e41f4b71Sopenharmony_ci ``` 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci3. Call [start](../../reference/apis-camera-kit/js-apis-camera-sys.md#start) in the **depthDataOutput** class to start outputting the depth data stream. If the call fails, an error code is returned. For details about the error code types, see [CameraErrorCode](../../reference/apis-camera-kit/js-apis-camera.md#cameraerrorcode). 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci ```ts 35e41f4b71Sopenharmony_ci async function startDepthDataOutput(depthDataOutput: camera.DepthDataOutput): Promise<void> { 36e41f4b71Sopenharmony_ci if (!depthDataOutput) { 37e41f4b71Sopenharmony_ci console.error('depthDataOutput Undefined'); 38e41f4b71Sopenharmony_ci return; 39e41f4b71Sopenharmony_ci } 40e41f4b71Sopenharmony_ci try { 41e41f4b71Sopenharmony_ci await depthDataOutput.start(); 42e41f4b71Sopenharmony_ci } catch (err) { 43e41f4b71Sopenharmony_ci const error = err as BusinessError; 44e41f4b71Sopenharmony_ci console.error(`Failed to start depth data output. error: ${JSON.stringify(err)}`); 45e41f4b71Sopenharmony_ci } 46e41f4b71Sopenharmony_ci } 47e41f4b71Sopenharmony_ci ``` 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci## Status Listening 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ciDuring camera application development, you can listen for depth data and depth data output errors. 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci- Register the fixed callback function **depthDataAvailable** to obtain the depth data. 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci ```ts 56e41f4b71Sopenharmony_ci function onDepthDataAvailable(depthDataOutput: camera.DepthDataOutput): void { 57e41f4b71Sopenharmony_ci depthDataOutput.on('depthDataAvailable', (err: BusinessError) => { 58e41f4b71Sopenharmony_ci if (err !== undefined && err.code !== 0) { 59e41f4b71Sopenharmony_ci return; 60e41f4b71Sopenharmony_ci } 61e41f4b71Sopenharmony_ci console.info('Depth data available'); 62e41f4b71Sopenharmony_ci }); 63e41f4b71Sopenharmony_ci } 64e41f4b71Sopenharmony_ci ``` 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci- Register the **'error'** event to listen for depth data output errors. The callback function returns an error code when an API is incorrectly used. For details about the error code types, see [CameraErrorCode](../../reference/apis-camera-kit/js-apis-camera.md#cameraerrorcode). 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci ```ts 69e41f4b71Sopenharmony_ci function onDepthDataOutputError(depthDataOutput: camera.DepthDataOutput): void { 70e41f4b71Sopenharmony_ci depthDataOutput.on('error', (depthDataOutputError: BusinessError) => { 71e41f4b71Sopenharmony_ci console.error(`Depth data output error code: ${depthDataOutputError.code}`); 72e41f4b71Sopenharmony_ci }); 73e41f4b71Sopenharmony_ci } 74e41f4b71Sopenharmony_ci ``` 75