示例#1
0
        // set hardware properties
        public void ConfigureCameraForDevice(AVCaptureDevice device)
        {
            var error = new NSError();

            // set manual focus
            if (device.IsFocusModeSupported(AVCaptureFocusMode.ContinuousAutoFocus))
            {
                device.LockForConfiguration(out error);
                device.FocusMode = AVCaptureFocusMode.ContinuousAutoFocus;
                device.UnlockForConfiguration();
            }
            // set continuous auto exposure
            else if (device.IsExposureModeSupported(AVCaptureExposureMode.ContinuousAutoExposure))
            {
                device.LockForConfiguration(out error);
                device.ExposureMode = AVCaptureExposureMode.ContinuousAutoExposure;
                device.UnlockForConfiguration();
            }
            // set continuous auto white balance
            else if (device.IsWhiteBalanceModeSupported(AVCaptureWhiteBalanceMode.ContinuousAutoWhiteBalance))
            {
                device.LockForConfiguration(out error);
                device.WhiteBalanceMode = AVCaptureWhiteBalanceMode.ContinuousAutoWhiteBalance;
                device.UnlockForConfiguration();
            }
        }
        public void ConfigureCameraForDevice(AVCaptureDevice device)
        {
            var error = new NSError();

            if (device != null)
            {
                if (device.IsFocusModeSupported(AVCaptureFocusMode.ContinuousAutoFocus))
                {
                    device.LockForConfiguration(out error);
                    device.FocusMode = AVCaptureFocusMode.ContinuousAutoFocus;
                    device.UnlockForConfiguration();
                }
                else if (device.IsExposureModeSupported(AVCaptureExposureMode.ContinuousAutoExposure))
                {
                    device.LockForConfiguration(out error);
                    device.ExposureMode = AVCaptureExposureMode.ContinuousAutoExposure;
                    device.UnlockForConfiguration();
                }
                else if (device.IsWhiteBalanceModeSupported(AVCaptureWhiteBalanceMode.ContinuousAutoWhiteBalance))
                {
                    device.LockForConfiguration(out error);
                    device.WhiteBalanceMode = AVCaptureWhiteBalanceMode.ContinuousAutoWhiteBalance;
                    device.UnlockForConfiguration();
                }
            }
        }
 public void ConfigureCameraForDevice(AVCaptureDevice device)
 {
     try
     {
         var error = new NSError();
         if (device.IsFocusModeSupported(AVCaptureFocusMode.ContinuousAutoFocus))
         {
             device.LockForConfiguration(out error);
             device.FocusMode = AVCaptureFocusMode.ContinuousAutoFocus;
             device.UnlockForConfiguration();
         }
         else if (device.IsExposureModeSupported(AVCaptureExposureMode.ContinuousAutoExposure))
         {
             device.LockForConfiguration(out error);
             device.ExposureMode = AVCaptureExposureMode.ContinuousAutoExposure;
             device.UnlockForConfiguration();
         }
         else if (device.IsWhiteBalanceModeSupported(AVCaptureWhiteBalanceMode.ContinuousAutoWhiteBalance))
         {
             device.LockForConfiguration(out error);
             device.WhiteBalanceMode = AVCaptureWhiteBalanceMode.ContinuousAutoWhiteBalance;
             device.UnlockForConfiguration();
         }
     }
     catch (Exception message)
     {
         Debug.WriteLine(message.ToString());
     }
 }
        public void ConfigureCameraForDevice(AVCaptureDevice device)
        {
            var error         = new NSError();
            var photoSettings = AVCapturePhotoSettings.Create();

            photoSettings.FlashMode = AVCaptureFlashMode.Auto;
            photoSettings.IsHighResolutionPhotoEnabled = true;

            if (device.IsFocusModeSupported(AVCaptureFocusMode.ContinuousAutoFocus))
            {
                device.LockForConfiguration(out error);
                device.FocusMode = AVCaptureFocusMode.ContinuousAutoFocus;
                device.UnlockForConfiguration();
            }
            else if (device.IsExposureModeSupported(AVCaptureExposureMode.ContinuousAutoExposure))
            {
                device.LockForConfiguration(out error);
                device.ExposureMode = AVCaptureExposureMode.ContinuousAutoExposure;
                device.UnlockForConfiguration();
            }
            else if (device.IsWhiteBalanceModeSupported(AVCaptureWhiteBalanceMode.ContinuousAutoWhiteBalance))
            {
                device.LockForConfiguration(out error);
                device.WhiteBalanceMode = AVCaptureWhiteBalanceMode.ContinuousAutoWhiteBalance;
                device.UnlockForConfiguration();
            }
        }
