void FocusWithMode(AVCaptureFocusMode focusMode, AVCaptureExposureMode exposureMode, CGPoint point, bool monitorSubjectAreaChange)
        {
            sessionQueue.DispatchAsync(() =>
            {
                var device    = videoDeviceInput.Device;
                NSError error = null;
                if (device.LockForConfiguration(out error))
                {
                    /*
                     *      Setting (focus/exposure)PointOfInterest alone does not initiate a (focus/exposure) operation.
                     *      Call 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: {error}");
                }
            });
        }
Beispiel #2
0
        void UpdateDeviceFocus(AVCaptureFocusMode focusMode, AVCaptureExposureMode exposureMode, CGPoint point, bool monitorSubjectAreaChange)
        {
            sessionQueue.DispatchAsync(() => {
                var device = videoDeviceInput?.Device;
                if (device == null)
                {
                    return;
                }

                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: {error.LocalizedDescription}");
                }
            });
        }
		public static bool TrySetFocusMode (this AVCaptureDevice device, AVCaptureFocusMode mode)
		{
			bool isSupported = device.IsFocusModeSupported (mode);
			if (isSupported)
				device.FocusMode = mode;

			return isSupported;
		}
Beispiel #4
0
        public static bool TrySetFocusMode(this AVCaptureDevice device, AVCaptureFocusMode mode)
        {
            bool isSupported = device.IsFocusModeSupported(mode);

            if (isSupported)
            {
                device.FocusMode = mode;
            }

            return(isSupported);
        }
        /// <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)));
            }
        }
		void UpdateDeviceFocus (AVCaptureFocusMode focusMode, AVCaptureExposureMode exposureMode, CGPoint point, bool monitorSubjectAreaChange)
		{
			sessionQueue.DispatchAsync (() => {
				var device = videoDeviceInput?.Device;
				if (device == null)
					return;

				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: {error.LocalizedDescription}");
				}
			});
		}
		void SetFocusAndMode (AVCaptureFocusMode focusMode, AVCaptureExposureMode exposureMode, CGPoint point, bool monitorSubjectAreaChange)
		{
			sessionQueue.DispatchAsync (() => {
				AVCaptureDevice device = VideoDevice;
				NSError error = null;
				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 (focusMode != AVCaptureFocusMode.Locked && device.FocusPointOfInterestSupported && device.IsFocusModeSupported (focusMode)) {
						device.FocusMode = focusMode;
						device.FocusPointOfInterest = point;
					}
					if (exposureMode != AVCaptureExposureMode.Custom && device.ExposurePointOfInterestSupported && device.IsExposureModeSupported (exposureMode)) {
						device.ExposureMode = exposureMode;
						device.ExposurePointOfInterest = point;
					}
					device.SubjectAreaChangeMonitoringEnabled = monitorSubjectAreaChange;
					device.UnlockForConfiguration ();
				} else {
					Console.WriteLine ($"Could not lock device for configuration: {error}");
				}
			});
		}
		static string StringFromFocusMode (AVCaptureFocusMode focusMode)
		{
			switch (focusMode) {
			case AVCaptureFocusMode.Locked:
				return "Locked";
			case AVCaptureFocusMode.AutoFocus:
				return "Auto";
			case AVCaptureFocusMode.ContinuousAutoFocus:
				return "ContinuousAuto";
			default:
				return "INVALID FOCUS MODE";
			}
		}