我从网上下载了图片并将其保存到独立存储中,现在我想通过给出Uri来访问我的XAML文件中的这些图像。
我已使用IsoStoreSpy验证它们是否被正确存储在预期位置,并且如果我打开文件并读取字节流,我可以从它们创建BitmapImages。但现在,我想通过从我的模型传递仅Uri到独立存储位置并让我的XAML加载图像来优化我的图像处理。
这是绑定到BitmapImage.UriSource的“PodcastLogoUri” Uri值:
我已使用IsoStoreSpy验证它们是否被正确存储在预期位置,并且如果我打开文件并读取字节流,我可以从它们创建BitmapImages。但现在,我想通过从我的模型传递仅Uri到独立存储位置并让我的XAML加载图像来优化我的图像处理。
<Image Height="120" Width="120" Stretch="Uniform" HorizontalAlignment="Left">
<Image.Source>
<BitmapImage UriSource="{Binding PodcastLogoUri}" DecodePixelHeight="120" DecodePixelWidth="120" />
</Image.Source>
</Image>
这是绑定到BitmapImage.UriSource的“PodcastLogoUri” Uri值:
以下是我构建它的方法:"isostore:/PodcastIcons/258393889fa6a0a0db7034c30a8d1c3322df55696137611554288265.jpg"
public Uri PodcastLogoUri
{
get
{
Uri uri = new Uri(@"isostore:/" + PodcastLogoLocation);
return uri;
}
}
然而,我在用户界面中看不到图像。我确信该图像位于PodcastLogoLocation
。
在Windows Phone 8中,是否可以像这样从隔离存储引用图像到UI中?我做错了什么?
编辑:如果我直接使用相同路径创建BitmapImage,并在XAML中使用BitmapImage,则可以正常工作,并且我可以在那里看到我期望看到的图像:
<Image Height="120" Source="{Binding PodcastLogo}" Width="120" Stretch="Uniform" HorizontalAlignment="Left"/>
public BitmapImage PodcastLogo
{
get
{
Stream stream = null;
BitmapImage logo = new BitmapImage();
using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
if (isoStore.FileExists(PodcastLogoLocation))
{
stream = isoStore.OpenFile(PodcastLogoLocation, System.IO.FileMode.Open, FileAccess.Read);
try
{
logo.SetSource(stream);
}
catch (Exception e)
{
}
}
}
return logo;
}
}
UriKind.Absolute
吗? - Neil Turner