在隔离存储中从图像设置辅助平铺BackgroundImage

这是我从图片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,我想我可以把它设置为这样的Secondary Tile的BackgroundImage:

 var tileData = new FlipTileData() { ... BackgroundImage = new Uri("isostore:/Shared/ShellContent/FILENAME.jpg", UriKind.Absolute), ... 

它不会起作用。 它不会抛出exception,只会显示图像。 我错过了什么? 当然如果我将Image Url作为Uri放到BackgroundImage它可以工作,但这不是我想要的。

编辑:我在这里看到过类似的问题,但它对我的代码没有帮助。

试试这个。 可能是它的帮助。

 string imageFolder = @"\Shared\ShellContent"; string shareJPEG = "FILENAME.jpg"; private void SaveImage(Stream result) { using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication()) { if(!myIsolatedStorage.DirectoryExists(imageFolder)) { myIsolatedStorage.CreateDirectory(imageFolder); } if (myIsolatedStorage.FileExists(shareJPEG)) { myIsolatedStorage.DeleteFile(shareJPEG); } string filePath = System.IO.Path.Combine(imageFolder, shareJPEG); IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(filePath); BitmapImage bitmap = new BitmapImage(); bitmap.SetSource(result); WriteableBitmap wb = new WriteableBitmap(bitmap); // Encode WriteableBitmap object to a JPEG stream. 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); fileStream.Close(); } } private void CreateTile() { var tileData = new FlipTileData() { .... string filePath = System.IO.Path.Combine(imageFolder, shareJPEG); BackgroundImage = new Uri(@"isostore:" + filePath, UriKind.Absolute); .... } }