示例#1
0
        async void TakePhoto(object sender, EventArgs eventArgs)
        {
            await CrossMedia.Current.Initialize();

            if (!await GetCameraPermission())
            {
                return;
            }

            if (!CrossMedia.Current.IsCameraAvailable ||
                !CrossMedia.Current.IsTakePhotoSupported)
            {
                await DisplayAlert("No Camera", "No camera available", "Not cool...");

                return;
            }

            var frontOrBackCamera = cameraSwitch.IsToggled ?
                                    Plugin.Media.Abstractions.CameraDevice.Rear :
                                    Plugin.Media.Abstractions.CameraDevice.Front;

            var imgStoreOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions()
            {
                Directory     = "Pictures",
                Name          = "test.jpg",
                DefaultCamera = frontOrBackCamera
            };

            MediaFile capturedPhoto;

            try
            {
                capturedPhoto = await CrossMedia.Current.TakePhotoAsync(imgStoreOptions);
            }
            catch (Exception)
            {
                await DisplayAlert("Failed operation", "Couldn't take a photo.", "Ok");

                return;
            }

            if (capturedPhoto == null)
            {
                return;
            }

            var preView = new CameraCapturePreview();

            preView.SetPreviewImg(capturedPhoto);

            await Navigation.PushAsync(preView);
        }
示例#2
0
        async void PickPhoto(object sender, EventArgs eventArgs)
        {
            if (!CrossMedia.Current.IsPickPhotoSupported)
            {
                await DisplayAlert("Not supported", "It's not possible to pickup a photo", "Ok");

                return;
            }

            var photo = await CrossMedia.Current.PickPhotoAsync();

            if (photo == null)
            {
                return;
            }

            var preView = new CameraCapturePreview();

            preView.SetPreviewImg(photo);
            await Navigation.PushAsync(preView);
        }