Exemple #1
0
        async void PickPhotoAsync()
        {
            viewModel.IsBusy = true;

            await CrossMedia.Current.Initialize();

            if (!CrossMedia.Current.IsPickPhotoSupported)
            {
                await DisplayAlert("Fehler", "Dein Gerät unterstützt diese Funktion nicht", "OK");

                return;
            }

            var storageStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage);

            if (storageStatus != PermissionStatus.Granted)
            {
                var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Storage });

                storageStatus = results[Permission.Storage];
            }

            if (storageStatus != PermissionStatus.Granted)
            {
                await DisplayAlert("Fehlende Berechtigung", "Die App darf keine Fotos aus der Galerie laden", "OK");

                //On iOS you may want to send your user to the settings screen.
                //CrossPermissions.Current.OpenAppSettings();
                return;
            }

            MediaFile image = await CrossMedia.Current.PickPhotoAsync();

            if (image == null)
            {
                return;
            }

            ImageCropPage cropPage = new ImageCropPage(Container);

            cropPage.OnCropResult += (result) =>
            {
                viewModel.IsBusy = true;

                newImage         = result;
                viewModel.Image  = ImageSource.FromStream(() => new MemoryStream(result));
                removeImage      = false;
                viewModel.IsBusy = false;
            };
            await Navigation.PushAsync(cropPage);

            await Task.Run(() => cropPage.SetSource(ImageSource.FromStream(() => image.GetStream())));

            viewModel.IsBusy = false;
        }
Exemple #2
0
        async void TakePhotoAsync()
        {
            await CrossMedia.Current.Initialize();

            if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
            {
                await DisplayAlert("Fehler", "Dein Gerät unterstützt diese Funktion nicht", "OK");

                return;
            }

            var cameraStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Camera);

            var storageStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage);

            if (cameraStatus != PermissionStatus.Granted || storageStatus != PermissionStatus.Granted)
            {
                var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Camera, Permission.Storage });

                cameraStatus  = results[Permission.Camera];
                storageStatus = results[Permission.Storage];
            }

            if (cameraStatus != PermissionStatus.Granted || storageStatus != PermissionStatus.Granted)
            {
                await DisplayAlert("Fehlende Berechtigung", "Die App darf keine Fotos aufnehmen", "OK");

                //On iOS you may want to send your user to the settings screen.
                //CrossPermissions.Current.OpenAppSettings();
                return;
            }

            MediaFile image = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions()
            {
                AllowCropping  = true,
                DefaultCamera  = CameraDevice.Rear,
                MaxWidthHeight = 300,
                PhotoSize      = PhotoSize.Small,
                Directory      = "profile",
                Name           = model.Id + ".jpg"
            });

            if (image == null)
            {
                return;
            }

            ImageCropPage cropPage = new ImageCropPage(Container);

            cropPage.OnCropResult += (result) =>
            {
                viewModel.IsBusy = true;

                newImage         = result;
                viewModel.Image  = ImageSource.FromStream(() => new MemoryStream(result));
                removeImage      = false;
                viewModel.IsBusy = false;
            };
            await Navigation.PushAsync(cropPage);

            await Task.Run(() => cropPage.SetSource(ImageSource.FromStream(() => image.GetStream())));

            viewModel.IsBusy = false;
        }