2013-06-30 42 views
0

我写了下面的代码从互联网上节省一些图片:获取一个URI

public static async Task SaveImage(string name, string uri) 
    { 
     var localfolder = ApplicationData.Current.LocalFolder; 
     var client = new HttpClient(); 

     var imageStream = await client.GetStreamAsync(uri); //Secuencia de bytes 
     var storageFile = await localfolder.CreateFileAsync(name, CreationCollisionOption.ReplaceExisting); 

     using (Stream outputStream = await storageFile.OpenStreamForWriteAsync()) 
     { 
      await imageStream.CopyToAsync(outputStream); 
     } 
    } 

我的问题是,当我尝试在本地存储这些图像店设置为CycleTile因为这个班级需要Uri的,我不知道如何在这里提供Uri。这是我有:

 CycleTileData cycleicon = new CycleTileData(); 
     cycleicon.Title = "Fotopantalla"; 
     cycleicon.Count = 0; 
     cycleicon.SmallBackgroundImage = new Uri("/Assets/Tiles/FlipCycleTileSmall.png", UriKind.RelativeOrAbsolute); 
     List<Uri> images = new List<Uri>(); 

     for (int i = 0; i < 9; i++) 
     { 
      /// tries... 
      string path1 = "ms-appdata:///local/image" + i + ".jpg"; 
      string path2 = "isostore:/Shared/ShellContent/image" + i + ".jpg"; 
      string path3 = "ms-appdata:///Local/Shared/ShellContent/image" + i + ".jpg"; 
      /// 

      Uri uri = new Uri(path2, UriKind.RelativeOrAbsolute); 
      images.Add(uri); 
     } 

     cycleicon.CycleImages = images; 

我是什么错误或我错过了什么?

+0

其实,应该工作(路径2或3)。如果下载工作正常,您是否使用WP Power Tools或其他Isostorage工具进行检查? – blakharaz

回答

0

对于任何与ShellTileData相关的数据结构,如果图像不在(只读)InstalledLocation文件夹中,则必须使用path2: “isostore:/ Shared/ShellContent/*”。

有关详细信息,请参阅:http://blogs.msdn.com/b/andy_wigley/archive/2013/04/10/live-apps-creating-custom-tile-and-lock-screen-images.aspx

我在我的代码类似的东西:

var store = IsolatedStorageFile.GetUserStoreForApplication(); 
if (!store.DirectoryExists("Shared/ShellContent")) 
{ 
    store.CreateDirectory("Shared/ShellContent"); 
} 
StorageFolder shellContent = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync("Shared", CreationCollisionOption.OpenIfExists); 
shellContent = await shellContent.CreateFolderAsync("ShellContent", CreationCollisionOption.OpenIfExists); 

Stream imgin = picture.GetImage(); 
//Picture read stream from Media Library or other input stream 

StorageFile new_img = await shellContent.CreateFileAsync(newPictureName); 
Stream imgout = await new_img.OpenStreamForWriteAsync(); 

imgin.CopyTo(imgout); 

imgout.Close(); // <- necessary in your code or not? 
imgin.Close(); // <- 

我不知道,你是否真的需要Isostore件事开始,但它的工作原理,如果我在缩短代码的时候没有犯过一些愚蠢的错误。 ;-)

另请参见Microsoft开发人员中心的“StandardTileData.BackgroundImage Property”,“Windows Phone数据”和“如何使用Windows Phone的独立存储浏览器工具”。 (最后一个是关于如何看看你的设备上保存的图像文件。)