Skip to content Skip to sidebar Skip to footer

Android Camera2 Getpreviewframe

I am trying to get the camera frame in preview mode. I am running the sample project from github https://github.com/googlesamples/android-Camera2Basic The issue I am having is gett

Solution 1:

The OnImageAvailableListener.onImageAvailable callback is never called when a preview frame is available because the CaptureRequest which was sent to the CameraCaptureSession.setRepeatingRequest() method did not list the ImageReader's Surface as an output target.

You identify what output Surfaces (raw byte buffers, essentially) you want the data of each capture to go to when you send the request to the camera. So to get the "preview frames" to trigger the onImageAvailable() callback and then be sent to your onPreviewFrame() method, simply add the line:

mPreviewRequestBuilder.addTarget(mImageReader.getSurface());

This line can go, e.g., after the other similar line that adds the SurfaceTexture's Surface to the same request builder.

Note that this will send every preview frame to your function, as well as the "output frames" from the capture button. You may want some code in the onImageAvailable() callback to discriminate.

Post a Comment for "Android Camera2 Getpreviewframe"