• Lv0
    粉丝14

积分431 / 贡献0

提问1答案被采纳32文章4

作者动态

    如何获取前置摄像头的预览图像?

    hyacinth养花人 显示全部楼层 发表于 2023-8-30 09:30:45

    【问题描述】

    前置摄像头的预览图像功能,在OpenHarmony中如何实现?

    【运行环境】

    硬件:rk3568; ROM: 3.2 Release; API 9

    您尚未登录,无法参与评论,登录后可以:
    参与开源共建问题交流
    认同或收藏高质量问答
    获取积分成为开源共建先驱

    精彩评论1

    admin

    沙发 发表于 2023-8-30 09:32:42
    按照以下步骤操作:
    1.使用系统相机框架@ohos.multimedia.camera获取物理摄像头信息
    1. let cameraManager = await camera.getCameraManager(context);
    2. let camerasInfo = await cameraManager.getSupportedCameras();
    3. let cameraDevice = this.camerasInfo[0];
    复制代码


    2.创建并启动物理摄像头输入流通道。
    1. let cameraInput = await cameraManager.createCameraInput(cameraDevice);
    2. await this.cameraInput.open();
    复制代码


    3.拿到物理摄像头信息查询摄像头支持预览流支持的输出格式,结合XComponent提供的surfaceId创建预览输出通道
    1. let outputCapability = await this.cameraManager.getSupportedOutputCapability(cameraDevice);
    2. let previewProfile = this.outputCapability.previewProfiles[0];
    3. let previewOutput = await cameraManager.createPreviewOutput(previewProfile, previewId);
    复制代码


    4.创建相机会话,在会话中添加摄像头输入流和预览输出流,然后启动会话,预览画面就会在XComponent组件上送显。
    1. let captureSession = await cameraManager.createCaptureSession();
    2. await captureSession.beginConfig();
    3. await captureSession.addInput(cameraInput);
    4. await captureSession.addOutput(previewOutput);
    5. await this.captureSession.commitConfig()
    6. await this.captureSession.start();
    复制代码


    Copyright   ©2023  OpenHarmony开发者论坛  京ICP备2020036654号-3 |技术支持 Discuz!

    返回顶部