VoiceCamera.CameraFragment.StartPreview C# (CSharp) Метод

StartPreview() приватный Метод

Starts the camera previe
private StartPreview ( ) : void
Результат void
        private void StartPreview()
        {
            if (mCameraDevice == null || !mTextureView.IsAvailable || mPreviewSize == null) {
                return;
            }
            try
            {
                SurfaceTexture texture = mTextureView.SurfaceTexture;
                System.Diagnostics.Debug.Assert( texture != null );

                // We configure the size of the default buffer to be the size of the camera preview we want
                texture.SetDefaultBufferSize(mPreviewSize.Width, mPreviewSize.Height);

                // This is the output Surface we need to start the preview
                Surface surface = new Surface(texture);

                // We set up a CaptureRequest.Builder with the output Surface
                mPreviewBuilder = mCameraDevice.CreateCaptureRequest(CameraTemplate.Preview);
                mPreviewBuilder.AddTarget(surface);

                // Here, we create a CameraCaptureSession for camera preview.
                mCameraDevice.CreateCaptureSession(new List<Surface>() { surface },
                    new CameraCaptureStateListener()
                    {
                        OnConfigureFailedAction = (CameraCaptureSession session) =>
                            {
                                Activity activity = Activity;
                                if (activity != null)
                                {
                                    Toast.MakeText(activity, "Failed", ToastLength.Short).Show();
                                }
                            },
                        OnConfiguredAction = (CameraCaptureSession session) =>
                            {
                                mPreviewSession = session;
                                UpdatePreview ();
                            }
                    },
                    null);

            }
            catch (CameraAccessException ex) {
                Log.WriteLine (LogPriority.Info, "Camera2BasicFragment", ex.StackTrace);
            }
        }

Usage Example

Пример #1
0
 public override void OnOpened(CameraDevice camera)
 {
     if (Fragment != null)
     {
         Fragment.mCameraDevice = camera;
         Fragment.StartPreview();
         Fragment.mOpeningCamera = false;
     }
 }
All Usage Examples Of VoiceCamera.CameraFragment::StartPreview