[英]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.