示例#5
0
        public void SetAutoFocus()
        {
            var error = new NSError();

            if (device.IsFocusModeSupported(AVCaptureFocusMode.ContinuousAutoFocus))
            {
                device.LockForConfiguration(out error);
                device.FocusMode = AVCaptureFocusMode.ContinuousAutoFocus;
                device.UnlockForConfiguration();
            }
        }
示例#6
0
        void updateCameraSelection()
        {
            session.BeginConfiguration();

            AVCaptureInput[] oldInputs = session.Inputs;
            foreach (var oldInput in oldInputs)
            {
                session.RemoveInput(oldInput);
            }

            AVCaptureDeviceInput input = pickCamera();

            if (input == null)
            {
                foreach (var oldInput in oldInputs)
                {
                    session.AddInput(oldInput);
                }
            }
            else
            {
                session.AddInput(input);
                device = input.Device;

                NSError error;
                if (!device.LockForConfiguration(out error))
                {
                    Console.WriteLine("Could not lock for device: " + error.LocalizedDescription);
                }

                updateAVFoundationFaceDetection();
            }

            session.CommitConfiguration();
        }
        /// <summary>
        /// Set the device's focus settings
        /// </summary>
        /// <returns><see cref="T:ChilliSource.Mobile.Core.OperationResult"/> instance indicating the outcome of the operation</returns>
        /// <param name="videoDeviceInput">Video device input.</param>
        /// <param name="focusMode">Focus mode.</param>
        /// <param name="exposureMode">Exposure mode.</param>
        /// <param name="pointOfInterest">Point of interest</param>
        /// <param name="monitorSubjectAreaChange">If set to <c>true</c> monitor subject area change.</param>
        public static OperationResult UpdateFocus(this AVCaptureDeviceInput videoDeviceInput, AVCaptureFocusMode focusMode,
                                                  AVCaptureExposureMode exposureMode, CGPoint pointOfInterest, bool monitorSubjectAreaChange)
        {
            if (videoDeviceInput == null)
            {
                return(OperationResult.AsFailure("device input is null"));
            }

            AVCaptureDevice device = videoDeviceInput.Device;
            NSError         error;

            if (device.LockForConfiguration(out error))
            {
                if (device.FocusPointOfInterestSupported && device.IsFocusModeSupported(focusMode))
                {
                    device.FocusPointOfInterest = pointOfInterest;
                    device.FocusMode            = focusMode;
                }
                if (device.ExposurePointOfInterestSupported && device.IsExposureModeSupported(exposureMode))
                {
                    device.ExposurePointOfInterest = pointOfInterest;
                    device.ExposureMode            = exposureMode;
                }
                device.SubjectAreaChangeMonitoringEnabled = monitorSubjectAreaChange;
                device.UnlockForConfiguration();
                return(OperationResult.AsSuccess());
            }
            else
            {
                return(OperationResult.AsFailure(string.Format("Could not lock device for configuration: {0}", error)));
            }
        }
