简体   繁体   中英

How can I access the streaming camera video as bitmap or ByteBuffer in Android studio without saving it?(Java)

I am building an app in Android studio in Java where I want to access realtime video from camera without saving it and get it as a ByteBuffer. Any help will be appreciated.

It Depends on the API you use (CameraX, Camera2). If you use Camera2 API the general flow would be:

  1. Open a Camera:
val manager = getSystemService(CAMERA_SERVICE) as CameraManager
manager.openCamera(cameraId, cameraStateCallback, cameraHandler)
  1. Wait for the camera to open:
private val cameraStateCallback: CameraDevice.StateCallback = object : CameraDevice.StateCallback() {
    override fun onOpened(cameraDevice: CameraDevice) {
        //Start a capture session
    }

    override fun onDisconnected(cameraDevice: CameraDevice) {
        cameraOpenCloseLock.release()
        cameraDevice.close()
    }

    override fun onError(cameraDevice: CameraDevice, error: Int) {
        cameraOpenCloseLock.release()
        cameraDevice.close()
    }
}
  1. Then start a capture session, and using ImageReader to receive images.

You can check this project for a small basic working example of the entire flow.

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