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

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

阅读 641
1 个回答

解决措施

  1. 使用系统相机框架camera模块获取物理摄像头信息。
let cameraManager = await camera.getCameraManager(context); 
let camerasInfo = await cameraManager.getSupportedCameras(); 
let cameraDevice = this.camerasInfo[0];
  1. 创建并启动物理摄像头输入流通道。
let cameraInput = await cameraManager.createCameraInput(cameraDevice); 
await this.cameraInput.open();
  1. 拿到物理摄像头信息查询摄像头支持预览流支持的输出格式,结合XComponent提供的surfaceId创建预览输出通道。
let outputCapability = await this.cameraManager.getSupportedOutputCapability(cameraDevice); 
let previewProfile = this.outputCapability.previewProfiles[0]; 
let previewOutput = await cameraManager.createPreviewOutput(previewProfile, previewId);
  1. 创建相机会话,在会话中添加摄像头输入流和预览输出流,然后启动会话,预览画面就会在XComponent组件上送显。
let captureSession = await cameraManager.createCaptureSession(); 
await captureSession.beginConfig(); 
await captureSession.addInput(cameraInput); 
await captureSession.addOutput(previewOutput); 
await this.captureSession.commitConfig() 
await this.captureSession.start();

参考链接

拍照实现方案

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进