Hi, I'm trying to save image into Azure database. But i'm facing problem to convert MediaFile into Byte[]. I'm using Xam.Plugin.Medie ( http://www.nuget.org/packages/Xam.Plugin.Media ) to access camera and gallery. Please kindly guide me how to convert MedieFile into Byte[]. Thank you.
Image image = new Image();
Button test = new Button
{
Text = "Take Photo"
};
Button test2 = new Button
{
Text = "Pick Photo"
};
Content = new StackLayout
{
Children = {
test, test2, image
}
};
test.Clicked += async (sender, args) =>
{
if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
{
await DisplayAlert("No Camera", ":( No camera avaialble.", "OK");
return;
}
var file = await CrossMedia.Current.TakePhotoAsync(new Media.Plugin.Abstractions.StoreCameraMediaOptions
{
Directory = "Sample",
Name = "test.jpg"
});
if (file == null)
return;
await DisplayAlert("File Location", file.Path, "OK");
image.Source = ImageSource.FromStream(() =>
{
var stream = file.GetStream();
file.Dispose();
return stream;
});
};
test2.Clicked += async (sender, args) =>
{
if (!CrossMedia.Current.IsPickPhotoSupported)
{
await DisplayAlert("Photos Not Supported", ":( Permission not granted to photos.", "OK");
return;
}
var file = await CrossMedia.Current.PickPhotoAsync();
if (file == null)
return;
image.Source = ImageSource.FromStream(() =>
{
var stream = file.GetStream();
file.Dispose();
return stream;
});
};