使用Android中的Camera2 API添加/启动/停止相机预览

时间:2019-01-17 23:29:52

标签: android android-camera preview android-camera2

我看了文档和几个Android Camera2 API示例。 它们都支持在预览相机会话的过程中添加预览。例如:

cameraDevice.createCaptureSession(Collections.singletonList(previewSurface),
                new CameraCaptureSession.StateCallback() {

                    @Override
                    public void onConfigured(CameraCaptureSession cameraCaptureSession) {
                        if (cameraDevice == null) {
                            return;
                        }

                        try {
                            captureRequest = captureRequestBuilder.build();
                            CameraActivity.this.cameraCaptureSession = cameraCaptureSession;
                            CameraActivity.this.cameraCaptureSession.setRepeatingRequest(captureRequest,
                                    null, backgroundHandler);
                        } catch (CameraAccessException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onConfigureFailed(CameraCaptureSession cameraCaptureSession) {

                    }
                }, backgroundHandler);

Camera2 Android API 21级中是否可以在不重新启动会话的情况下向相机会话添加表面/纹理视图?是否可以使用Camera2启动/停止预览?

0 个答案:

没有答案