Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
0
        // 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
            {
                if (null == mCameraDevice)
                {
                    return;
                }
                // This is the CaptureRequest.Builder that we use to take a picture.

                stillCaptureBuilder = mCameraDevice.CreateCaptureRequest(CameraTemplate.StillCapture);

                stillCaptureBuilder.AddTarget(mImageReader.Surface);

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

                // Orientation
                int rotation = (int)WindowManager.DefaultDisplay.Rotation;
                var orient   = GetOrientation(rotation);
                stillCaptureBuilder.Set(CaptureRequest.JpegOrientation, orient);

                mCaptureSession.StopRepeating();
                mCaptureSession.Capture(stillCaptureBuilder.Build(), new CameraCaptureStillPictureSessionCallback(this), null);
            }
            catch (CameraAccessException e)
            {
                e.PrintStackTrace();
            }
        }
Exemplo n.º 3
0
        public void SetFlash(CaptureRequest.Builder requestBuilder)
        {
            if (mFlashSupported)
            {
                ControlAEMode sysFlashMode = 0;
                switch (mFlashMode)
                {
                case FlashMode.On:
                    flashBtn.Background = GetDrawable(Resource.Drawable.outline_flash_auto_24);
                    sysFlashMode        = ControlAEMode.On;
                    break;

                case FlashMode.Off:
                    flashBtn.Background = GetDrawable(Resource.Drawable.outline_flash_off_24);
                    sysFlashMode        = ControlAEMode.Off;
                    break;

                case FlashMode.Auto:
                    flashBtn.Background = GetDrawable(Resource.Drawable.outline_flash_on_24);
                    sysFlashMode        = ControlAEMode.OnAutoFlash;
                    break;

                default:
                    break;
                }
                requestBuilder.Set(CaptureRequest.ControlAeMode, (int)ControlAEMode.On);
                requestBuilder.Set(CaptureRequest.FlashMode, (int)sysFlashMode);
            }
        }
Exemplo n.º 4
0
        public async Task <ICameraPreview> OpenWithPreviewAsync(Xamarin.Forms.Size previewRequestSize)
        {
            await OpenAsync(true);

            var stateCallback = new StateCallback();

            stateCallback.Configured      += SessionConfigured;
            stateCallback.ConfigureFailed += SessionConfigureFailed;
            var previewSurface = _cameraPreview.CreateSurface(previewRequestSize);

            _previewRequestBuilder.AddTarget(previewSurface);
            _previewRequestBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.ContinuousPicture);

            var characteristics = _manager.GetCameraCharacteristics(_cameraDevice.Id);
            var map             = (StreamConfigurationMap)characteristics.Get(CameraCharacteristics.ScalerStreamConfigurationMap);

            // ReSharper disable once CoVariantArrayConversion
            _imageSize = (Size)Collections.Max(
                Arrays.AsList(map.GetOutputSizes((int)ImageFormatType.Jpeg)),
                new CompareSizesByArea());

            _imageReader = ImageReader.NewInstance(_imageSize.Width, _imageSize.Height,
                                                   ImageFormatType.Jpeg, /* maxImages */ 2);
            _imageAvailableListener = new ImageAvailableListener();
            _imageAvailableListener.ImageAvailable += CaptureAvailable;
            _imageReader.SetOnImageAvailableListener(_imageAvailableListener, _backgroundThread.Handler);
            var surfaces = new List <Surface> {
                previewSurface, _imageReader.Surface
            };

            _cameraDevice.CreateCaptureSession(surfaces, stateCallback, null);
            return(_cameraPreview);
        }
Exemplo n.º 5
0
        // 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 == mCameraDevice)
                {
                    return;
                }
                // This is the CaptureRequest.Builder that we use to take a picture.
                if (stillCaptureBuilder == null)
                {
                    stillCaptureBuilder = mCameraDevice.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);

                stillCaptureBuilder.Set(CaptureRequest.JpegOrientation, 90);//TODO

                mCaptureSession.StopRepeating();
                mCaptureSession.Capture(stillCaptureBuilder.Build(), new CaptureStillPictureSessionCallback(this), null);
            }
            catch (CameraAccessException e)
            {
                e.PrintStackTrace();
            }
        }
