2014-08-28 79 views
1

我有一个使用C#编写的Windows应用商店应用,可以与照片一起使用。我想要显示用户在中型活动拼贴(150 x 150)中选择的最后一张照片。我正在使用下面的代码来做到这一点。当我运行应用程序时,我没有收到任何错误,但是在实时拼贴中看不到选定的照片。我知道我至少在做一些事情是正确的。我这样说是因为如果用户还没有选择一张照片,那么我会显示一张测试图像,然后在该图像中看到该图像。但测试图像来自应用程序包,使用的协议不是来自应用程序存储区的协议。分配给活动图块的动态图像不显示?

我在这个主题上发现了一些SO帖子,但它们都是针对Windows Phone的。我查看了Windows应用商店应用文件的KnownFolders列表,但似乎没有映射到Windows Phone中用于实时切片使用的文件所需的SharedContent文件夹。我的代码有什么问题?

笔记,所述vvm.ActiveVideomark.GetThumbnail()呼叫简单地检索一个位图作为WriteableBitmap的对象。正如您在代码中看到的那样,我将图像调整为中等活动图块所需的大小(150 x 150)。 ToJpegFileAsync()是一种扩展方法,它将WriteableBitmap对象编码为jpeg字节,然后使用给定的文件名将这些字节写入文件。就我所知,这两种电话都经过了充分测试,并不是问题的根源。

 TileUpdateManager.CreateTileUpdaterForApplication().Clear(); 
     TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true); 

     var tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150Image); 

     var tileImage = tileXml.GetElementsByTagName("image")[0] as XmlElement; 

     // Got a current photo? 
     if (vvm.ActiveVideomark == null) 
      // No, just show the regular logo image. 
      tileImage.SetAttribute("src", "ms-appx:///Assets/Logo.scale-100.png"); 
     else 
     { 
      // Resize it to the correct size. 
      WriteableBitmap wbm = await vvm.ActiveVideomark.GetThumbnail(); 
      WriteableBitmap wbm2 = wbm.Resize(150, 150, WriteableBitmapExtensions.Interpolation.Bilinear); 

      // Write it to a file so we can pass it to the Live Tile. 
      string jpegFilename = "LiveTile1.jpg"; 
      StorageFile jpegFile = await wbm2.ToJpegFileAsync(jpegFilename); 

      // Yes, show the selected image. 
      tileImage.SetAttribute("src", jpegFile.Path); 
     } 

回答

3

src属性必须包含与MS-APPX一个URI:///,MS-应用程序数据:///本地,或http [S]://方案。与jpegFile.Path一起使用的StorageFile.Path属性是一个本地文件系统路径,如c:\ users \ Robert \ AppData ...,这将无效。因此,在本地应用程序数据中创建您的平铺图像,然后使用ms-appdata:/// local /在平铺有效载荷中引用它们。