使用相机预配置(C/C++)
==============

相机预配置（Preconfig），对常用的场景和分辨率进行了预配置集成，可简化开发相机应用流程，提高应用的开发效率。

开发者在开发相机应用时，在获取到CameraDevice之后，如果遵循通用流程开发，步骤较为繁琐。需要先查询当前相机在指定模式下所支持的各类输出的配置信息，拿到[Camera\_OutputCapability](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/capi-oh-camera-camera-outputcapability)之后，应用开发者还需要对里面的各类数据进行解析，筛选，找到自己需要的配置数据[Camera\_Profile](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/capi-oh-camera-camera-profile)和[Camera\_VideoProfile](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/capi-oh-camera-camera-videoprofile)。最后使用对应的Profile以及VideoProfile创建对应的[Camera\_PreviewOutput](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/capi-oh-camera-camera-previewoutput)、[Camera\_PhotoOutput](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/capi-oh-camera-camera-photooutput)以及[Camera\_VideoOutput](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/capi-oh-camera-camera-videooutput)。

为了解决上述问题，优化应用开发流程，系统针对拍照、录像两类场景（即[Camera\_SceneMode](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/capi-camera-h#camera_scenemode)为NORMAL\_PHOTO或NORMAL\_VIDEO），提供了[OH\_CameraManager\_CreatePreviewOutputUsedInPreconfig](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/capi-camera-manager-h#oh_cameramanager_createpreviewoutputusedinpreconfig)、[OH\_CameraManager\_CreatePhotoOutputUsedInPreconfig](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/capi-camera-manager-h#oh_cameramanager_createphotooutputusedinpreconfig)、[OH\_CameraManager\_CreateVideoOutputUsedInPreconfig](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/capi-camera-manager-h#oh_cameramanager_createvideooutputusedinpreconfig)接口帮助开发者快速完成相机参数配置。推荐仅需要自定义拍照界面的无需开发专业相机应用的开发者，使用相机预配置功能快速开发应用。

#### 规格说明

系统提供了4种预配置类型（[Camera\_PreconfigType](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/capi-camera-h#camera_preconfigtype)），分别为PRECONFIG\_720P、PRECONFIG\_1080P、PRECONFIG\_4K、PRECONFIG\_HIGH\_QUALITY。以及3种画幅比例规格（[Camera\_PreconfigRatio](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/capi-camera-h#camera_preconfigratio)），1:1画幅（PRECONFIG\_RATIO\_1\_1）、4:3画幅（PRECONFIG\_RATIO\_4\_3）、16:9画幅（PRECONFIG\_RATIO\_16\_9）。

![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/82/v3/RWKeEj8AS2CORpqcOb_gBA/caution_3.0-zh-cn.png?HW-CC-KV=V1&HW-CC-Date=20260612T073517Z&HW-CC-Expire=86400&HW-CC-Sign=6BD9558B49D8E9B6A4995AEA1DF910EFD103A39EEB5C0EE2999A24E2AB8ABD59)

由于不同的设备所支持的能力不同。使用相机预配置（preconfig）功能时，需要先调用[OH\_CaptureSession\_CanPreconfig](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/capi-capture-session-h#oh_capturesession_canpreconfig)或[OH\_CaptureSession\_CanPreconfigWithRatio](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/capi-capture-session-h#oh_capturesession_canpreconfigwithratio)检查对应的PreconfigType和PreconfigRatio的组合在当前设备上是否支持。

在不同的画幅比例下，其分辨率规格不同，详见下表。

*   普通拍照模式下的预览输出
    
    | 预配置类型PreconfigType | PRECONFIG\_RATIO\_1\_1 | PRECONFIG\_RATIO\_4\_3 | PRECONFIG\_RATIO\_16\_9 |
    | :-- | :-- | :-- | :-- |
    | PRECONFIG\_720P | 720x720 | 960x720 | 1280x720 |
    | PRECONFIG\_1080P | 1080x1080 | 1440x1080 | 1920x1080 |
    | PRECONFIG\_4K | 1080x1080 | 1440x1080 | 1920x1080 |
    | PRECONFIG\_HIGH\_QUALITY | 1440x1440 | 1920x1440 | 2560x1440 |
    
*   普通拍照模式下的拍照输出
    
    | 预配置类型PreconfigType | PRECONFIG\_RATIO\_1\_1 | PRECONFIG\_RATIO\_4\_3 | PRECONFIG\_RATIO\_16\_9 |
    | :-- | :-- | :-- | :-- |
    | PRECONFIG\_720P | 720x720 | 960x720 | 1280x720 |
    | PRECONFIG\_1080P | 1080x1080 | 1440x1080 | 1920x1080 |
    | PRECONFIG\_4K | 2160x2160 | 2880x2160 | 3840x2160 |
    | PRECONFIG\_HIGH\_QUALITY | 跟随Sensor最大能力 | 跟随Sensor最大能力 | 跟随Sensor最大能力 |
    
*   普通录像模式下的预览输出
    
    | 预配置类型PreconfigType | PRECONFIG\_RATIO\_1\_1 | PRECONFIG\_RATIO\_4\_3 | PRECONFIG\_RATIO\_16\_9 |
    | :-- | :-- | :-- | :-- |
    | PRECONFIG\_720P | 720x720 | 960x720 | 1280x720 |
    | PRECONFIG\_1080P | 1080x1080 | 1440x1080 | 1920x1080 |
    | PRECONFIG\_4K | 1080x1080 | 1440x1080 | 1920x1080 |
    | PRECONFIG\_HIGH\_QUALITY | 1080x1080 | 1440x1080 | 1920x1080 |
    
*   普通录像模式下的录像输出
    
    | 预配置类型PreconfigType | PRECONFIG\_RATIO\_1\_1 | PRECONFIG\_RATIO\_4\_3 | PRECONFIG\_RATIO\_16\_9 |
    | :-- | :-- | :-- | :-- |
    | PRECONFIG\_720P | 720x720 | 960x720 | 1280x720 |
    | PRECONFIG\_1080P | 1080x1080 | 1440x1080 | 1920x1080 |
    | PRECONFIG\_4K | 2160x2160 | 2880x2160 | 3840x2160 |
    | PRECONFIG\_HIGH\_QUALITY | 2160x2160 | 2880x2160 | 3840x2160 |
    
*   普通录像模式下的拍照输出
    
    | 预配置类型PreconfigType | PRECONFIG\_RATIO\_1\_1 | PRECONFIG\_RATIO\_4\_3 | PRECONFIG\_RATIO\_16\_9 |
    | :-- | :-- | :-- | :-- |
    | PRECONFIG\_720P | 跟随Sensor最大能力 | 跟随Sensor最大能力 | 跟随Sensor最大能力 |
    | PRECONFIG\_1080P | 跟随Sensor最大能力 | 跟随Sensor最大能力 | 跟随Sensor最大能力 |
    | PRECONFIG\_4K | 跟随Sensor最大能力 | 跟随Sensor最大能力 | 跟随Sensor最大能力 |
    | PRECONFIG\_HIGH\_QUALITY | 跟随Sensor最大能力 | 跟随Sensor最大能力 | 跟随Sensor最大能力 |
    

#### 开发示例

1.  在CMake脚本中链接相关动态库。
    
    target\_link\_libraries(entry PUBLIC libohcamera.so libhilog\_ndk.z.so)
    
2.  cpp侧导入NDK接口，并根据传入的SurfaceId进行拍照。
    
    #include "hilog/log.h"
    #include "ohcamera/camera.h"
    #include "ohcamera/camera\_input.h"
    #include "ohcamera/capture\_session.h"
    #include "ohcamera/photo\_output.h"
    #include "ohcamera/preview\_output.h"
    #include "ohcamera/video\_output.h"
    #include "ohcamera/camera\_manager.h"
    class NDKCamera {
    public:
        NDKCamera(char \*previewId, char \*photoId);
    };
    
    void CaptureSessionOnFocusStateChange(Camera\_CaptureSession \*session, Camera\_FocusState focusState) {
        OH\_LOG\_INFO(LOG\_APP, "CaptureSessionOnFocusStateChange");
    }
    
    void CaptureSessionOnError(Camera\_CaptureSession \*session, Camera\_ErrorCode errorCode) {
        OH\_LOG\_INFO(LOG\_APP, "CaptureSessionOnError = %{public}d", errorCode);
    }
    
    CaptureSession\_Callbacks \*GetCaptureSessionRegister(void) {
        static CaptureSession\_Callbacks captureSessionCallbacks = {.onFocusStateChange = CaptureSessionOnFocusStateChange,
                                                                   .onError = CaptureSessionOnError};
        return &captureSessionCallbacks;
    }
    
    void PreviewOutputOnFrameStart(Camera\_PreviewOutput \*previewOutput) {
        OH\_LOG\_INFO(LOG\_APP, "PreviewOutputOnFrameStart");
    }
    
    void PreviewOutputOnFrameEnd(Camera\_PreviewOutput \*previewOutput, int32\_t frameCount) {
        OH\_LOG\_INFO(LOG\_APP, "PreviewOutputOnFrameEnd = %{public}d", frameCount);
    }
    
    void PreviewOutputOnError(Camera\_PreviewOutput \*previewOutput, Camera\_ErrorCode errorCode) {
        OH\_LOG\_INFO(LOG\_APP, "PreviewOutputOnError = %{public}d", errorCode);
    }
    
    PreviewOutput\_Callbacks \*GetPreviewOutputListener(void) {
        static PreviewOutput\_Callbacks previewOutputListener = {.onFrameStart = PreviewOutputOnFrameStart,
                                                                .onFrameEnd = PreviewOutputOnFrameEnd,
                                                                .onError = PreviewOutputOnError};
        return &previewOutputListener;
    }
    
    void OnCameraInputError(const Camera\_Input \*cameraInput, Camera\_ErrorCode errorCode) {
        OH\_LOG\_INFO(LOG\_APP, "OnCameraInput errorCode = %{public}d", errorCode);
    }
    
    CameraInput\_Callbacks \*GetCameraInputListener(void) {
        static CameraInput\_Callbacks cameraInputCallbacks = {.onError = OnCameraInputError};
        return &cameraInputCallbacks;
    }
    
    void CameraManagerStatusCallback(Camera\_Manager \*cameraManager, Camera\_StatusInfo \*status) {
        OH\_LOG\_INFO(LOG\_APP, "CameraManagerStatusCallback is called");
    }
    
    CameraManager\_Callbacks \*GetCameraManagerListener() {
        static CameraManager\_Callbacks cameraManagerListener = {.onCameraStatus = CameraManagerStatusCallback};
        return &cameraManagerListener;
    }
    
    NDKCamera::NDKCamera(char \*previewId, char \*photoId) {
        Camera\_Manager \*cameraManager = nullptr;
        Camera\_Device \*cameras = nullptr;
        Camera\_CaptureSession \*captureSession = nullptr;
        Camera\_PreviewOutput \*previewOutput = nullptr;
        Camera\_PhotoOutput \*photoOutput = nullptr;
        Camera\_Input \*cameraInput = nullptr;
        uint32\_t size = 0;
        uint32\_t cameraDeviceIndex = 0;
        char \*previewSurfaceId = previewId;
        char \*photoSurfaceId = photoId;
        // 创建CameraManager对象
        Camera\_ErrorCode ret = OH\_Camera\_GetCameraManager(&cameraManager);
        if (cameraManager == nullptr || ret != CAMERA\_OK) {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_Camera\_GetCameraMananger failed.");
        }
        // 监听相机状态变化
        ret = OH\_CameraManager\_RegisterCallback(cameraManager, GetCameraManagerListener());
        if (ret != CAMERA\_OK) {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CameraManager\_RegisterCallback failed.");
        }
    
        // 获取相机列表
        ret = OH\_CameraManager\_GetSupportedCameras(cameraManager, &cameras, &size);
        if (cameras == nullptr || size < 0 || ret != CAMERA\_OK) {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CameraManager\_GetSupportedCameras failed.");
        }
    
        // 创建相机输入流
        ret = OH\_CameraManager\_CreateCameraInput(cameraManager, &cameras\[cameraDeviceIndex\], &cameraInput);
        if (cameraInput == nullptr || ret != CAMERA\_OK) {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CameraManager\_CreateCameraInput failed.");
        }
    
        // 监听cameraInput错误信息
        ret = OH\_CameraInput\_RegisterCallback(cameraInput, GetCameraInputListener());
        if (ret != CAMERA\_OK) {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CameraInput\_RegisterCallback failed.");
        }
    
        // 打开相机
        ret = OH\_CameraInput\_Open(cameraInput);
        if (ret != CAMERA\_OK) {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CameraInput\_Open failed.");
        }
    
        // 创建会话
        ret = OH\_CameraManager\_CreateCaptureSession(cameraManager, &captureSession);
        if (captureSession == nullptr || ret != CAMERA\_OK) {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CameraManager\_CreateCaptureSession failed.");
        }
    
        // 监听session错误信息
        ret = OH\_CaptureSession\_RegisterCallback(captureSession, GetCaptureSessionRegister());
        if (ret != CAMERA\_OK) {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CaptureSession\_RegisterCallback failed.");
        }
    
        // 查询Preconfig能力
        bool canPreconfigResult = false;
        ret = OH\_CaptureSession\_CanPreconfig(captureSession, PRECONFIG\_1080P, &canPreconfigResult);
        if (ret != CAMERA\_OK || !canPreconfigResult) {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CaptureSession\_CanPreconfig failed.");
        }
    
        // 配置Preconfig
        ret = OH\_CaptureSession\_Preconfig(captureSession, PRECONFIG\_1080P);
        if (ret != CAMERA\_OK) {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CaptureSession\_Preconfig failed.");
        }
    
        // 创建预览输出流,其中参数 previewSurfaceId 参考上文 XComponent 组件，预览流为XComponent组件提供的surface
        ret = OH\_CameraManager\_CreatePreviewOutputUsedInPreconfig(cameraManager, previewSurfaceId, &previewOutput);
        if (previewOutput == nullptr || ret != CAMERA\_OK) {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CameraManager\_CreatePreviewOutput failed.");
        }
    
        // 监听预览输出错误信息
        ret = OH\_PreviewOutput\_RegisterCallback(previewOutput, GetPreviewOutputListener());
        if (ret != CAMERA\_OK) {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_PreviewOutput\_RegisterCallback failed.");
        }
    
        // 创建拍照输出流，其中参数 photoSurfaceId 参考上文 ImageReceiver获取的surface
        ret = OH\_CameraManager\_CreatePhotoOutputUsedInPreconfig(cameraManager, photoSurfaceId, &photoOutput);
        if (photoOutput == nullptr || ret != CAMERA\_OK) {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CameraManager\_CreatePhotoOutput failed.");
        }
    
        // 开始配置会话
        ret = OH\_CaptureSession\_BeginConfig(captureSession);
        if (ret != CAMERA\_OK) {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CaptureSession\_BeginConfig failed.");
        }
    
        // 向会话中添加相机输入流
        ret = OH\_CaptureSession\_AddInput(captureSession, cameraInput);
        if (ret != CAMERA\_OK) {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CaptureSession\_AddInput failed.");
        }
    
        // 向会话中添加预览输出流
        ret = OH\_CaptureSession\_AddPreviewOutput(captureSession, previewOutput);
        if (ret != CAMERA\_OK) {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CaptureSession\_AddPreviewOutput failed.");
        }
    
        // 向会话中添加拍照输出流
        ret = OH\_CaptureSession\_AddPhotoOutput(captureSession, photoOutput);
        if (ret != CAMERA\_OK) {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CaptureSession\_AddPhotoOutput failed.");
        }
    
        // 提交会话配置
        ret = OH\_CaptureSession\_CommitConfig(captureSession);
        if (ret != CAMERA\_OK) {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CaptureSession\_CommitConfig failed.");
        }
    
        // 启动会话
        ret = OH\_CaptureSession\_Start(captureSession);
        if (ret != CAMERA\_OK) {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CaptureSession\_Start failed.");
        }
    
        // 判断设备是否支持闪光灯
        Camera\_FlashMode flashMode = FLASH\_MODE\_AUTO;
        bool hasFlash = false;
        ret = OH\_CaptureSession\_HasFlash(captureSession, &hasFlash);
        if (ret != CAMERA\_OK) {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CaptureSession\_HasFlash failed.");
        }
        if (hasFlash) {
            OH\_LOG\_INFO(LOG\_APP, "hasFlash success");
        } else {
            OH\_LOG\_ERROR(LOG\_APP, "hasFlash fail");
        }
        // 检测闪光灯模式是否支持
        bool isSupported = false;
        ret = OH\_CaptureSession\_IsFlashModeSupported(captureSession, flashMode, &isSupported);
        if (ret != CAMERA\_OK) {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CaptureSession\_IsFlashModeSupported failed.");
        }
        if (isSupported) {
            OH\_LOG\_INFO(LOG\_APP, "isFlashModeSupported success");
            // 设置闪光灯模式
            ret = OH\_CaptureSession\_SetFlashMode(captureSession, flashMode);
            if (ret == CAMERA\_OK) {
                OH\_LOG\_INFO(LOG\_APP, "OH\_CaptureSession\_SetFlashMode success.");
            } else {
                OH\_LOG\_ERROR(LOG\_APP, "OH\_CaptureSession\_SetFlashMode failed. %{public}d ", ret);
            }
            // 获取当前设备的闪光灯模式
            ret = OH\_CaptureSession\_GetFlashMode(captureSession, &flashMode);
            if (ret == CAMERA\_OK) {
                OH\_LOG\_INFO(LOG\_APP, "OH\_CaptureSession\_GetFlashMode success. flashMode：%{public}d ", flashMode);
            } else {
                OH\_LOG\_ERROR(LOG\_APP, "OH\_CaptureSession\_GetFlashMode failed. %d ", ret);
            }
        } else {
            OH\_LOG\_ERROR(LOG\_APP, "isFlashModeSupported fail");
        }
    
        // 判断是否支持连续自动变焦模式
        Camera\_FocusMode focusMode = FOCUS\_MODE\_CONTINUOUS\_AUTO;
        bool isFocusModeSupported = false;
        ret = OH\_CaptureSession\_IsFocusModeSupported(captureSession, focusMode, &isFocusModeSupported);
        if (ret != CAMERA\_OK) {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CaptureSession\_IsFocusModeSupported failed.");
        }
        if (isFocusModeSupported) {
            OH\_LOG\_INFO(LOG\_APP, "isFocusModeSupported success");
            ret = OH\_CaptureSession\_SetFocusMode(captureSession, focusMode);
            if (ret != CAMERA\_OK) {
                OH\_LOG\_ERROR(LOG\_APP, "OH\_CaptureSession\_SetFocusMode failed. %{public}d ", ret);
            }
            ret = OH\_CaptureSession\_GetFocusMode(captureSession, &focusMode);
            if (ret == CAMERA\_OK) {
                OH\_LOG\_INFO(LOG\_APP, "OH\_CaptureSession\_GetFocusMode success. focusMode%{public}d ", focusMode);
            } else {
                OH\_LOG\_ERROR(LOG\_APP, "OH\_CaptureSession\_GetFocusMode failed. %d ", ret);
            }
        } else {
            OH\_LOG\_ERROR(LOG\_APP, "isFocusModeSupported fail");
        }
    
        // 获取相机支持的可变焦距比范围
        float minZoom;
        float maxZoom;
        ret = OH\_CaptureSession\_GetZoomRatioRange(captureSession, &minZoom, &maxZoom);
        if (ret != CAMERA\_OK) {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CaptureSession\_GetZoomRatioRange failed.");
        } else {
            OH\_LOG\_INFO(LOG\_APP, "OH\_CaptureSession\_GetZoomRatioRange success. minZoom: %{public}f, maxZoom:%{public}f",
                        minZoom, maxZoom);
        }
        // 设置变焦
        ret = OH\_CaptureSession\_SetZoomRatio(captureSession, maxZoom);
        if (ret == CAMERA\_OK) {
            OH\_LOG\_INFO(LOG\_APP, "OH\_CaptureSession\_SetZoomRatio success.");
        } else {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CaptureSession\_SetZoomRatio failed. %{public}d ", ret);
        }
        // 获取当前设备的变焦值
        ret = OH\_CaptureSession\_GetZoomRatio(captureSession, &maxZoom);
        if (ret == CAMERA\_OK) {
            OH\_LOG\_INFO(LOG\_APP, "OH\_CaptureSession\_GetZoomRatio success. zoom：%{public}f ", maxZoom);
        } else {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CaptureSession\_GetZoomRatio failed. %{public}d ", ret);
        }
    
        // 无拍照设置进行拍照
        ret = OH\_PhotoOutput\_Capture(photoOutput);
        if (ret == CAMERA\_OK) {
            OH\_LOG\_INFO(LOG\_APP, "OH\_PhotoOutput\_Capture success ");
        } else {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_PhotoOutput\_Capture failed. %d ", ret);
        }
    
        // 停止当前会话
        ret = OH\_CaptureSession\_Stop(captureSession);
        if (ret == CAMERA\_OK) {
            OH\_LOG\_INFO(LOG\_APP, "OH\_CaptureSession\_Stop success ");
        } else {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CaptureSession\_Stop failed. %d ", ret);
        }
    
        // 释放相机输入流
        ret = OH\_CameraInput\_Close(cameraInput);
        if (ret == CAMERA\_OK) {
            OH\_LOG\_INFO(LOG\_APP, "OH\_CameraInput\_Close success ");
        } else {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CameraInput\_Close failed. %d ", ret);
        }
    
        // 释放预览输出流
        ret = OH\_PreviewOutput\_Release(previewOutput);
        if (ret == CAMERA\_OK) {
            OH\_LOG\_INFO(LOG\_APP, "OH\_PreviewOutput\_Release success ");
        } else {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_PreviewOutput\_Release failed. %d ", ret);
        }
    
        // 释放拍照输出流
        ret = OH\_PhotoOutput\_Release(photoOutput);
        if (ret == CAMERA\_OK) {
            OH\_LOG\_INFO(LOG\_APP, "OH\_PhotoOutput\_Release success ");
        } else {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_PhotoOutput\_Release failed. %d ", ret);
        }
    
        // 释放会话
        ret = OH\_CaptureSession\_Release(captureSession);
        if (ret == CAMERA\_OK) {
            OH\_LOG\_INFO(LOG\_APP, "OH\_CaptureSession\_Release success ");
        } else {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CaptureSession\_Release failed. %d ", ret);
        }
    
        // 资源释放
        ret = OH\_CameraManager\_DeleteSupportedCameras(cameraManager, cameras, size);
        if (ret != CAMERA\_OK) {
            OH\_LOG\_ERROR(LOG\_APP, "Delete Cameras failed.");
        } else {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_CameraManager\_DeleteSupportedCameras. ok");
        }
    
        ret = OH\_Camera\_DeleteCameraManager(cameraManager);
        if (ret != CAMERA\_OK) {
            OH\_LOG\_ERROR(LOG\_APP, "Delete Cameras failed.");
        } else {
            OH\_LOG\_ERROR(LOG\_APP, "OH\_Camera\_DeleteCameraManager. ok");
        }
    }