1e41f4b71Sopenharmony_ci# Camera Photographing Sample (C/C++)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThis topic provides sample code that covers the complete photographing process and the API calling sequence. For details about a single process (such as device input, session management, and photographing), see the corresponding C/C++ development guide links provided in [Camera Development Preparations](camera-preparation.md).
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci## Development Process
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciAfter obtaining the output stream capabilities supported by the camera, create a photo stream. The development process is as follows:
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci![Photographing Development Process](figures/photographing-ndk-development-process.png)
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci## Sample Code
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci1. Link the dynamic library in the CMake script.
14e41f4b71Sopenharmony_ci    ```txt
15e41f4b71Sopenharmony_ci        target_link_libraries(entry PUBLIC libohcamera.so libhilog_ndk.z.so)
16e41f4b71Sopenharmony_ci    ```
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci2. Import the NDK APIs on the C++ side, and perform photographing based on the surface ID passed in.
19e41f4b71Sopenharmony_ci    ```c++
20e41f4b71Sopenharmony_ci    #include "hilog/log.h"
21e41f4b71Sopenharmony_ci    #include "ohcamera/camera.h"
22e41f4b71Sopenharmony_ci    #include "ohcamera/camera_input.h"
23e41f4b71Sopenharmony_ci    #include "ohcamera/capture_session.h"
24e41f4b71Sopenharmony_ci    #include "ohcamera/photo_output.h"
25e41f4b71Sopenharmony_ci    #include "ohcamera/preview_output.h"
26e41f4b71Sopenharmony_ci    #include "ohcamera/video_output.h"
27e41f4b71Sopenharmony_ci    #include "ohcamera/camera_manager.h"
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci    void CaptureSessionOnFocusStateChange(Camera_CaptureSession* session, Camera_FocusState focusState)
30e41f4b71Sopenharmony_ci    {
31e41f4b71Sopenharmony_ci        OH_LOG_INFO(LOG_APP, "CaptureSessionOnFocusStateChange");
32e41f4b71Sopenharmony_ci    }
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci    void CaptureSessionOnError(Camera_CaptureSession* session, Camera_ErrorCode errorCode)
35e41f4b71Sopenharmony_ci    {
36e41f4b71Sopenharmony_ci        OH_LOG_INFO(LOG_APP, "CaptureSessionOnError = %{public}d", errorCode);
37e41f4b71Sopenharmony_ci    }
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci    CaptureSession_Callbacks* GetCaptureSessionRegister(void)
40e41f4b71Sopenharmony_ci    {
41e41f4b71Sopenharmony_ci        static CaptureSession_Callbacks captureSessionCallbacks = {
42e41f4b71Sopenharmony_ci            .onFocusStateChange = CaptureSessionOnFocusStateChange,
43e41f4b71Sopenharmony_ci            .onError = CaptureSessionOnError
44e41f4b71Sopenharmony_ci        };
45e41f4b71Sopenharmony_ci        return &captureSessionCallbacks;
46e41f4b71Sopenharmony_ci    }
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci    void PreviewOutputOnFrameStart(Camera_PreviewOutput* previewOutput)
49e41f4b71Sopenharmony_ci    {
50e41f4b71Sopenharmony_ci        OH_LOG_INFO(LOG_APP, "PreviewOutputOnFrameStart");
51e41f4b71Sopenharmony_ci    }
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci    void PreviewOutputOnFrameEnd(Camera_PreviewOutput* previewOutput, int32_t frameCount)
54e41f4b71Sopenharmony_ci    {
55e41f4b71Sopenharmony_ci        OH_LOG_INFO(LOG_APP, "PreviewOutputOnFrameEnd = %{public}d", frameCount);
56e41f4b71Sopenharmony_ci    }
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci    void PreviewOutputOnError(Camera_PreviewOutput* previewOutput, Camera_ErrorCode errorCode)
59e41f4b71Sopenharmony_ci    {
60e41f4b71Sopenharmony_ci        OH_LOG_INFO(LOG_APP, "PreviewOutputOnError = %{public}d", errorCode);
61e41f4b71Sopenharmony_ci    }
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ci    PreviewOutput_Callbacks* GetPreviewOutputListener(void)
64e41f4b71Sopenharmony_ci    {
65e41f4b71Sopenharmony_ci        static PreviewOutput_Callbacks previewOutputListener = {
66e41f4b71Sopenharmony_ci            .onFrameStart = PreviewOutputOnFrameStart,
67e41f4b71Sopenharmony_ci            .onFrameEnd = PreviewOutputOnFrameEnd,
68e41f4b71Sopenharmony_ci            .onError = PreviewOutputOnError
69e41f4b71Sopenharmony_ci        };
70e41f4b71Sopenharmony_ci        return &previewOutputListener;
71e41f4b71Sopenharmony_ci    }
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci    void OnCameraInputError(const Camera_Input* cameraInput, Camera_ErrorCode errorCode)
74e41f4b71Sopenharmony_ci    {
75e41f4b71Sopenharmony_ci        OH_LOG_INFO(LOG_APP, "OnCameraInput errorCode = %{public}d", errorCode);
76e41f4b71Sopenharmony_ci    }
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci    CameraInput_Callbacks* GetCameraInputListener(void)
79e41f4b71Sopenharmony_ci    {
80e41f4b71Sopenharmony_ci        static CameraInput_Callbacks cameraInputCallbacks = {
81e41f4b71Sopenharmony_ci            .onError = OnCameraInputError
82e41f4b71Sopenharmony_ci        };
83e41f4b71Sopenharmony_ci        return &cameraInputCallbacks;
84e41f4b71Sopenharmony_ci    }
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci    void CameraManagerStatusCallback(Camera_Manager* cameraManager, Camera_StatusInfo* status)
87e41f4b71Sopenharmony_ci    {
88e41f4b71Sopenharmony_ci        OH_LOG_INFO(LOG_APP, "CameraManagerStatusCallback is called");
89e41f4b71Sopenharmony_ci    }
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci    CameraManager_Callbacks* GetCameraManagerListener()
92e41f4b71Sopenharmony_ci    {
93e41f4b71Sopenharmony_ci        static CameraManager_Callbacks cameraManagerListener = {
94e41f4b71Sopenharmony_ci            .onCameraStatus = CameraManagerStatusCallback
95e41f4b71Sopenharmony_ci        };
96e41f4b71Sopenharmony_ci        return &cameraManagerListener;
97e41f4b71Sopenharmony_ci    }
98e41f4b71Sopenharmony_ci
99e41f4b71Sopenharmony_ci    NDKCamera::NDKCamera(char *previewId, char *photoId)
100e41f4b71Sopenharmony_ci    {
101e41f4b71Sopenharmony_ci        Camera_Manager* cameraManager = nullptr;
102e41f4b71Sopenharmony_ci        Camera_Device* cameras = nullptr;
103e41f4b71Sopenharmony_ci        Camera_CaptureSession* captureSession = nullptr;
104e41f4b71Sopenharmony_ci        Camera_OutputCapability* cameraOutputCapability = nullptr;
105e41f4b71Sopenharmony_ci        const Camera_Profile* previewProfile = nullptr;
106e41f4b71Sopenharmony_ci        const Camera_Profile* photoProfile = nullptr;
107e41f4b71Sopenharmony_ci        Camera_PreviewOutput* previewOutput = nullptr;
108e41f4b71Sopenharmony_ci        Camera_PhotoOutput* photoOutput = nullptr;
109e41f4b71Sopenharmony_ci        Camera_Input* cameraInput = nullptr;
110e41f4b71Sopenharmony_ci        uint32_t size = 0;
111e41f4b71Sopenharmony_ci        uint32_t cameraDeviceIndex = 0;
112e41f4b71Sopenharmony_ci        char* previewSurfaceId = previewId;
113e41f4b71Sopenharmony_ci        char* photoSurfaceId = photoId;
114e41f4b71Sopenharmony_ci        // Create a CameraManager object.
115e41f4b71Sopenharmony_ci        Camera_ErrorCode ret = OH_Camera_GetCameraManager(&cameraManager);
116e41f4b71Sopenharmony_ci        if (cameraManager == nullptr || ret != CAMERA_OK) {
117e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_Camera_GetCameraMananger failed.");
118e41f4b71Sopenharmony_ci        }
119e41f4b71Sopenharmony_ci        // Listen for camera status changes.
120e41f4b71Sopenharmony_ci        ret = OH_CameraManager_RegisterCallback(cameraManager, GetCameraManagerListener());
121e41f4b71Sopenharmony_ci        if (ret != CAMERA_OK) {
122e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CameraManager_RegisterCallback failed.");
123e41f4b71Sopenharmony_ci        }
124e41f4b71Sopenharmony_ci        
125e41f4b71Sopenharmony_ci        // Obtain the camera list.
126e41f4b71Sopenharmony_ci        ret = OH_CameraManager_GetSupportedCameras(cameraManager, &cameras, &size);
127e41f4b71Sopenharmony_ci        if (cameras == nullptr || size < 0 || ret != CAMERA_OK) {
128e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CameraManager_GetSupportedCameras failed.");
129e41f4b71Sopenharmony_ci        }
130e41f4b71Sopenharmony_ci        
131e41f4b71Sopenharmony_ci        // Create a camera input stream.
132e41f4b71Sopenharmony_ci        ret = OH_CameraManager_CreateCameraInput(cameraManager, &cameras[cameraDeviceIndex], &cameraInput);
133e41f4b71Sopenharmony_ci        if (cameraInput == nullptr || ret != CAMERA_OK) {
134e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CameraManager_CreateCameraInput failed.");
135e41f4b71Sopenharmony_ci        }
136e41f4b71Sopenharmony_ci        
137e41f4b71Sopenharmony_ci        // Listen for camera input errors.
138e41f4b71Sopenharmony_ci        ret = OH_CameraInput_RegisterCallback(cameraInput, GetCameraInputListener());
139e41f4b71Sopenharmony_ci        if (ret != CAMERA_OK) {
140e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CameraInput_RegisterCallback failed.");
141e41f4b71Sopenharmony_ci        }
142e41f4b71Sopenharmony_ci        
143e41f4b71Sopenharmony_ci        // Open the camera.
144e41f4b71Sopenharmony_ci        ret = OH_CameraInput_Open(cameraInput);
145e41f4b71Sopenharmony_ci        if (ret != CAMERA_OK) {
146e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CameraInput_Open failed.");
147e41f4b71Sopenharmony_ci        }
148e41f4b71Sopenharmony_ci        
149e41f4b71Sopenharmony_ci        // Obtain the output streams supported by the camera.
150e41f4b71Sopenharmony_ci        ret = OH_CameraManager_GetSupportedCameraOutputCapability(cameraManager, &cameras[cameraDeviceIndex],
151e41f4b71Sopenharmony_ci                                                                  &cameraOutputCapability);
152e41f4b71Sopenharmony_ci        if (cameraOutputCapability == nullptr || ret != CAMERA_OK) {
153e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CameraManager_GetSupportedCameraOutputCapability failed.");
154e41f4b71Sopenharmony_ci        }
155e41f4b71Sopenharmony_ci        
156e41f4b71Sopenharmony_ci        if (cameraOutputCapability->previewProfilesSize < 0) {
157e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "previewProfilesSize == null");
158e41f4b71Sopenharmony_ci        }
159e41f4b71Sopenharmony_ci        previewProfile = cameraOutputCapability->previewProfiles[0];
160e41f4b71Sopenharmony_ci        
161e41f4b71Sopenharmony_ci        if (cameraOutputCapability->photoProfilesSize < 0) {
162e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "photoProfilesSize == null");
163e41f4b71Sopenharmony_ci        }
164e41f4b71Sopenharmony_ci        photoProfile = cameraOutputCapability->photoProfiles[0];
165e41f4b71Sopenharmony_ci        
166e41f4b71Sopenharmony_ci        
167e41f4b71Sopenharmony_ci        // Create a preview output stream, with the previewSurfaceId parameter set to the ID of the surface provided by the <XComponent>.
168e41f4b71Sopenharmony_ci        ret = OH_CameraManager_CreatePreviewOutput(cameraManager, previewProfile, previewSurfaceId, &previewOutput);
169e41f4b71Sopenharmony_ci        if (previewProfile == nullptr || previewOutput == nullptr || ret != CAMERA_OK) {
170e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CameraManager_CreatePreviewOutput failed.");
171e41f4b71Sopenharmony_ci        }
172e41f4b71Sopenharmony_ci        
173e41f4b71Sopenharmony_ci        // Listen for preview output errors.
174e41f4b71Sopenharmony_ci        ret = OH_PreviewOutput_RegisterCallback(previewOutput, GetPreviewOutputListener());
175e41f4b71Sopenharmony_ci        if (ret != CAMERA_OK) {
176e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_PreviewOutput_RegisterCallback failed.");
177e41f4b71Sopenharmony_ci        }
178e41f4b71Sopenharmony_ci        
179e41f4b71Sopenharmony_ci        // Create a photo output stream, with the photoSurfaceId parameter set to the ID of the surface obtained through ImageReceiver.
180e41f4b71Sopenharmony_ci        ret = OH_CameraManager_CreatePhotoOutput(cameraManager, photoProfile, photoSurfaceId, &photoOutput);
181e41f4b71Sopenharmony_ci        if (photoProfile == nullptr || photoOutput == nullptr || ret != CAMERA_OK) {
182e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CameraManager_CreatePhotoOutput failed.");
183e41f4b71Sopenharmony_ci        }
184e41f4b71Sopenharmony_ci        
185e41f4b71Sopenharmony_ci        // Create a session.
186e41f4b71Sopenharmony_ci        ret = OH_CameraManager_CreateCaptureSession(cameraManager, &captureSession);
187e41f4b71Sopenharmony_ci        if (captureSession == nullptr || ret != CAMERA_OK) {
188e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CameraManager_CreateCaptureSession failed.");
189e41f4b71Sopenharmony_ci        }
190e41f4b71Sopenharmony_ci        
191e41f4b71Sopenharmony_ci        // Listen for session errors.
192e41f4b71Sopenharmony_ci        ret = OH_CaptureSession_RegisterCallback(captureSession, GetCaptureSessionRegister());
193e41f4b71Sopenharmony_ci        if (ret != CAMERA_OK) {
194e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_RegisterCallback failed.");
195e41f4b71Sopenharmony_ci        }
196e41f4b71Sopenharmony_ci        
197e41f4b71Sopenharmony_ci        // Start configuration for the session.
198e41f4b71Sopenharmony_ci        ret = OH_CaptureSession_BeginConfig(captureSession);
199e41f4b71Sopenharmony_ci        if (ret != CAMERA_OK) {
200e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_BeginConfig failed.");
201e41f4b71Sopenharmony_ci        }
202e41f4b71Sopenharmony_ci        
203e41f4b71Sopenharmony_ci        // Add the camera input stream to the session.
204e41f4b71Sopenharmony_ci        ret = OH_CaptureSession_AddInput(captureSession, cameraInput);
205e41f4b71Sopenharmony_ci        if (ret != CAMERA_OK) {
206e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_AddInput failed.");
207e41f4b71Sopenharmony_ci        }
208e41f4b71Sopenharmony_ci        
209e41f4b71Sopenharmony_ci        // Add the preview output stream to the session.
210e41f4b71Sopenharmony_ci        ret = OH_CaptureSession_AddPreviewOutput(captureSession, previewOutput);
211e41f4b71Sopenharmony_ci        if (ret != CAMERA_OK) {
212e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_AddPreviewOutput failed.");
213e41f4b71Sopenharmony_ci        }
214e41f4b71Sopenharmony_ci        
215e41f4b71Sopenharmony_ci        // Add the photo output stream to the session.
216e41f4b71Sopenharmony_ci        ret = OH_CaptureSession_AddPhotoOutput(captureSession, photoOutput);
217e41f4b71Sopenharmony_ci        if (ret != CAMERA_OK) {
218e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_AddPhotoOutput failed.");
219e41f4b71Sopenharmony_ci        }
220e41f4b71Sopenharmony_ci        
221e41f4b71Sopenharmony_ci        // Commit the session configuration.
222e41f4b71Sopenharmony_ci        ret = OH_CaptureSession_CommitConfig(captureSession);
223e41f4b71Sopenharmony_ci        if (ret != CAMERA_OK) {
224e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_CommitConfig failed.");
225e41f4b71Sopenharmony_ci        }
226e41f4b71Sopenharmony_ci        
227e41f4b71Sopenharmony_ci        // Start the session.
228e41f4b71Sopenharmony_ci        ret = OH_CaptureSession_Start(captureSession);
229e41f4b71Sopenharmony_ci        if (ret != CAMERA_OK) {
230e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_Start failed.");
231e41f4b71Sopenharmony_ci        }
232e41f4b71Sopenharmony_ci        
233e41f4b71Sopenharmony_ci        // Check whether the camera has flash.
234e41f4b71Sopenharmony_ci        Camera_FlashMode flashMode = FLASH_MODE_AUTO;
235e41f4b71Sopenharmony_ci        bool hasFlash = false;
236e41f4b71Sopenharmony_ci        ret = OH_CaptureSession_HasFlash(captureSession, &hasFlash);
237e41f4b71Sopenharmony_ci        if (ret != CAMERA_OK) {
238e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_HasFlash failed.");
239e41f4b71Sopenharmony_ci        }
240e41f4b71Sopenharmony_ci        if (hasFlash) {
241e41f4b71Sopenharmony_ci          OH_LOG_INFO(LOG_APP, "hasFlash success");
242e41f4b71Sopenharmony_ci        } else {
243e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "hasFlash fail");
244e41f4b71Sopenharmony_ci        }
245e41f4b71Sopenharmony_ci        // Check whether a flash mode is supported.
246e41f4b71Sopenharmony_ci        bool isSupported = false;
247e41f4b71Sopenharmony_ci        ret = OH_CaptureSession_IsFlashModeSupported(captureSession, flashMode, &isSupported);
248e41f4b71Sopenharmony_ci        if (ret != CAMERA_OK) {
249e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_IsFlashModeSupported failed.");
250e41f4b71Sopenharmony_ci        }
251e41f4b71Sopenharmony_ci        if (isSupported) {
252e41f4b71Sopenharmony_ci          OH_LOG_INFO(LOG_APP, "isFlashModeSupported success");
253e41f4b71Sopenharmony_ci          // Set the flash mode.
254e41f4b71Sopenharmony_ci          ret = OH_CaptureSession_SetFlashMode(captureSession, flashMode);
255e41f4b71Sopenharmony_ci          if (ret == CAMERA_OK) {
256e41f4b71Sopenharmony_ci              OH_LOG_INFO(LOG_APP, "OH_CaptureSession_SetFlashMode success.");
257e41f4b71Sopenharmony_ci          } else {
258e41f4b71Sopenharmony_ci              OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetFlashMode failed. %{public}d ", ret);
259e41f4b71Sopenharmony_ci          }
260e41f4b71Sopenharmony_ci          // Obtain the flash mode in use.
261e41f4b71Sopenharmony_ci          ret = OH_CaptureSession_GetFlashMode(captureSession, &flashMode);
262e41f4b71Sopenharmony_ci          if (ret == CAMERA_OK) {
263e41f4b71Sopenharmony_ci              OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetFlashMode success. flashMode: %{public}d ", flashMode);
264e41f4b71Sopenharmony_ci          } else {
265e41f4b71Sopenharmony_ci              OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetFlashMode failed. %d ", ret);
266e41f4b71Sopenharmony_ci          }
267e41f4b71Sopenharmony_ci        } else {
268e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "isFlashModeSupported fail");
269e41f4b71Sopenharmony_ci        }
270e41f4b71Sopenharmony_ci        
271e41f4b71Sopenharmony_ci        // Check whether the continuous auto focus is supported.
272e41f4b71Sopenharmony_ci        Camera_FocusMode focusMode = FOCUS_MODE_CONTINUOUS_AUTO;
273e41f4b71Sopenharmony_ci        bool isFocusModeSupported = false;
274e41f4b71Sopenharmony_ci        ret = OH_CaptureSession_IsFocusModeSupported(captureSession, focusMode, &isFocusModeSupported);
275e41f4b71Sopenharmony_ci        if (ret != CAMERA_OK) {
276e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_IsFocusModeSupported failed.");
277e41f4b71Sopenharmony_ci        }
278e41f4b71Sopenharmony_ci        if (isFocusModeSupported) {
279e41f4b71Sopenharmony_ci          OH_LOG_INFO(LOG_APP, "isFocusModeSupported success");
280e41f4b71Sopenharmony_ci          ret = OH_CaptureSession_SetFocusMode(captureSession, focusMode);
281e41f4b71Sopenharmony_ci          if (ret != CAMERA_OK) {
282e41f4b71Sopenharmony_ci              OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetFocusMode failed. %{public}d ", ret);
283e41f4b71Sopenharmony_ci          }
284e41f4b71Sopenharmony_ci          ret = OH_CaptureSession_GetFocusMode(captureSession, &focusMode);
285e41f4b71Sopenharmony_ci          if (ret == CAMERA_OK) {
286e41f4b71Sopenharmony_ci              OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetFocusMode success. focusMode%{public}d ", focusMode);
287e41f4b71Sopenharmony_ci          } else {
288e41f4b71Sopenharmony_ci              OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetFocusMode failed. %d ", ret);
289e41f4b71Sopenharmony_ci          }
290e41f4b71Sopenharmony_ci        } else {
291e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "isFocusModeSupported fail");
292e41f4b71Sopenharmony_ci        }
293e41f4b71Sopenharmony_ci        
294e41f4b71Sopenharmony_ci        // Obtain the zoom ratio range supported by the camera.
295e41f4b71Sopenharmony_ci        float minZoom;
296e41f4b71Sopenharmony_ci        float maxZoom;
297e41f4b71Sopenharmony_ci        ret = OH_CaptureSession_GetZoomRatioRange(captureSession, &minZoom, &maxZoom);
298e41f4b71Sopenharmony_ci        if (ret != CAMERA_OK) {
299e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetZoomRatioRange failed.");
300e41f4b71Sopenharmony_ci        } else {
301e41f4b71Sopenharmony_ci          OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetZoomRatioRange success. minZoom: %{public}f, maxZoom:%{public}f",
302e41f4b71Sopenharmony_ci              minZoom, maxZoom);
303e41f4b71Sopenharmony_ci        }
304e41f4b71Sopenharmony_ci        // Set a zoom ratio.
305e41f4b71Sopenharmony_ci        ret = OH_CaptureSession_SetZoomRatio(captureSession, maxZoom);
306e41f4b71Sopenharmony_ci        if (ret == CAMERA_OK) {
307e41f4b71Sopenharmony_ci          OH_LOG_INFO(LOG_APP, "OH_CaptureSession_SetZoomRatio success.");
308e41f4b71Sopenharmony_ci        } else {
309e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_SetZoomRatio failed. %{public}d ", ret);
310e41f4b71Sopenharmony_ci        }
311e41f4b71Sopenharmony_ci        // Obtain the zoom ratio of the camera.
312e41f4b71Sopenharmony_ci        ret = OH_CaptureSession_GetZoomRatio(captureSession, &maxZoom);
313e41f4b71Sopenharmony_ci        if (ret == CAMERA_OK) {
314e41f4b71Sopenharmony_ci          OH_LOG_INFO(LOG_APP, "OH_CaptureSession_GetZoomRatio success. zoom: %{public}f ", maxZoom);
315e41f4b71Sopenharmony_ci        } else {
316e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_GetZoomRatio failed. %{public}d ", ret);
317e41f4b71Sopenharmony_ci        }
318e41f4b71Sopenharmony_ci        
319e41f4b71Sopenharmony_ci        // Take photos without photographing settings.
320e41f4b71Sopenharmony_ci        ret = OH_PhotoOutput_Capture(photoOutput);
321e41f4b71Sopenharmony_ci        if (ret == CAMERA_OK) {
322e41f4b71Sopenharmony_ci          OH_LOG_INFO(LOG_APP, "OH_PhotoOutput_Capture success ");
323e41f4b71Sopenharmony_ci        } else {
324e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_PhotoOutput_Capture failed. %d ", ret);
325e41f4b71Sopenharmony_ci        }
326e41f4b71Sopenharmony_ci        
327e41f4b71Sopenharmony_ci        // Stop the session.
328e41f4b71Sopenharmony_ci        ret = OH_CaptureSession_Stop(captureSession);
329e41f4b71Sopenharmony_ci        if (ret == CAMERA_OK) {
330e41f4b71Sopenharmony_ci          OH_LOG_INFO(LOG_APP, "OH_CaptureSession_Stop success ");
331e41f4b71Sopenharmony_ci        } else {
332e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_Stop failed. %d ", ret);
333e41f4b71Sopenharmony_ci        }
334e41f4b71Sopenharmony_ci        
335e41f4b71Sopenharmony_ci        // Release the camera input stream.
336e41f4b71Sopenharmony_ci        ret = OH_CameraInput_Close(cameraInput);
337e41f4b71Sopenharmony_ci        if (ret == CAMERA_OK) {
338e41f4b71Sopenharmony_ci          OH_LOG_INFO(LOG_APP, "OH_CameraInput_Close success ");
339e41f4b71Sopenharmony_ci        } else {
340e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CameraInput_Close failed. %d ", ret);
341e41f4b71Sopenharmony_ci        }
342e41f4b71Sopenharmony_ci        
343e41f4b71Sopenharmony_ci        // Release the preview output stream.
344e41f4b71Sopenharmony_ci        ret = OH_PreviewOutput_Release(previewOutput);
345e41f4b71Sopenharmony_ci        if (ret == CAMERA_OK) {
346e41f4b71Sopenharmony_ci          OH_LOG_INFO(LOG_APP, "OH_PreviewOutput_Release success ");
347e41f4b71Sopenharmony_ci        } else {
348e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_PreviewOutput_Release failed. %d ", ret);
349e41f4b71Sopenharmony_ci        }
350e41f4b71Sopenharmony_ci        
351e41f4b71Sopenharmony_ci        // Release the photo output stream.
352e41f4b71Sopenharmony_ci        ret = OH_PhotoOutput_Release(photoOutput);
353e41f4b71Sopenharmony_ci        if (ret == CAMERA_OK) {
354e41f4b71Sopenharmony_ci          OH_LOG_INFO(LOG_APP, "OH_PhotoOutput_Release success ");
355e41f4b71Sopenharmony_ci        } else {
356e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_PhotoOutput_Release failed. %d ", ret);
357e41f4b71Sopenharmony_ci        }
358e41f4b71Sopenharmony_ci        
359e41f4b71Sopenharmony_ci        // Release the session.
360e41f4b71Sopenharmony_ci        ret = OH_CaptureSession_Release(captureSession);
361e41f4b71Sopenharmony_ci        if (ret == CAMERA_OK) {
362e41f4b71Sopenharmony_ci          OH_LOG_INFO(LOG_APP, "OH_CaptureSession_Release success ");
363e41f4b71Sopenharmony_ci        } else {
364e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CaptureSession_Release failed. %d ", ret);
365e41f4b71Sopenharmony_ci        }
366e41f4b71Sopenharmony_ci        
367e41f4b71Sopenharmony_ci        // Release the resources.
368e41f4b71Sopenharmony_ci        ret = OH_CameraManager_DeleteSupportedCameras(cameraManager, cameras, size);
369e41f4b71Sopenharmony_ci        if (ret != CAMERA_OK) {
370e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "Delete Cameras failed.");
371e41f4b71Sopenharmony_ci        } else {
372e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CameraManager_DeleteSupportedCameras. ok");
373e41f4b71Sopenharmony_ci        }
374e41f4b71Sopenharmony_ci        ret = OH_CameraManager_DeleteSupportedCameraOutputCapability(cameraManager, cameraOutputCapability);
375e41f4b71Sopenharmony_ci        if (ret != CAMERA_OK) {
376e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "Delete Cameras failed.");
377e41f4b71Sopenharmony_ci        } else {
378e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_CameraManager_DeleteSupportedCameraOutputCapability. ok");
379e41f4b71Sopenharmony_ci        }
380e41f4b71Sopenharmony_ci        ret = OH_Camera_DeleteCameraManager(cameraManager);
381e41f4b71Sopenharmony_ci        if (ret != CAMERA_OK) {
382e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "Delete Cameras failed.");
383e41f4b71Sopenharmony_ci        } else {
384e41f4b71Sopenharmony_ci          OH_LOG_ERROR(LOG_APP, "OH_Camera_DeleteCameraManager. ok");
385e41f4b71Sopenharmony_ci        }
386e41f4b71Sopenharmony_ci    }
387e41f4b71Sopenharmony_ci    ```
388