如何使用PickPhotoAsync指定特定目录?

时间:2019-03-27 20:35:44

标签: xamarin

使用PickPhotoAsync时如何指定特定目录或路径?

1 个答案:

答案 0 :(得分:0)

  

使用PickPhotoAsync时如何指定特定目录或路径?

很遗憾,它不能。。但是,如果有帮助,可以获取image.path。

officila document中,Task<MediaFile> PickPhotoAsync(PickMediaOptions options = null);无法使用目录添加选项。

enter image description here

但是,在拍照时,可以使用目录设置选项:

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

虽然不能从目录 PickPhotoAsync ,但是可以在需要的地方使用file.path

Image imgTemplateImages = new Image();
if (imgTemplateImages != null)
{
    lblImagePath.Text = "ImagePath" + file.Path;
    byte[] testByte = CommonFunctions.ReadStream(file.GetStream());
    imgTemplateImages.Source = ImageSource.FromStream(() =>
    {
        var stream = file.GetStream();
        file.Dispose();
        return stream;
    });
}

或者您可以保存到下次使用的数据库或Web服务器的路径。