我想检索我在手机中具有路径的图像
filepath = "/storage/emulated/0/Android/data/com.CommunicatorEye/files/Pictures/EmployeesCards/IMG_20190131_143513.jpg";
var image = DependencyService.Get<IDependency().RetriveImageFromLocation(filepath);
IDependency.cs
public interface IDependency
{
Task<Image> RetriveImageFromLocation(string location);
}
Android DependencyImplementation.cs
public async Task<Image> RetriveImageFromLocation(string location)
{
Image image = new Image();
var memoryStream = new MemoryStream();
using (var source = System.IO.File.OpenRead(location))
{
await source.CopyToAsync(memoryStream);
}
image.Source = ImageSource.FromStream(() => memoryStream);
return image;
}
但这对我不起作用,有样品吗?
如果该文件在您应用的沙箱中,则没有理由使用DI / DependencyService / etc ...获取流以填充ImageSource
,然后将其添加到Image
。
使用FileImageSource
(static ImageSource.FromFile
)并提供路径:
var image = new Image
{
Source = ImageSource.FromFile(filePath)
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句