Camera.PreviewCallback equivalent in Camera2 API

前端 未结 2 1346
忘了有多久
忘了有多久 2021-02-04 03:08

Is there any equivalent for Camera.PreviewCallback in Camera2 from API 21,better than mapping to a SurfaceTexture and pulling a Bitmap ? I need to be able to pull preview data o

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-04 03:18

    Yes, use the ImageReader class.

    Create an ImageReader using the format ImageFormat.YUV_420_888 and your desired size (make sure you select a size that's supported by the camera device you're using).

    Then use ImageReader.getSurface() for a Surface to provide to CameraDevice.createCaptureSession(), along with your other preview outputs, if any.

    Finally, in your repeating capture request, add the ImageReader provided surface as a target before setting it as the repeating request in your capture session.

提交回复
热议问题