Exemplo n.º 6
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();
            }
        }
Exemplo n.º 7
0
        private void CaptureStillPicture()
        {
            try
            {
                // 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);
                Utils.SetAutoFlash(_stillCaptureBuilder, _manager, _cameraId);

                var rotation = Utils.CalculateRotation();
                _stillCaptureBuilder.Set(CaptureRequest.JpegOrientation, Utils.GetOrientation(rotation));

                _captureSession.StopRepeating();

                var stillCaptureListener = new CameraCaptureListener();
                stillCaptureListener.CaptureResultAvailable += StillCaptureHandler;
                _captureSession.Capture(_stillCaptureBuilder.Build(),
                                        stillCaptureListener, null);
            }
            catch (CameraAccessException e)
            {
                Debug.WriteLine(e);
                throw;
            }
        }
Exemplo n.º 8
0
        //Start the camera preview
        public void startPreview()
        {
            if (null == cameraDevice || !textureView.IsAvailable || null == previewSize)
            {
                return;
            }

            try
            {
                closePreviewSession();
                SurfaceTexture texture = textureView.SurfaceTexture;
                //Assert.IsNotNull(texture);

                texture.SetDefaultBufferSize(previewSize.Width, previewSize.Height);

                previewBuilder = cameraDevice.CreateCaptureRequest(CameraTemplate.Record);
                surfaces       = new List <Surface>();
                var previewSurface = new Surface(texture);
                surfaces.Add(previewSurface);
                previewBuilder.AddTarget(previewSurface);

                if (previewBuilder != null)
                {
                    if (flashon)
                    {
                        previewBuilder.Set(CaptureRequest.FlashMode, (int)FlashMode.Torch);
                    }

                    Rect sensor_rect = max;
                    int  left        = sensor_rect.Width() / 2;
                    int  right       = left;
                    int  top         = sensor_rect.Height() / 2;
                    int  bottom      = top;
                    int  hwidth      = (int)(sensor_rect.Width() / (2.0 * zoomlev));
                    int  hheight     = (int)(sensor_rect.Height() / (2.0 * zoomlev));
                    left   -= hwidth;
                    right  += hwidth;
                    top    -= hheight;
                    bottom += hheight;
                    previewBuilder.Set(CaptureRequest.ScalerCropRegion, new Rect(left, top, right, bottom));
                }

                previewBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.Off);
                previewBuilder.Set(CaptureRequest.ControlAfTrigger, (int)ControlAFTrigger.Cancel);

                //var recorderSurface = mediaRecorder.Surface;
                //surfaces.Add(recorderSurface);
                //previewBuilder.AddTarget(recorderSurface);
                mPreviewSession = new PreviewCaptureStateCallback(this, false);
                cameraDevice.CreateCaptureSession(surfaces, mPreviewSession, backgroundHandler);
            }
            catch (CameraAccessException e)
            {
                e.PrintStackTrace();
            }
            catch (IOException e)
            {
                e.PrintStackTrace();
            }
        }
Exemplo n.º 9
0
        public void AdjustFocus(int focusValue)
        {
            if (mPreviewRequestBuilder == null)
            {
                return;
            }

            if (minimumLens != null && minimumLens != 0)
            {
                mPreviewRequestBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.Off);

                float num = (((float)focusValue) * (float)minimumLens / 100);
                mPreviewRequestBuilder.Set(CaptureRequest.LensFocusDistance, num);

                mCaptureSession?.SetRepeatingRequest(mPreviewRequest = mPreviewRequestBuilder.Build(), null, mBackgroundHandler);
            }
            else if (availableFocalLenths != null && availableFocalLenths.Any())
            {
                availableFocalLenths = availableFocalLenths.OrderBy((arg) => arg).ToArray();

                mPreviewRequestBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.Off);

                float max1 = (float)availableFocalLenths.Last();//10000
                float min1 = (float)availableFocalLenths.First();

                var foc = ((focusValue * (max1 - min1)) / 100 + min1);

                mPreviewRequestBuilder.Set(CaptureRequest.LensFocalLength, foc);

                mCaptureSession?.SetRepeatingRequest(mPreviewRequest = mPreviewRequestBuilder.Build(), null, mBackgroundHandler);
            }
        }
