I am working on a project which uses CameraX to show the camera preview on a TextureView
. The code hails from this codelab. I have used the setOnPreviewOutputUpdateListener()
method to update the TextureView
.
private fun startCamera() {
val previewConfig = PreviewConfig.Builder().apply {
setTargetAspectRatio( Rational( 1 , 1 ) )
setTargetResolution( Size( 640 , 640 ) )
}.build()
val preview = Preview( previewConfig )
preview.setOnPreviewOutputUpdateListener {
val parent = cameraTextureView?.parent as ViewGroup
parent.removeView( cameraTextureView )
cameraTextureView?.surfaceTexture = it.surfaceTexture
parent.addView( cameraTextureView , 0)
updateTransform()
}
preview.removePreviewOutputListener()
CameraX.bindToLifecycle( this , preview )
}
My question is how do I get the raw byte[]
object from preview frames using CameraX. I expect something which is similar to onPreviewFrame(byte[] data, Camera camera)
method.
Basically, I want the realtime frames ( in
byte[]
orBitmap
) from the preview using CameraX.