Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 81910

App closed when i click ok button on camera

$
0
0

I have used Xamarin plugin to access gallery and camera, after taking photo i can able to see the picture when i click the ok button my app gets closed.
here is the sample code:
`private async void Upload_Clicked(object sender, EventArgs e)
{
try
{
var action = await DisplayActionSheet("Options", "Cancel", null, "Camera", "Gallery", "Files");
switch (action)
{
case "Camera":
if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
{
DisplayAlert("No Camera", ":( No camera avaialble.", "OK");
return;
}

                    var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
                    {

                        Directory = "Sample",
                        Name = "test.jpg"
                    });

                    if (file == null)
                        return;

                    DisplayAlert("File Location", file.Path, "OK");

                    image.Source = ImageSource.FromStream(() =>
                    {
                        var stream = file.GetStream();
                        file.Dispose();
                        return stream;
                    });
                    break;
                case "Gallery":
                    if (!CrossMedia.Current.IsPickPhotoSupported)
                    {
                        DisplayAlert("Photos Not Supported", ":( Permission not granted to photos.", "OK");
                        return;
                    }
                    var Pickfile = await CrossMedia.Current.PickPhotoAsync();
                    if (Pickfile == null)
                        return;
                    image.Source = ImageSource.FromStream(() =>
                    {
                        var stream = Pickfile.GetStream();
                        Pickfile.Dispose();
                        return stream;
                    });
                    break;
            }

        }
        catch (Exception)
        {
            throw;
        }
    }`

Viewing all articles
Browse latest Browse all 81910

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>