示例#8
0
        void UpdateDeviceFocus(AVCaptureFocusMode focusMode, AVCaptureExposureMode exposureMode, CGPoint point, bool monitorSubjectAreaChange)
        {
            SessionQueue.DispatchAsync(() => {
                if (VideoDeviceInput == null)
                {
                    return;
                }

                AVCaptureDevice device = VideoDeviceInput.Device;
                NSError error;
                if (device.LockForConfiguration(out error))
                {
                    // Setting (Focus/Exposure)PointOfInterest alone does not initiate a (focus/exposure) operation.
                    // Set (Focus/Exposure)Mode to apply the new point of interest.
                    if (device.FocusPointOfInterestSupported && device.IsFocusModeSupported(focusMode))
                    {
                        device.FocusPointOfInterest = point;
                        device.FocusMode            = focusMode;
                    }
                    if (device.ExposurePointOfInterestSupported && device.IsExposureModeSupported(exposureMode))
                    {
                        device.ExposurePointOfInterest = point;
                        device.ExposureMode            = exposureMode;
                    }
                    device.SubjectAreaChangeMonitoringEnabled = monitorSubjectAreaChange;
                    device.UnlockForConfiguration();
                }
                else
                {
                    Console.WriteLine("Could not lock device for configuration: {0}", error);
                }
            });
        }
示例#9
0
        /// <summary>
        /// Sets the device's frame rate
        /// </summary>
        /// <returns><see cref="T:ChilliSource.Mobile.Core.OperationResult"/> instance indicating the outcome of the operation</returns>
        /// <param name="device">Device.</param>
        /// <param name="frameRate">Frame rate.</param>
        /// <param name="timeValue">Time value.</param>
        public static OperationResult SetFrameRate(this AVCaptureDevice device, int frameRate, int timeValue = 1)
        {
            NSError error = null;

            if (!device.LockForConfiguration(out error))
            {
                return(OperationResult.AsFailure(error?.LocalizedDescription ?? "Could not lock configuration"));
            }

            double epsilon = 0.00000001;

            bool frameRateSet = false;

            foreach (var range in device.ActiveFormat.VideoSupportedFrameRateRanges)
            {
                if (range.MinFrameRate <= frameRate + epsilon && range.MaxFrameRate >= frameRate - epsilon)
                {
                    device.ActiveVideoMaxFrameDuration = new CoreMedia.CMTime(timeValue, frameRate);
                    device.ActiveVideoMinFrameDuration = new CoreMedia.CMTime(timeValue, frameRate);
                    frameRateSet = true;
                    break;
                }
            }

            device.UnlockForConfiguration();
            return(frameRateSet ? OperationResult.AsSuccess() : OperationResult.AsFailure("Frame rate is not supported"));
        }
示例#10
0
        void SetFrameRate()
        {
            // Based on code from https://github.com/dokun1/Lumina/
            var activeDimensions = (captureDevice.ActiveFormat.FormatDescription as CMVideoFormatDescription).Dimensions;

            foreach (var vFormat in captureDevice.Formats)
            {
                var dimensions = (vFormat.FormatDescription as CMVideoFormatDescription).Dimensions;
                var ranges     = vFormat.VideoSupportedFrameRateRanges;
                var frameRate  = ranges[0];

                if (frameRate.MaxFrameRate >= (double)targetFramerate &&
                    frameRate.MinFrameRate <= (double)targetFramerate &&
                    activeDimensions.Width == dimensions.Width &&
                    activeDimensions.Height == dimensions.Height &&
                    vFormat.FormatDescription.MediaSubType == 875704422)                     // meant for full range 420f
                {
                    try
                    {
                        NSError error;
                        captureDevice.LockForConfiguration(out error);
                        captureDevice.ActiveFormat = vFormat as AVCaptureDeviceFormat;
                        captureDevice.ActiveVideoMinFrameDuration = new CMTime(1, targetFramerate);
                        captureDevice.ActiveVideoMaxFrameDuration = new CMTime(1, targetFramerate);
                        captureDevice.UnlockForConfiguration();
                    }
                    catch (Exception ex)
                    {
                        continue;
                    }
                }

                Console.WriteLine("Camera format: " + captureDevice.ActiveFormat);
            }
        }
