简体   繁体   中英

Android camera2: how ho to get Image from a defined cameraId?

I use the following android code CameraManager service:

CameraManager cameraManager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);

String[] cameraIdList = cameraManager.getCameraIdList();

Now, I want to get the image from one of the cameraIds in this list in order to be able to execute the following code on this image:

ShortBuffer shortDepthBuffer = image.getPlanes()[0].getBuffer().asShortBuffer();

How can I get this Image from a defined cameraId ?

Thanks !

There is no fast and easy way to do this with the Camera2 API. For a particular cameraId you need to:

  1. Open camera device: cameraManager.openCamera(...)
  2. Once the device is opened, use it to create capture session: cameraDevice.createCaptureSession(...)
  3. Configure ImageReader for output and create capture request:: cameraDevice.createCaptureRequest(...)
  4. Use captureSession to process your capture request: captureSession.capture(...)
  5. As the result you will obtain an Image from ImageReader that you have configured for capture output.

Therefore, for simple camera app I would suggest to look at CameraX instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM