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;
}
}`