示例#11
0
        public void ConfigureCameraForDevice(AVCaptureDevice device)
        {
            var error = new NSError();

            if (device.IsFocusModeSupported(AVCaptureFocusMode.ContinuousAutoFocus))
            {
                device.LockForConfiguration(out error);
                device.FocusMode = AVCaptureFocusMode.ContinuousAutoFocus;
                device.UnlockForConfiguration();
            }
            else if (device.AutoFocusRangeRestrictionSupported)
            {
                device.LockForConfiguration(out error);
                device.AutoFocusRangeRestriction = AVCaptureAutoFocusRangeRestriction.Near;
                device.UnlockForConfiguration();
            }
        }
示例#12
0
 public void onClickFlash()
 {
     if (!flashOn)
     {
         device.LockForConfiguration(out error);
         device.TorchMode = AVCaptureTorchMode.On;
         device.UnlockForConfiguration();
         flashOn = true;
     }
     else
     {
         device.LockForConfiguration(out error);
         device.TorchMode = AVCaptureTorchMode.Off;
         device.UnlockForConfiguration();
         flashOn = false;
     }
 }
 private NSError SetFlashOff(AVCaptureDevice device)
 {
     NSError error;
     device.LockForConfiguration(out error);
     device.FlashMode = AVCaptureFlashMode.Off;
     device.UnlockForConfiguration();
     _toggleFlashButton.SetBackgroundImage(UIImage.FromFile("NoFlashButton.png"), UIControlState.Normal);
     return error;
 }
示例#14
0
        /// <summary>
        /// Switchs the flash.
        /// </summary>
        /// <param name="flashOn">If set to <c>true</c> flash on.</param>
        public void SwitchFlash(bool flashOn)
        {
            NSError err;

            if (_cameraAvailable && _device != null)
            {
                try
                {
                    _device.LockForConfiguration(out err);
                    _device.TorchMode = flashOn ? AVCaptureTorchMode.On : AVCaptureTorchMode.Off;
                    _device.UnlockForConfiguration();
                }
                catch (Exception error)
                {
                    Console.WriteLine(error.Message);
                }
            }
        }
示例#15
0
        /*
         * Setting up camera setting for EOSpec:
         * Focus: 0.3 locked : Empirically chosen for set distance to current version of EOSpec
         * ISO : Avg between max and min ISO of device
         * Exposure : Empirically set to 1/10
         * RGB gain: R and G normalized using max Gain values,
         * however Blue is normalized using min Gain value due to it saturating more than green and red channels (my phone: 1.858154 , 1 ,  1)
         */
        void ConfigureCameraForDevice(AVCaptureDevice device)
        {
            var error = new NSError();

            if (device.IsFocusModeSupported(AVCaptureFocusMode.ContinuousAutoFocus))
            {
                device.LockForConfiguration(out error);
                device.FocusMode = AVCaptureFocusMode.Locked;
                device.SetFocusModeLocked((float)0.3, null);

                Console.WriteLine("devidce device.FocusMode: " + device.FocusMode);
                device.UnlockForConfiguration();
            }

            if (device.IsExposureModeSupported(AVCaptureExposureMode.ContinuousAutoExposure))
            {
                device.LockForConfiguration(out error);
                device.ExposureMode = AVCaptureExposureMode.Custom;

                var    iso          = (device.ActiveFormat.MaxISO + device.ActiveFormat.MinISO) / 2;
                CMTime exposureTime = new CMTime(1, 10);
                device.LockExposure(exposureTime, iso, null);
                Console.WriteLine("deviceexposure: " + device.ExposureDuration + " = " + exposureTime + " iso: " + iso);

                device.UnlockForConfiguration();

                //Setting RGB gains using WhiteBalance
                device.LockForConfiguration(out error);
                AVCaptureWhiteBalanceGains gains = device.DeviceWhiteBalanceGains;
                //normalizign Gains
                gains.RedGain   = Math.Max(1, gains.RedGain);
                gains.GreenGain = Math.Max(1, gains.GreenGain);
                gains.BlueGain  = Math.Min(1, gains.BlueGain);

                float maxGain = device.MaxWhiteBalanceGain;
                gains.RedGain   = Math.Min(maxGain, gains.RedGain);
                gains.GreenGain = Math.Min(maxGain, gains.GreenGain);
                gains.BlueGain  = Math.Min(maxGain, gains.BlueGain);
                Console.WriteLine("devidce device.WhiteBalanceMode gains RGB: " + gains.RedGain + " " + gains.GreenGain + " " + gains.BlueGain);

                device.SetWhiteBalanceModeLockedWithDeviceWhiteBalanceGains(gains, null);
                device.UnlockForConfiguration();
            }
        }
