如何在Xamarin Forms中将Xam.Plugin.Media目录设置为外部存储

时间:2018-09-20 05:27:50

标签: xamarin xamarin.forms

我添加了Xam.Plugin.Media来捕获图像。问题是,如果有SD卡并且不固定在内部存储器中,我想将图片保存到SD卡中。如何检查是否存在SD卡?如果可以的话,如何获取目录?

下面的代码是捕获图像的功能

 try
 {
     var cafNo = entCafNo.Text;

     await CrossMedia.Current.Initialize();

     if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
     {
         await DisplayAlert("No Camera", "No Camera Available", "Ok");
         return;
     }
     var file = await CrossMedia.Current.TakePhotoAsync(
        new StoreCameraMediaOptions
        {
            SaveToAlbum = true,
            Name = cafNo + "_IMG_01.png",
            CompressionQuality = 80,
            PhotoSize = PhotoSize.Medium,
            DefaultCamera = Plugin.Media.Abstractions.CameraDevice.Front
        }
     );
     entPhoto1Url.Text = file.Path;

  }
  catch (Exception ex)
  {
    Console.Write(ex.Message);
  }

0 个答案:

没有答案