Ejemplo n.º 1
0
 /// <summary>
 /// Verifies the camera options.
 /// </summary>
 /// <param name="options">The options.</param>
 /// <exception cref="ArgumentException">options.Camera is not a member of CameraDevice</exception>
 private static void VerifyCameraOptions(CameraMediaStorageOptions options)
 {
     VerifyOptions(options);
     if (!Enum.IsDefined(typeof(CameraDevice), options.DefaultCamera))
     {
         throw new ArgumentException("options.Camera is not a member of CameraDevice");
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Select a picture from library.
        /// </summary>
        /// <param name="options">The storage options.</param>
        /// <returns>Task&lt;IMediaFile&gt;.</returns>
        /// <exception cref="NotSupportedException"></exception>
        public Task <MediaFile> SelectPhotoAsync(CameraMediaStorageOptions options)
        {
            if (!IsPhotosSupported)
            {
                throw new NotSupportedException();
            }

            return(GetMediaAsync(UIImagePickerControllerSourceType.PhotoLibrary, TypeImage, options));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Takes the picture.
        /// </summary>
        /// <param name="options">The storage options.</param>
        /// <returns>Task with a return type of MediaFile.</returns>
        /// <exception cref="System.NotSupportedException">Throws an exception if feature is not supported.</exception>
        public Task <MediaFile> TakePhotoAsync(CameraMediaStorageOptions options)
        {
            if (!IsCameraAvailable)
            {
                throw new NotSupportedException();
            }

            options.VerifyOptions();

            return(TakeMediaAsync("image/*", MediaStore.ActionImageCapture, options));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Select a picture from library.
        /// </summary>
        /// <param name="options">The storage options.</param>
        /// <returns>Task with a return type of MediaFile.</returns>
        /// <exception cref="System.NotSupportedException">Throws an exception if feature is not supported.</exception>
        public Task <MediaFile> SelectPhotoAsync(CameraMediaStorageOptions options)
        {
            if (!IsCameraAvailable)
            {
                throw new NotSupportedException();
            }

            options.VerifyOptions();

            return(TakeMediaAsync("image/*", Intent.ActionPick, options));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Select a picture from library.
        /// </summary>
        /// <param name="options">The storage options.</param>
        /// <returns>Task with a return type of MediaFile.</returns>
        /// <exception cref="System.NotSupportedException">Throws an exception if feature is not supported.</exception>
        public Task<MediaFile> SelectPhotoAsync(CameraMediaStorageOptions options)
        {
            if (!IsCameraAvailable)
            {
                throw new NotSupportedException();
            }

            options.VerifyOptions();

            return TakeMediaAsync("image/*", Intent.ActionPick, options);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Takes the picture.
        /// </summary>
        /// <param name="options">The storage options.</param>
        /// <returns>Task&lt;IMediaFile&gt;.</returns>
        /// <exception cref="NotSupportedException">
        /// </exception>
        public Task <MediaFile> TakePhotoAsync(CameraMediaStorageOptions options)
        {
            if (!IsPhotosSupported)
            {
                throw new NotSupportedException();
            }
            if (!IsCameraAvailable)
            {
                throw new NotSupportedException();
            }

            VerifyCameraOptions(options);

            return(GetMediaAsync(UIImagePickerControllerSourceType.Camera, TypeImage, options));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Takes the picture.
        /// </summary>
        /// <param name="options">The storage options.</param>
        /// <returns>Task&lt;IMediaFile&gt;.</returns>
        /// <exception cref="InvalidOperationException">Only one operation can be active at a time</exception>
        /// <exception cref="System.NotImplementedException"></exception>
        public Task <MediaFile> TakePhotoAsync(CameraMediaStorageOptions options)
        {
            options.VerifyOptions();

            var ntcs = new TaskCompletionSource <MediaFile>(options);

            if (Interlocked.CompareExchange(ref _completionSource, ntcs, null) != null)
            {
                throw new InvalidOperationException("Only one operation can be active at a time");
            }

            _cameraCapture.Show();

            return(ntcs.Task);
        }
Ejemplo n.º 8
0
		/// <summary>
		/// Select a picture from library.
		/// </summary>
		/// <param name="options">The storage options.</param>
		/// <returns>Task&lt;IMediaFile&gt;.</returns>
		/// <exception cref="NotSupportedException"></exception>
		public Task<MediaFile> SelectPhotoAsync(CameraMediaStorageOptions options)
		{
			if (!IsPhotosSupported)
			{
				throw new NotSupportedException();
			}

			return GetMediaAsync(UIImagePickerControllerSourceType.PhotoLibrary, TypeImage);
		}
Ejemplo n.º 9
0
		/// <summary>
		/// Verifies the camera options.
		/// </summary>
		/// <param name="options">The options.</param>
		/// <exception cref="ArgumentException">options.Camera is not a member of CameraDevice</exception>
		private static void VerifyCameraOptions(CameraMediaStorageOptions options)
		{
			VerifyOptions(options);
			if (!Enum.IsDefined(typeof(CameraDevice), options.DefaultCamera))
			{
				throw new ArgumentException("options.Camera is not a member of CameraDevice");
			}
		}
Ejemplo n.º 10
0
		/// <summary>
		/// Takes the picture.
		/// </summary>
		/// <param name="options">The storage options.</param>
		/// <returns>Task&lt;IMediaFile&gt;.</returns>
		/// <exception cref="NotSupportedException">
		/// </exception>
		public Task<MediaFile> TakePhotoAsync(CameraMediaStorageOptions options)
		{
			if (!IsPhotosSupported)
			{
				throw new NotSupportedException();
			}
			if (!IsCameraAvailable)
			{
				throw new NotSupportedException();
			}

			VerifyCameraOptions(options);

			return GetMediaAsync(UIImagePickerControllerSourceType.Camera, TypeImage, options);
		}
Ejemplo n.º 11
0
        /// <summary>
        /// Takes the picture.
        /// </summary>
        /// <param name="options">The storage options.</param>
        /// <returns>Task with a return type of MediaFile.</returns>
        /// <exception cref="System.NotSupportedException">Throws an exception if feature is not supported.</exception>
        public Task<MediaFile> TakePhotoAsync(CameraMediaStorageOptions options)
        {
            if (!IsCameraAvailable)
            {
                throw new NotSupportedException();
            }   

            options.VerifyOptions();

            return TakeMediaAsync("image/*", MediaStore.ActionImageCapture, options);
        }
Ejemplo n.º 12
0
		public async Task SelectPhoto ()
		{
			PreviewSource = null;

			try {
				var options = new CameraMediaStorageOptions {
					DefaultCamera = CameraDevice.Front,
					MaxPixelDimension = 300
				};

				var file = await mediaPicker.SelectPhotoAsync (options);
				PreviewSource = ImageSource.FromStream (() => file.Source);
				imageStream = file.Source;
			} catch (Exception) {
			}
		}
Ejemplo n.º 13
0
		public async Task<MediaFile> TakePhoto ()
		{
			PreviewSource = null;

			var options = new CameraMediaStorageOptions { DefaultCamera = CameraDevice.Rear, MaxPixelDimension = 300 };
			return await mediaPicker.TakePhotoAsync (options).ContinueWith (t => {
				if (!t.IsFaulted && !t.IsCanceled) {
					var mediaFile = t.Result;

					PreviewSource = ImageSource.FromStream (() => mediaFile.Source);
					imageStream = mediaFile.Source;

					return mediaFile;
				}

				return null;
			}, TaskScheduler.FromCurrentSynchronizationContext ());
		}
		/// <summary>
		/// Takes the picture.
		/// </summary>
		/// <param name="options">The storage options.</param>
		/// <returns>Task&lt;IMediaFile&gt;.</returns>
		/// <exception cref="InvalidOperationException">Only one operation can be active at a time</exception>
		/// <exception cref="System.NotImplementedException"></exception>
		public Task<MediaFile> TakePhotoAsync(CameraMediaStorageOptions options)
		{
			options.VerifyOptions();

			var ntcs = new TaskCompletionSource<MediaFile>(options);
			if (Interlocked.CompareExchange(ref _completionSource, ntcs, null) != null)
			{
				throw new InvalidOperationException("Only one operation can be active at a time");
			}

			_cameraCapture.Show();

			return ntcs.Task;
		}
Ejemplo n.º 15
0
        private async Task<MediaFile> TakePic()
        {
            var mediaStorageOptions = new CameraMediaStorageOptions
            {
                DefaultCamera = CameraDevice.Rear
            };
            var mediaFile = await _device.MediaPicker.TakePhotoAsync(mediaStorageOptions);

            return mediaFile;
        }