Exemplo n.º 10
0
        public void CapturePreviewShot()
        {
            try
            {
                //final Activity activity = getActivity();
                if (null == mCameraDevice)
                {
                    return;
                }

                // This is the CaptureRequest.Builder that we use to take a picture.
                //final CaptureRequest.Builder captureBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
                CaptureRequest.Builder captureBuilder = mCameraDevice.CreateCaptureRequest(CameraTemplate.Preview);
                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)WindowManager.DefaultDisplay.Rotation;
                captureBuilder.Set(CaptureRequest.JpegOrientation, GetOrientation(rotation));

                mCaptureSession.StopRepeating();
                //mCaptureSession.Capture(captureBuilder.Build(), new CameraCapturePreviewSessionCallback(this), null);
                mCaptureSession.Capture(captureBuilder.Build(), new CameraCapturePreviewSessionCallback(this), mBackgroundHandler);
            }
            catch (CameraAccessException e)
            {
                e.PrintStackTrace();
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Updates the camera preview, StartPreview() needs to be called in advance
        /// </summary>
        private void UpdatePreview()
        {
            if (_cameraDevice != null && _previewSession != null)
            {
                try
                {
                    // The camera preview can be run in a background thread. This is a Handler for the camere preview
                    _previewBuilder.Set(CaptureRequest.ControlMode, new Java.Lang.Integer((int)ControlMode.Auto));

                    // We create a Handler since we want to handle the resulting JPEG in a background thread
                    HandlerThread thread = new HandlerThread("CameraPicture");
                    thread.Start();
                    Handler backgroundHandler = new Handler(thread.Looper);

                    // Finally, we start displaying the camera preview
                    //if (_previewSession.IsReprocessable)
                    _previewSession.SetRepeatingRequest(_previewBuilder.Build(), null, backgroundHandler);
                }
                catch (CameraAccessException error)
                {
                    Log.WriteLine(LogPriority.Error, error.Source, error.Message);
                }
                catch (IllegalStateException error)
                {
                    Log.WriteLine(LogPriority.Error, error.Source, error.Message);
                }
            }
        }
        public void TakePhoto()
        {
            var characteristics = cameraManager.GetCameraCharacteristics(CameraDevice.Id);
            var jpegSizes       = ((StreamConfigurationMap)characteristics.Get(CameraCharacteristics.ScalerStreamConfigurationMap)).GetOutputSizes((int)ImageFormatType.Jpeg);
            var width           = jpegSizes[0].Width;
            var height          = jpegSizes[0].Height;

            var reader         = ImageReader.NewInstance(width, height, ImageFormatType.Jpeg, 1);
            var outputSurfaces = new List <Surface> {
                reader.Surface
            };

            CaptureRequest.Builder captureBuilder = CameraDevice.CreateCaptureRequest(CameraTemplate.StillCapture);
            captureBuilder.AddTarget(reader.Surface);
            captureBuilder.Set(CaptureRequest.ControlMode, (int)ControlMode.Auto);

            // Orientation
            var windowManager           = Context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>();
            SurfaceOrientation rotation = windowManager.DefaultDisplay.Rotation;

            captureBuilder.Set(CaptureRequest.JpegOrientation, orientation);

            var readerListener = new ImageAvailableListener();

            readerListener.Photo += (sender, e) =>
            {
                (Element as Controls.CameraPage).SetPhotoResult(e, width, height);
            };

            HandlerThread thread = new HandlerThread("CameraPicture");

            thread.Start();
            Handler backgroundHandler = new Handler(thread.Looper);

            reader.SetOnImageAvailableListener(readerListener, backgroundHandler);

            var captureListener = new CameraCaptureListener();

            captureListener.PhotoComplete += (sender, e) =>
            {
                StartPreview();
            };

            CameraDevice.CreateCaptureSession(outputSurfaces, new CameraCaptureStateListener()
            {
                OnConfiguredAction = (CameraCaptureSession session) =>
                {
                    try
                    {
                        previewSession = session;
                        session.Capture(captureBuilder.Build(), captureListener, backgroundHandler);
                    }
                    catch (CameraAccessException ex)
                    {
                        Log.WriteLine(LogPriority.Info, "Capture Session error: ", ex.ToString());
                    }
                }
            }, backgroundHandler);
        }
Exemplo n.º 13
0
        private void UpdatePreview()
        {
            if (CameraDevice == null || previewSession == null)
            {
                return;
            }

            previewBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.ContinuousPicture);
            SetAutoFlash(previewBuilder);

            previewRequest = previewBuilder.Build();
            previewSession.SetRepeatingRequest(previewRequest, cameraCaptureListener, backgroundHandler);
        }
