Example #1
0
        public void CaptureStillPicture()
        {
            try
            {
                if (Device == null)
                {
                    return;
                }
                // This is the CaptureRequest.Builder that we use to take a picture.
                if (stillCaptureBuilder == null)
                {
                    stillCaptureBuilder = Device.CreateCaptureRequest(CameraTemplate.StillCapture);
                }

                stillCaptureBuilder.AddTarget(mImageReader.Surface);

                // Use the same AE and AF modes as the preview.
                stillCaptureBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.ContinuousPicture);
                SetAutoFlash(stillCaptureBuilder);

                // Orientation
                var windowManager = Context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();
                int rotation      = (int)windowManager.DefaultDisplay.Rotation;
                stillCaptureBuilder.Set(CaptureRequest.JpegOrientation, GetOrientation(rotation));

                CaptureSession.StopRepeating();
                CaptureSession.Capture(stillCaptureBuilder.Build(), new CameraCaptureStillPictureSessionCallback(this), null);
            }
            catch (CameraAccessException e)
            {
                e.PrintStackTrace();
            }
        }
        // Capture a still picture. This method should be called when we get a response in
        // {@link #mCaptureCallback} from both {@link #lockFocus()}.
        public void CaptureStillPicture()
        {
            try
            {
                var activity = Activity;
                if (null == activity || null == CameraDevice)
                {
                    return;
                }

                // This is the CaptureRequest.Builder that we use to take a picture.
                //if (_stillCaptureBuilder == null)
                //{
                _stillCaptureBuilder = CameraDevice.CreateCaptureRequest(CameraTemplate.StillCapture);
                //}

                _stillCaptureBuilder.AddTarget(_imageReader.Surface);

                // Use the same AE and AF modes as the preview.
                _stillCaptureBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.ContinuousPicture);
                SetAutoFlash(_stillCaptureBuilder);

                CaptureSession.StopRepeating();
                CaptureSession.Capture(_stillCaptureBuilder.Build(), new CameraCaptureStillPictureSessionCallback(this), null);
            }
            catch (CameraAccessException ex)
            {
#if DEBUG
                ex.PrintStackTrace();
#endif
            }
        }
Example #3
0
        /// <summary>
        /// Capture a still picture. This method should be called when we get a response in
        /// CaptureCallback from both LockFocus()
        /// </summary>
        public void CaptureStillPicture()
        {
            try
            {
                var activity = Activity;
                if (null == activity || null == CameraDevice)
                {
                    return;
                }
                // This is the CaptureRequest.Builder that we use to take a picture.
                CaptureRequest.Builder captureBuilder =
                    CameraDevice.CreateCaptureRequest(CameraTemplate.StillCapture);
                captureBuilder.AddTarget(mImageReader.Surface);

                // Use the same AE and AF modes as the preview.
                captureBuilder.Set(CaptureRequest.ControlAfMode,
                                   (int)ControlAFMode.ContinuousPicture);
                SetAutoFlash(captureBuilder);

                // Orientation
                int rotation = (int)activity.WindowManager.DefaultDisplay.Rotation;
                captureBuilder.Set(CaptureRequest.JpegOrientation, GetOrientation(rotation));

                var captureCallback = new CameraCaptureSessionCaptureCallback2(this);

                CaptureSession.StopRepeating();
                CaptureSession.Capture(captureBuilder.Build(), captureCallback, null);
            }
            catch (CameraAccessException e)
            {
                e.PrintStackTrace();
            }
        }
        // Closes the current {@link CameraDevice}.
        protected void CloseCamera()
        {
            if (CaptureSession == null)
            {
                return;
            }

            try
            {
                CameraOpenCloseLock.Acquire();
                if (null != CaptureSession)
                {
                    try
                    {
                        CaptureSession.StopRepeating();
                        CaptureSession.AbortCaptures();
                    }
                    catch (CameraAccessException ex)
                    {
#if DEBUG
                        ex.PrintStackTrace();
#endif
                    }
                    catch (IllegalStateException ex)
                    {
#if DEBUG
                        ex.PrintStackTrace();
#endif
                    }

                    CaptureSession.Close();
                    CaptureSession = null;
                }

                if (null != CameraDevice)
                {
                    CameraDevice.Close();
                    CameraDevice = null;
                }

                if (null != _imageReader)
                {
                    _imageReader.Close();
                    _imageReader = null;
                }
            }
            catch (InterruptedException ex)
            {
                throw new RuntimeException("Interrupted while trying to lock camera closing.", ex);
            }
            finally
            {
                CameraOpenCloseLock.Release();
            }
        }