c# - 如何从 Xamarin.Forms 中的流中获取图像的路径
问题描述
我将图像转换为流并设置为 Xamarin.Forms.Image.Source,在单击按钮时,我试图访问相同的图像,但在后面的代码中,我无法将图像作为 StreamImagesSource 获取访问获取流。
Assembly _assembly = this.GetType().Assembly;
Stream stream = _assembly.GetManifestResourceStream("DataGrithWithImagePdfExport.Resources.Jk.png");
ImageSource source = ImageSource.FromStream(() => stream);
///Added the image to the ImageSource property in Model
Persons.Add(new Person() { Name = "John Smith", Photo = source });
请帮助我克服这个问题。谢谢。
解决方案
@Bala Malarkodi,您为什么要访问流?您可以简单地获取文件路径,假设如果您在图像文件夹下有 sample.png 然后像这样设置您的属性,
public class Person
{
public string Name { get; set; }
public string ImageURL { get; set; }
}
像这样准备你的模型,
Persons.Add(new Person()
{
Name = "John Smith",
ImageURL = "Images/sample.png"
});
并在您的页面 (xaml) 中绑定此 ImageURL。
推荐阅读
- c++ - 禁用 Visual Studio 绿色箭头按钮移动指令指针
- node.js - 从 Next.js 中的 CMS 访问 api
- monaco-editor - 如何在当前视口滚动时获取摩纳哥编辑器中第一条可见行的行号?
- javascript - Vuejs:如何有条件地附加道具?
- css - Vutify 中的不同视口
- python - 如何在python中拆分文本计数字符串列表中的出现次数
- amazon-web-services - 使用数据库脚本将 JSON 数组导入 DynamoDB 表
- android - android 库中的 assembleRelease 任务“:verifyReleaseResources”执行失败
- json - oc 补丁替换图像名称错误“json:无法将对象解组为 jsonpatch.Patch 类型的 Go 值”
- hook - 将 Google Adsense 与 Google 跟踪代码管理器集成