在Xamarin Forms中将Image转换为ByteArray

时间:2016-12-07 04:15:24

标签: xamarin xamarin.forms

我可以知道如何将图像转换(从文件夹/从相机中取出)到字节数组吗? &安培;还将字节数组转换为图像?

从相机拍摄照片

merge into original_table o
  using (
    with
         helper ( id, rn, rand_rn ) as (
           select id,
                  row_number() over (order by id),
                  row_number() over (order by dbms_random.value())
           from   original_table
         )
    select ot.name, h2.id
    from   original_table ot inner join helper h1 on      ot.id = h1.id
                             inner join helper h2 on h1.rand_rn = h2.rn
  ) p
on (o.id = p.id)
when matched then update set o.name = p.name
;

select * from original_table;

ID  NAME
--  ------
1   ricky
2   dave
3   Jérôme
4   jane
6   august
9   mike

从文件夹中拍照

 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 
            {

            }
        }

我不知道Image的位置在哪里,以及在哪里获取图像。

我试图将图像保存到Azure数据库中。但我面临将MediaFile转换为Byte []的问题。我使用Xam.Plugin.Medie(http://www.nuget.org/packages/Xam.Plugin.Media)来访问相机和图库。请指导我如何将MedieFile转换为Byte []。谢谢。 参考的任何示例源代码

0 个答案:

没有答案