Exemplo n.º 1
0
        // Creates a new {@link CameraCaptureSession} for camera preview.
        public void CreateCameraPreviewSession()
        {
            try
            {
                SurfaceTexture texture = _textureView.SurfaceTexture;
                if (texture == null)
                {
                    throw new IllegalStateException("texture is null");
                }

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

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

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

                // Here, we create a CameraCaptureSession for camera preview.
                List <Surface> surfaces = new List <Surface>();
                surfaces.Add(surface);
                CurrentCameraDevice.CreateCaptureSession(surfaces, new CameraCaptureSessionCallback(this), null);
            }
            catch (CameraAccessException e)
            {
                e.PrintStackTrace();
            }
        }
Exemplo n.º 2
0
 // Closes the current {@link CurrentCameraDevice}.
 private void CloseCamera()
 {
     try
     {
         CameraOpenCloseLock.Acquire();
         if (null != CaptureSession)
         {
             CaptureSession.Close();
             CaptureSession = null;
         }
         if (null != CurrentCameraDevice)
         {
             CurrentCameraDevice.Close();
             CurrentCameraDevice = null;
         }
     }
     catch (InterruptedException e)
     {
         throw new RuntimeException("Interrupted while trying to lock camera closing.", e);
     }
     finally
     {
         CameraOpenCloseLock.Release();
     }
 }