示例#16
0
 partial void onClickFlahBtn(UIButton sender)
 {
     if (!flashOn)
     {
         device.LockForConfiguration(out error);
         device.TorchMode = AVCaptureTorchMode.On;
         device.UnlockForConfiguration();
         flashBtn.SetImage(UIImage.FromBundle("flashoff"), UIControlState.Normal);
         flashOn = true;
     }
     else
     {
         device.LockForConfiguration(out error);
         device.TorchMode = AVCaptureTorchMode.Off;
         device.UnlockForConfiguration();
         flashBtn.SetImage(UIImage.FromBundle("flashon"), UIControlState.Normal);
         flashOn = false;
     }
 }
示例#17
0
        public void ConfigureCameraForDevice(AVCaptureDevice device)
        {
            var error = new NSError();


            if (device.IsFocusModeSupported(AVCaptureFocusMode.ContinuousAutoFocus))
            {
                device.LockForConfiguration(out error);
                device.FocusMode = AVCaptureFocusMode.ContinuousAutoFocus;
                device.UnlockForConfiguration();
            }
            if (device.IsExposureModeSupported(AVCaptureExposureMode.ContinuousAutoExposure))
            {
                device.LockForConfiguration(out error);
                device.ExposureMode = AVCaptureExposureMode.ContinuousAutoExposure;
                device.UnlockForConfiguration();
            }

            //AdjustExposure(50);
        }
示例#18
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        private void Initialize()
        {
            var captureSession = new AVCaptureSession();

            _previewLayer = new AVCaptureVideoPreviewLayer(captureSession)
            {
                VideoGravity = AVLayerVideoGravity.ResizeAspectFill,

                Frame = Bounds
            };
            // create a device input and attach it to the session
            AVCaptureDevice frontCameraDevice = MediaDevices.FrontCamera;

            if (frontCameraDevice == null)
            {
                LoadErrors = "Cannot load camera";
                return;
            }

            try
            {
                NSError error = null;
                frontCameraDevice.LockForConfiguration(out error);
                if (error != null)
                {
                    Debug.WriteLine(error);
                    //throw new BusinessLogicException (ErrorCode.EC_UNDEFINED_ERROR, error.ToString());
                    //TODO: show error to user
                }
                frontCameraDevice.ActiveVideoMinFrameDuration = new CMTime(1, 15); // Configure for 15 FPS
            }
            finally
            {
                frontCameraDevice.UnlockForConfiguration();
            }

            AVCaptureDeviceInput inputDevice = AVCaptureDeviceInput.FromDevice(frontCameraDevice);

            if (inputDevice == null)
            {
                LoadErrors = "Cannot access front camera";
                return;
            }

            captureSession.AddInput(inputDevice);

            NSError errorOut;

            Layer.AddSublayer(_previewLayer);

            captureSession.StartRunning();
        }
示例#19
0
        //                                                  //Camera Dye and Temperature
        protected void ValueChanged(object sender, EventArgs e)
        {
            var TempAndTint = new AVCaptureWhiteBalanceTemperatureAndTintValues
                                  (this.sldTemperature.Value, this.sldTint.Value);
            var StatusDev = acdDevice.GetDeviceWhiteBalanceGains(TempAndTint);

            if (
                acdDevice.LockForConfiguration(out nsError)
                )
            {
                StatusDev = Settings(StatusDev);
                acdDevice.SetWhiteBalanceModeLockedWithDeviceWhiteBalanceGains(StatusDev, null);
                acdDevice.UnlockForConfiguration();
            }
            sldTint.BeginInvokeOnMainThread(() =>
            {
                sldTint.Value = TempAndTint.Tint;
            });
            sldTemperature.BeginInvokeOnMainThread(() =>
            {
                sldTemperature.Value =
            });
        }