Exemplo n.º 14
0
        void SetUpCaptureRequestBuilder(CaptureRequest.Builder builder)
        {
            // In this sample, we just let the camera device pick the automatic settings
            builder.Set(CaptureRequest.ControlMode, new Integer((int)ControlMode.Auto));

            if (ActiveCameraDevice.Id == backCameraId)
            {
                builder.Set(CaptureRequest.FlashMode, new Integer((int)FlashMode.Off));
            }
            else if (ActiveCameraDevice.Id == frontCameraId)
            {
                builder.Set(CaptureRequest.FlashMode, new Integer((int)FlashMode.Off));
            }
        }
Exemplo n.º 15
0
        private void UpdatePreview()
        {
            if (CameraDevice == null || _previewSession == null)
            {
                return;
            }

            // Reset the auto-focus trigger
            _previewBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.ContinuousPicture);
            SetAutoFlash(_previewBuilder);

            _previewRequest = _previewBuilder.Build();
            _previewSession.SetRepeatingRequest(_previewRequest, _cameraCaptureListener, _backgroundHandler);
        }
Exemplo n.º 16
0
        // Creates a new {@link CameraCaptureSession} for camera preview.
        public void CreateCameraPreviewSession(bool builderexists = false)
        {
            try
            {
                var texture = mTextureView.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(mPreviewSize.Width, mPreviewSize.Height);

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

                // We set up a CaptureRequest.Builder with the output Surface.
                if (!builderexists)
                {
                    mPreviewRequestBuilder = mCameraDevice.CreateCaptureRequest(CameraTemplate.Preview);
                }

                //mPreviewRequestBuilder.Set(CaptureRequest.ControlAeTargetFpsRange, new Android.Util.Range(30, 120));

                mPreviewRequestBuilder.Set(CaptureRequest.ControlAeMode, (int)ControlAEMode.On);
                mPreviewRequestBuilder.Set(CaptureRequest.ControlAwbMode, (int)ControlAwbMode.Auto);
                mPreviewRequestBuilder.Set(CaptureRequest.ControlAePrecaptureTrigger, (int)ControlAEPrecaptureTrigger.Start);
                mPreviewRequestBuilder.Set(CaptureRequest.LensOpticalStabilizationMode, (int)LensOpticalStabilizationMode.On);
                mPreviewRequestBuilder.Set(CaptureRequest.EdgeMode, (int)EdgeMode.Fast);
                mPreviewRequestBuilder.Set(CaptureRequest.ShadingMode, (int)ShadingMode.HighQuality);
                mPreviewRequestBuilder.Set(CaptureRequest.TonemapMode, (int)TonemapMode.HighQuality);

                mPreviewRequestBuilder.AddTarget(surface);


                // Here, we create a CameraCaptureSession for camera preview.
                var surfaces = new List <Surface>();
                surfaces.Add(surface);
                surfaces.Add(mImageReader.Surface);

                mCameraCaptureSessionCallback = new CameraCaptureSessionCallback(this);

                mCameraDevice.CreateCaptureSession(surfaces, mCameraCaptureSessionCallback, null);
            }
            catch (CameraAccessException e)
            {
                Crashes.TrackError(e);
                e.PrintStackTrace();
            }
        }
