【发布时间】:2016-06-17 13:16:31
【问题描述】:
如何从 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(string sourceFile, string 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;
}
【问题讨论】:
-
您能详细说明您还想做什么吗?你试过什么?你在哪里失败?您发布的代码似乎也不完整。
-
我想从媒体选择器中永久上传图片,这样上传后我就不会丢失图片......这是我的安卓代码
标签: xamarin xamarin.ios xamarin.forms