示例#20
0
        /// <summary>
        /// Switchs the flash.
        /// </summary>
        /// <param name="flashOn">If set to <c>true</c> flash on.</param>
        public void SwitchFlash(bool flashOn)
        {
            NSError err;

            if (_cameraAvailable && _device != null)
            {
                try
                {
                    _device.LockForConfiguration(out err);
                    _device.TorchMode = flashOn ? AVCaptureTorchMode.On : AVCaptureTorchMode.Off;
                    _device.UnlockForConfiguration();
                }
                catch (Exception error)
                {
                    _log.WriteLineTime(_tag + "\n" +
                                       "SwitchFlash() Failed to switch flash on/off \n " +
                                       "ErrorMessage: \n" +
                                       error.Message + "\n" +
                                       "Stacktrace: \n " +
                                       error.StackTrace);
                }
            }
        }
示例#21
0
        public void toggleFlash(object sender, EventArgs e)
        {
            flashMode            = !flashMode;
            flashButton.Selected = !flashButton.Selected;
            var error = new NSError();

            //Debug.WriteLine("DHB:CameraServices_iOS:toggleFlash button state:" + flashButton.State.ToString());
            if (captureDevice.HasFlash)
            {
                if (flashMode == true)
                {
                    captureDevice.LockForConfiguration(out error);
                    captureDevice.FlashMode = AVCaptureFlashMode.On;
                    captureDevice.UnlockForConfiguration();
                }
                else
                {
                    captureDevice.LockForConfiguration(out error);
                    captureDevice.FlashMode = AVCaptureFlashMode.Off;
                    captureDevice.UnlockForConfiguration();
                }
            }
        }
示例#22
0
        void ContinuousFocus(CGPoint point)
        {
            AVCaptureDevice device = videoInput.Device;

            if (device.FocusPointOfInterestSupported && device.IsFocusModeSupported(AVCaptureFocusMode.ContinuousAutoFocus))
            {
                NSError error;
                if (device.LockForConfiguration(out error))
                {
                    device.FocusPointOfInterest = point;
                    device.FocusMode            = AVCaptureFocusMode.ContinuousAutoFocus;
                    device.UnlockForConfiguration();
                }
            }
        }
示例#23
0
        public void Expose(CGPoint point)
        {
            AVCaptureDevice device = videoInput.Device;

            if (device.ExposurePointOfInterestSupported && device.IsExposureModeSupported(AVCaptureExposureMode.ContinuousAutoExposure))
            {
                NSError error;
                if (device.LockForConfiguration(out error))
                {
                    device.ExposurePointOfInterest = point;
                    device.ExposureMode            = AVCaptureExposureMode.ContinuousAutoExposure;
                    device.UnlockForConfiguration();
                }
            }
        }
示例#24
0
        void ConfigureCameraForDevice(AVCaptureDevice device)
        {
            var error = new NSError();

            if (device.IsFocusModeSupported(AVCaptureFocusMode.ContinuousAutoFocus))
            {
                device.LockForConfiguration(out error);
                device.FocusMode = AVCaptureFocusMode.ContinuousAutoFocus;
                device.UnlockForConfiguration();
            }
            if (device.IsExposureModeSupported(AVCaptureExposureMode.ContinuousAutoExposure))
            {
                device.LockForConfiguration(out error);
                device.ExposureMode = AVCaptureExposureMode.ContinuousAutoExposure;
                device.UnlockForConfiguration();
            }
            if (device.IsWhiteBalanceModeSupported(AVCaptureWhiteBalanceMode.ContinuousAutoWhiteBalance))
            {
                device.LockForConfiguration(out error);
                device.WhiteBalanceMode = AVCaptureWhiteBalanceMode.ContinuousAutoWhiteBalance;
                device.UnlockForConfiguration();
            }
            // @todo AVCaptureDeviceFormat look into what are valid values for this.
        }
