示例#1
0
        private async Task PickPhoto()
        {
            StopFade();

            var status = await Permissions.CheckStatusAsync <Permissions.Photos>();

            if (status == PermissionStatus.Unknown)
            {
                status = await Permissions.RequestAsync <Permissions.Photos>();
            }

            if (status == PermissionStatus.Denied)
            {
                ShowFixSettings = true;

                await App.Current.MainPage.DisplayAlert(Title,
                                                        "Photo Pick Denied - fix in settings",
                                                        "Ok");
            }
            else
            {
                ShowFixSettings = false;

                //var sharedPhoto = await DependencyService.Get<IPhotoPickerService>()
                //                          .GetImageStreamAsync();
                var sharedPhotoService = App.ServiceProvider.GetService <IPhotoPickerService>();
                var sharedPhoto        = await sharedPhotoService.GetImageStreamAsync();


                if (sharedPhoto != null)
                {
                    BoxOpacity = 0;

                    // Make a copy of the image stream as ImageSource.FromStream() will
                    // close the source

                    var stream = new MemoryStream();
                    sharedPhoto.ImageData.CopyTo(stream);
                    cachedImage = stream.ToArray();

                    ImageSource = ImageSource.FromStream(() => new MemoryStream(cachedImage));

                    ButtonLabel        = "Pick another picture";
                    _EnableShareButton = true;
                    ShareCommand.ChangeCanExecute();
                }
            }
        }