Exemplo n.º 17
0
 private void ToggleFlashLight()
 {
     if (!mFlashLightOn)
     {
         mPreviewRequestBuilder.Set(CaptureRequest.FlashMode, (int)FlashMode.Torch);
         mFlashLightOn = true;
     }
     else
     {
         mPreviewRequestBuilder.Set(CaptureRequest.FlashMode, (int)FlashMode.Off);
         mFlashLightOn = false;
     }
     mPreviewRequest = mPreviewRequestBuilder.Build();
     mCaptureSession.SetRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler);
 }
 // Lock the focus as the first step for a still image capture.
 private void LockFocus()
 {
     try
     {
         mPreviewRequestBuilder.Set(CaptureRequest.ControlAfTrigger, (int)ControlAFTrigger.Start);
         // Tell #mCaptureCallback to wait for the lock.
         mState = CameraConstants.CameraStates.STATE_WAITING_LOCK;
         mCaptureSession.Capture(mPreviewRequestBuilder.Build(), mCaptureCallback,
                                 mBackgroundHandler);
     }
     catch (CameraAccessException e)
     {
         e.PrintStackTrace();
     }
 }
Exemplo n.º 19
0
 public void DisableFlash(CaptureRequest.Builder requestBuilder)
 {
     if (mFlashSupported)
     {
         requestBuilder.Set(CaptureRequest.FlashMode, (int)FlashMode.Off);
     }
 }
        // 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
            }
        }
        public void StartPreview()
        {
            if (liveTextureView.SurfaceTexture == null)
            {
                return;
            }

            var texture = liveTextureView.SurfaceTexture;

            texture.SetDefaultBufferSize(previewSize.Width, previewSize.Height);
            var surface = new Surface(texture);

            previewBuilder = CameraDevice.CreateCaptureRequest(CameraTemplate.Preview);
            previewBuilder.AddTarget(surface);

            CameraDevice.CreateCaptureSession(new List <Surface> {
                surface
            }, new CameraCaptureStateListener
            {
                OnConfigureFailedAction = (CameraCaptureSession session) =>
                {
                },
                OnConfiguredAction = (CameraCaptureSession session) =>
                {
                    previewSession = session;
                    previewBuilder.Set(CaptureRequest.ControlMode, new Java.Lang.Integer((int)ControlMode.Auto));

                    var thread = new HandlerThread("CameraPicture");
                    thread.Start();
                    var backgroundHandler = new Handler(thread.Looper);
                    previewSession.SetRepeatingRequest(previewBuilder.Build(), null, backgroundHandler);
                }
            }, null);
        }
Exemplo n.º 22
0
        public void TakePhoto()
        {
            if (_context == null || CameraDevice == null)
            {
                return;
            }

            if (_captureBuilder == null)
            {
                _captureBuilder = CameraDevice.CreateCaptureRequest(CameraTemplate.StillCapture);
            }

            _captureBuilder.AddTarget(_imageReader.Surface);

            _captureBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.ContinuousPicture);
            SetAutoFlash(_captureBuilder);

            _previewSession.StopRepeating();
            _previewSession.Capture(_captureBuilder.Build(),
                                    new CameraCaptureStillPictureSessionCallback
            {
                OnCaptureCompletedAction = session =>
                {
                    UnlockFocus();
                }
            }, null);
        }
Exemplo n.º 23
0
 protected void SetAutoFlash(CaptureRequest.Builder captureRequestBuilder)
 {
     if (FlashSupported)
     {
         captureRequestBuilder.Set(CaptureRequest.ControlAeMode, (int)ControlAEMode.OnAutoFlash);
     }
 }