示例#25
0
 static void SetFlashModeForDevice(AVCaptureFlashMode flashMode, AVCaptureDevice device)
 {
     if (device.HasFlash && device.IsFlashModeSupported(flashMode))
     {
         NSError error;
         if (device.LockForConfiguration(out error))
         {
             device.FlashMode = flashMode;
             device.UnlockForConfiguration();
         }
         else
         {
             Console.WriteLine("Could not lock device for configuration: {0}", error);
         }
     }
 }
示例#26
0
		void CreateDevice ()
		{
			NSError error;

			device = AVCaptureDevice.DefaultDeviceWithMediaType (AVMediaType.Video);
			if (device == null) {
				throw new Exception ("No default video device");
			}

			device.LockForConfiguration(out error);
			if (error != null) {
				throw new Exception ("Could not configure. Error: " + error);
			}

			device.ActiveVideoMinFrameDuration = new CMTime (1, 30);

			device.UnlockForConfiguration();
		}
示例#27
0
        public QRCodeReaderView(QRCodeReaderViewController _thisController)
        {
            this.thisController = _thisController;

            this.BackgroundColor = UIColor.White;

            scanAnimateView = new ScanAnimateView();
            this.AddSubview(scanAnimateView);

            UIButton btnCancel = new UIButton(UIButtonType.Custom);

            btnCancel.SetTitle("Cancel", UIControlState.Normal);
            btnCancel.SetTitleColor(UIColor.LightGray, UIControlState.Highlighted);
            btnCancel.Frame = new CGRect(20, 40, 80, 20);
            this.Add(btnCancel);
            btnCancel.TouchUpInside += delegate {
                thisController.Close();
            };

            UIButton btnFlash = new UIButton(UIButtonType.Custom);

            btnFlash.SetTitle("Flash", UIControlState.Normal);
            btnFlash.SetTitleColor(UIColor.LightGray, UIControlState.Highlighted);
            btnFlash.Frame = new CGRect(UIScreen.MainScreen.Bounds.Width - 100, 40, 80, 20);
            this.Add(btnFlash);
            btnFlash.TouchUpInside += delegate {
                device.LockForConfiguration(out error);
                if (device.FlashMode == AVCaptureFlashMode.On)
                {
                    device.TorchMode = AVCaptureTorchMode.Off;
                    device.FlashMode = AVCaptureFlashMode.Off;
                }
                else
                {
                    device.TorchMode = AVCaptureTorchMode.On;
                    device.FlashMode = AVCaptureFlashMode.On;
                }
                device.UnlockForConfiguration();
            };

            Setup();
        }
示例#28
0
        void CreateDevice()
        {
            NSError error;

            device = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Video);
            if (device == null)
            {
                throw new Exception("No default video device");
            }

            device.LockForConfiguration(out error);
            if (error != null)
            {
                throw new Exception("Could not configure. Error: " + error);
            }

            device.ActiveVideoMinFrameDuration = new CMTime(1, 30);

            device.UnlockForConfiguration();
        }
        private void updateTorch(PropertyChangedEventArgs e)
        {
            if (e.PropertyName == BarcodeScanner.TorchProperty.PropertyName && device.TorchAvailable)
            {
                NSError error;
                device.LockForConfiguration(out error);

                if (error != null)
                {
                    this.Debug("Torch error");

                    return;
                }

                device.TorchMode = barcodeScanner.Torch ? AVCaptureTorchMode.On : AVCaptureTorchMode.Off;

                device.UnlockForConfiguration();
                this.Debug("Torch AVCaptureTorchMode {0}", barcodeScanner.Torch);
            }
        }
示例#30
0
 /// <summary>
 /// Sets the device's flash settings
 /// </summary>
 /// <returns><see cref="T:ChilliSource.Mobile.Core.OperationResult"/> instance indicating the outcome of the operation</returns>
 /// <param name="device">Device.</param>
 /// <param name="flashMode">Flash mode.</param>
 public static OperationResult SetFlashMode(this AVCaptureDevice device, AVCaptureFlashMode flashMode)
 {
     if (device.HasFlash && device.IsFlashModeSupported(flashMode))
     {
         NSError error;
         if (device.LockForConfiguration(out error))
         {
             device.FlashMode = flashMode;
             device.UnlockForConfiguration();
             return(OperationResult.AsSuccess());
         }
         else
         {
             return(OperationResult.AsFailure(string.Format("Could not lock device for configuration: {0}", error)));
         }
     }
     else
     {
         return(OperationResult.AsSuccess());
     }
 }
