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 getting the frame in preview mode.
Here is the code:
private CameraCaptureSession.CaptureCallback mCaptureCallback = new CameraCaptureSession.CaptureCallback() {
private void process(CaptureResult result) {
switch (mState) {
case STATE_PREVIEW: {
//HERE, HOW CAN I RETRIEVE THE CURRENT FRAME?
break;
}
case STATE_WAITING_LOCK: {
...
break;
}
case STATE_WAITING_PRECAPTURE: {
...
break;
}
case STATE_WAITING_NON_PRECAPTURE: {
...
break;
}
}
}
Another thing I tried to get the frame is setting the mImageReader.setOnImageAvailableListener. I was expecting to be able to get the frame onImageAvailable callback, but onImageAvailable is never called. onPreviewFrame is my own method, I need to pass it the current frame.
mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG, /*maxImages*/2);
mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler);
private final ImageReader.OnImageAvailableListener mOnImageAvailableListener = new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader reader) {
mTextureView.onPreviewFrame(reader.acquireNextImage().getPlanes([0].getBuffer().array());
}
};
What I am doing wrong? Thanks.