如何从xamarin

时间:2016-06-17 13:16:32

标签: xamarin xamarin.ios xamarin.forms

如何从Xamarin Forms中的文件路径获取文件图像源我在本地使用依赖服务存储了一个文件夹。

_fileHelper = _fileHelper ?? DependencyService.Get<IFileHelper>();

 profiletap.Tapped += async (s, e) =>
{
    var file = await CrossMedia.Current.PickPhotoAsync();
    if (file == null)
    return;
    await DisplayAlert("File Location", file.Path, "OK");

    profile.Source = im;

    imageName = "SomeUniqueFileName" + DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss-tt");
    filePath  = _fileHelper.CopyFile(file.Path, imageName);

    im = ImageSource.FromFile(filePath)
}

我想永久地从媒体选择器上传图像,这样一旦上传的公共字符串CopyFile,我就无法丢失图像(字符串sourceFile,字符串destinationFilename,bool overwrite = true)         {

        if (!File.Exists(sourceFile)) { return string.Empty; }
        string fullFileLocation = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) );
        File.Copy(sourceFile, fullFileLocation, overwrite);
        return fullFileLocation;
    }

1 个答案:

答案 0 :(得分:1)

im = ImageSource.FromStream(()=> file.GetStream());