示例#31
0
        partial void OpenButton_TouchUpInside(UIButton sender)
        {
            if (mark == false)
            {
                //OpenButton.SetTitle("关闭", UIControlState.Normal);
                OpenButton.SetImage(UIImage.FromBundle("Red.png"), UIControlState.Normal);

                #region 摄像头调用
                CaptureSession = new AVCaptureSession();
                CaptureSession.SessionPreset = AVCaptureSession.PresetMedium;
                videoDevice = AVCaptureDevice.GetDefaultDevice(AVMediaType.Video);

                NSError error = null;
                videoDevice.LockForConfiguration(out error);
                if (error != null)
                {
                    videoDevice.UnlockForConfiguration();
                }
                videoDevice.TorchMode = AVCaptureTorchMode.On;
                videoDevice.UnlockForConfiguration();

                CaptureSession.StartRunning();
                #endregion
            }
            else
            {
                //OpenButton.SetTitle("打开", UIControlState.Normal);
                OpenButton.SetImage(UIImage.FromBundle("Green.png"), UIControlState.Normal);
                NSError error = null;
                videoDevice.LockForConfiguration(out error);
                if (error != null)
                {
                    videoDevice.UnlockForConfiguration();
                }
                videoDevice.TorchMode = AVCaptureTorchMode.Off;
                videoDevice.UnlockForConfiguration();
            }
            mark = !mark;
        }
		static void SetFlashModeForDevice (AVCaptureFlashMode flashMode, AVCaptureDevice device)
		{
			if (device.HasFlash && device.IsFlashModeSupported (flashMode)) {
				NSError error;
				if (device.LockForConfiguration (out error)) {
					device.FlashMode = flashMode;
					device.UnlockForConfiguration ();
				} else {
					Console.WriteLine ("Could not lock device for configuration: {0}", error);
				}
			}
		}
示例#33
0
		void ConfigureCameraForDevice (AVCaptureDevice device)
		{
			var error = new NSError ();
			if (device.IsFocusModeSupported (AVCaptureFocusMode.ContinuousAutoFocus)) {
				device.LockForConfiguration (out error);
				device.FocusMode = AVCaptureFocusMode.ContinuousAutoFocus;
				device.UnlockForConfiguration ();
			} else if (device.IsExposureModeSupported (AVCaptureExposureMode.ContinuousAutoExposure)) {
				device.LockForConfiguration (out error);
				device.ExposureMode = AVCaptureExposureMode.ContinuousAutoExposure;
				device.UnlockForConfiguration ();
			} else if (device.IsWhiteBalanceModeSupported (AVCaptureWhiteBalanceMode.ContinuousAutoWhiteBalance)) {
				device.LockForConfiguration (out error);
				device.WhiteBalanceMode = AVCaptureWhiteBalanceMode.ContinuousAutoWhiteBalance;
				device.UnlockForConfiguration ();
			}
		}
        void updateCameraSelection()
        {
            session.BeginConfiguration ();

            AVCaptureInput[] oldInputs = session.Inputs;
            foreach (var oldInput in oldInputs)
                session.RemoveInput (oldInput);

            AVCaptureDeviceInput input = pickCamera ();
            if (input == null) {
                foreach (var oldInput in oldInputs)
                    session.AddInput (oldInput);
            } else {
                session.AddInput (input);
                device = input.Device;

                NSError error;
                if (!device.LockForConfiguration (out error))
                    Console.WriteLine ("Could not lock for device: " + error.LocalizedDescription);

                updateAVFoundationFaceDetection ();
            }

            session.CommitConfiguration ();
        }