[英]How to get the path of the image from stream in 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 });
请帮助我克服此问题。 谢谢。
根据您在评论中的回答,似乎您尚未将文件添加为Embeded Resources(Jk.png)。
如果要使用应用程序清单中的文件,则需要将属性设置为Embedded-Resource 。
编辑
如果将嵌入式图像放入项目中的文件夹,则文件夹名称也将由资源ID中的句点(。)分隔。
在您的问题中, DataGrithWithImagePdfExport.Resources.Jk.jpg
资源ID表示:
有关更多信息: https : //docs.microsoft.com/zh-cn/xamarin/ios/app-fundamentals/images-icons/displaying-an-image?tabs=windows
请检查以下图片:
@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"
});
并将此ImageURL绑定到页面(xaml)中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.