如何将图像路径保存到Live Tile的WP8 Local文件夹中

我正在更新我的Windows Phone应用程序以使用新的WP8文件存储API( LocalFolder )而不是WP7 API( IsolatedStorageFile )。

旧工作方法

以下是使用IsolatedStorageFile方法将Image成功保存到/ Shared / ShellContent文件夹的方法(在保存图像时注意/Shared/ShellContent/前缀,以及更新实时图块时的isostore:/Shared/ShellContent/前缀。

 using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { if (myIsolatedStorage.FileExists("/Shared/ShellContent/LiveTileImagePath.jpg")) { myIsolatedStorage.DeleteFile("/Shared/ShellContent/LiveTileImagePath.jpg"); } IsolatedStorageFileStream copyFileStream = myIsolatedStorage.CreateFile("/Shared/ShellContent/LiveTileImagePath.jpg"); wb.SaveJpeg(copyFileStream, wb.PixelWidth, wb.PixelHeight, 0, 100); copyFileStream.Close(); //UpdateTile ShellTile tile = ShellTile.ActiveTiles.First(); if (tile != null) { FlipTileData tileData = new FlipTileData() { Title = "title", BackTitle = "backtitle", BackContent = "", WideBackContent = "", SmallBackgroundImage = new Uri("/Images/SmallIconBW.png", UriKind.RelativeOrAbsolute), BackgroundImage = new Uri("/Images/MediumKiss336.png", UriKind.RelativeOrAbsolute), BackBackgroundImage = new Uri("isostore:/Shared/ShellContent/LiveTileImagePath.jpg", UriKind.RelativeOrAbsolute), WideBackgroundImage = new Uri("/Images/MediumKiss336.png", UriKind.RelativeOrAbsolute), WideBackBackgroundImage = new Uri("isostore:/Shared/ShellContent/LiveTileImagePath.jpg", UriKind.RelativeOrAbsolute) }; tile.Update(tileData); } } 

要解决的问题

当我使用新方法保存图像时出现问题。 我似乎无法找到更新瓷砖的正确图像路径。 这是我保存图像的新方法( 注意fileStream是一个包含我在方法前面的WriteableBitmap中生成的jpeg图像的MemoryStream。它可以很好地存储在应用程序中使用,但不能存储在Shared文件夹中)

 StorageFile liveTileImageFile = await localFolder.CreateFileAsync("/Shared/ShellContent/LiveTileImagePath.jpg", CreationCollisionOption.ReplaceExisting); fileStream.Seek(0, SeekOrigin.Begin); using(Stream sharedFolderStream = await liveTileImageFile.OpenStreamForWriteAsync()) { await fileStream.CopyToAsync(sharedFolderStream); } ShellTile tile = ShellTile.ActiveTiles.First(); if (tile != null) { FlipTileData tileData = new FlipTileData() { Title = "Kiss Dictionary", BackTitle = "name", BackContent = "", WideBackContent = "", SmallBackgroundImage = new Uri("/Images/SmallIconBW.png", UriKind.RelativeOrAbsolute), BackgroundImage = new Uri("/Images/MediumKiss336.png", UriKind.RelativeOrAbsolute), BackBackgroundImage = new Uri("isostore:/Shared/ShellContent/LiveTileImagePath.jpg", UriKind.RelativeOrAbsolute), WideBackgroundImage = new Uri("/Images/MediumKiss336.png", UriKind.RelativeOrAbsolute), WideBackBackgroundImage = new Uri("isostore:/Shared/ShellContent/LiveTileImagePath.jpg", UriKind.RelativeOrAbsolute) }; tile.Update(tileData); } 

问题是我无法将图像保存到Shared / ShellFolder,我收到此exception消息:

文件名,目录名或卷标语法不正确。 (HRESULTexception:0x8007007B)

如果您已更新应用程序的LiveTile更新,请说明您用于保存的路径以及分配给LiveTile图像的文件路径。

更新:

Rob的回答修复了exception,并允许我保存到该文件夹​​。 我对我的磁贴更新中使用的文件路径进行了更改(感谢Scott Lovegrove的建议):

而不是旧的方式:

 BackBackgroundImage = new Uri("isostore:/Shared/ShellContent/LiveTileImagePath.jpg", UriKind.RelativeOrAbsolute) 

我成功地使用了这个

 BackBackgroundImage = new Uri("isostore:shared\\shellcontent\\LiveTileImagePath.jpg", UriKind.RelativeOrAbsolute) 

这很难看,但它有效…你需要深入到每个孤立存储目录。 你不能只是放入完整的路径(这太简单了)。

所以代替:

 StorageFile liveTileImageFile = await localFolder.CreateFileAsync("/Shared/ShellContent/LiveTileImagePath.jpg", CreationCollisionOption.ReplaceExisting); 

你应该有:

 var sharedFolder = await localFolder.GetFolderAsync("Shared"); var shellContentFolder = await sharedFolder.GetFolderAsync("ShellContent"); var liveTileImageFile = await shellContentFolder.CreateFileAsync("LiveTileImagePath.jpg", CreationCollisionOption.ReplaceExisting); 

希望有所帮助。