【发布时间】:2013-11-24 04:43:03
【问题描述】:
这就是我从图像 url 获取流的方式:
using (var httpClient = new HttpClient())
{
response = await httpClient.GetStreamAsync(new Uri(IMAGEURL_HERE, UriKind.Absolute));
}
SaveImage(response);
这就是我将它保存到 IsoloatedStorage 的方式:
private void SaveImage(Stream result)
{
using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
{
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(result);
var wb = new WriteableBitmap(bitmap);
using (IsolatedStorageFileStream fileStream = file.CreateFile("FILENAME.jpg"))
{
int width = wb.PixelWidth;
int height = wb.PixelHeight;
if (wb.PixelWidth > 336)
{
width = 336;
}
if (wb.PixelHeight > 336)
{
height = 336;
}
Extensions.SaveJpeg(wb, fileStream, width, height, 0, 100);
}
}
}
假设文件是 FILENAME.jpg,我想我可以将它设置为 BackgroundImage 到这样的辅助磁贴:
var tileData = new FlipTileData()
{
...
BackgroundImage = new Uri("isostore:/Shared/ShellContent/FILENAME.jpg", UriKind.Absolute),
...
这行不通。它不会抛出异常,只有图像不会显示。我想念什么?当然,如果我将 Image Url 作为 Uri 放到 BackgroundImage 中,它可以工作,但这不是我想要的。
编辑:我在这里看到了类似的问题,但它对我的代码没有帮助。
【问题讨论】:
-
tileData.BackgroundImage = ...
-
我已经编辑了代码。在那里,它是 FlipTileData ctor,因此创建 Tile 不是问题,它工作得很好,也适用于来自站点的图像 URL,但不是来自 IsoStorage。
标签: c# windows-phone-8