Windows phone 8 获取图像';Windows Phone中的Uri
我应该得到我的图像的Uri,但当我尝试这样做时,它给出了这个错误 图像的URI源可以强制转换BitmapImage,但BitmapImage的属性引发错误。如何获取图像的源Windows phone 8 获取图像';Windows Phone中的Uri,windows-phone-8,windows-phone,uri,bitmapimage,Windows Phone 8,Windows Phone,Uri,Bitmapimage,我应该得到我的图像的Uri,但当我尝试这样做时,它给出了这个错误 图像的URI源可以强制转换BitmapImage,但BitmapImage的属性引发错误。如何获取图像的源 img0.Source = GetImageForIndex(0, names, file, path).ImgSource; ImageListTemplate GetImageForIndex(int index, List<string> names, IsolatedStorageFile file,
img0.Source = GetImageForIndex(0, names, file, path).ImgSource;
ImageListTemplate GetImageForIndex(int index, List<string> names, IsolatedStorageFile file, string path)
{
using (IsolatedStorageFileStream stream = file.OpenFile(path + names[index], FileMode.Open, FileAccess.Read))
{
BitmapImage tempImage = new BitmapImage();
tempImage.SetSource(stream);
imagePath = path + names[index];
return new ImageListTemplate() { ImgSource = tempImage };
}
}
img0.Source=GetImageForIndex(0,名称,文件,路径);
ImageListTemplate GetImageForIndex(int索引、列表名称、IsolatedStorageFile文件、字符串路径)
{
使用(IsolatedStorageFileStream=file.OpenFile(路径+名称[index],FileMode.Open,FileAccess.Read))
{
BitmapImage tempImage=新的BitmapImage();
tempImage.SetSource(流);
imagePath=路径+名称[索引];
返回新的ImageListTemplate(){ImgSource=tempImage};
}
}
ImgSource的类型已经是BitmapImage。您没有为图像设置URI源,而是从数据流加载它 可以从流或URI填充
BitmapImage
。您只能通过从URI创建映像来读取已设置的URI源
根据您的代码,如果在查询SelectedItem
时需要返回原始数据源的引用,我建议将该路径/文件信息存储在标记
属性中。或者,将其添加为绑定项数据源的另一个属性,并查询该属性