Exemplo n.º 24
0
 public void SetFaceDetect(CaptureRequest.Builder requestBuilder, int faceDetectMode)
 {
     if (mFaceDetectSupported)
     {
         requestBuilder.Set(CaptureRequest.StatisticsFaceDetectMode, faceDetectMode);
     }
 }
Exemplo n.º 25
0
 public void SetAutoFlash(CaptureRequest.Builder requestBuilder)
 {
     if (mFlashSupported)
     {
         requestBuilder.Set(CaptureRequest.ControlAeMode, (int)ControlAEMode.OnAutoFlash);
     }
 }
        void OnConfigured(object sender, CameraCaptureSessionEventArgs e)
        {
            // The camera is already closed
            if (null == cameraDevice)
            {
                return;
            }

            // When the session is ready, we start displaying the preview.
            captureSession = e.Session;
            try
            {
                // Auto focus should be continuous for camera preview.
                previewRequestBuilder.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.Edof);
                // Flash is automatically enabled when necessary. For now, we skip this.
                // SetAutoFlash(previewRequestBuilder);

                // Finally, we start displaying the camera preview.
                previewRequest = previewRequestBuilder.Build();

                if (captureListener == null)
                {
                    captureListener = new CameraCaptureListener();
                    captureListener.CaptureCompleted  += OnCaptureCompleted;
                    captureListener.CaptureProgressed += OnCaptureProgressed;
                }
                captureSession.SetRepeatingRequest(previewRequest, captureListener, backgroundHandler);
            }
            catch (CameraAccessException ex)
            {
                ex.PrintStackTrace();
            }
        }
Exemplo n.º 27
0
        //public override void OnCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result)
        //{
        //    //if (_isReady)
        //    //    TakePicture();
        //}

        private void TakePicture()
        {
            //_isReady = false;
            if (_stillImageListener.IsBusy)
            {
                return;
            }

            CaptureRequest.Builder captureRequest = _session.Device.CreateCaptureRequest(CameraTemplate.StillCapture);
            captureRequest.Set(CaptureRequest.ControlAfMode, (int)ControlAFMode.ContinuousPicture);
            captureRequest.Set(CaptureRequest.JpegOrientation, 90);

            captureRequest.AddTarget(_reader.Surface);
            CaptureRequest stillImageRequest = captureRequest.Build();

            _session.Capture(stillImageRequest, _emptyCaptureCallback, new Handler(message => { }));
        }
Exemplo n.º 28
0
 public static void SetAutoFlash(CaptureRequest.Builder requestBuilder,
                                 Android.Hardware.Camera2.CameraManager cameraManager, string cameraId)
 {
     if (IsFlashSupported(cameraManager, cameraId))
     {
         requestBuilder.Set(CaptureRequest.ControlAeMode, (int)ControlAEMode.OnAutoFlash);
     }
 }
Exemplo n.º 29
0
 public void SetAutoFlash(CaptureRequest.Builder requestBuilder)
 {
     if (flashSupported)
     {
         var mode = IsFlashEnabled ? (int)ControlAEMode.OnAutoFlash : (int)ControlAEMode.Off;
         requestBuilder.Set(CaptureRequest.ControlAeMode, mode);
     }
 }
Exemplo n.º 30
0
 // Lock the focus as the first step for a still image capture.
 public void LockFocus()
 {
     try
     {
         // This is how to tell the camera to lock focus.
         mPreviewRequestBuilder.Set(CaptureRequest.ControlAfTrigger, (int)ControlAFTrigger.Start);
         // Tell #mCaptureCallback to wait for the lock.
         mState = STATE_WAITING_LOCK;
         //mCaptureSession.Capture(mPreviewRequestBuilder.Build(), mCaptureCallback,
         //mBackgroundHandler);
         CaptureStillPicture();
     }
     catch (CameraAccessException e)
     {
         e.PrintStackTrace();
     }
 }