0

May I know how to convert image (take from folder/take from Camera) to Byte Array? & also convert Byte Array to image?

Take Photo From Camera

 async void TakePhoto()
        {

            try
            {
                var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory = "Sample",
                    Name = "test.jpg",
                    //SaveToAlbum = saveToGallery.IsToggled
                });

                if (file == null)
                    return;

                //  await DisplayAlert("File Location", (saveToGallery.IsToggled ? file.AlbumPath : file.Path), "OK");

                img.Source = ImageSource.FromStream(() =>
                {
                    var stream = file.GetStream();
                    file.Dispose();
                    return stream;
                });
            }
            catch 
            {

            }
        }

Take Photo From Folder

async void FromFolder()
        {

            try
            {
                Stream stream = null;
                var file = await CrossMedia.Current.PickPhotoAsync().ConfigureAwait(true);


                if (file == null)
                    return;

                stream = file.GetStream();
                file.Dispose();

                img.Source = ImageSource.FromStream(() => stream);

            }
            catch 
            {

            }
        }

I dont know where are the location of Image, and where to get the image.

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. Any sample source code for references

Eng Soon Cheah
  • 257
  • 1
  • 10
  • 42

0 Answers0