分配给实时图块的动态图像不显示?

时间:2014-08-28 05:28:04

标签: c# windows-runtime windows-store-apps live-tile

我有一个用C#编写的Windows应用商店应用照片。我想在中等大小的实时图块(150 x 150)中显示用户在应用中选择的最后一张照片。我正在使用下面的代码来做到这一点。当我运行应用程序时,我没有收到任何错误,但我也没有在实时图块中看到所选照片。我知道我至少做了一些正确的事。我这样说是因为如果用户还没有选择照片,那么我会显示一张测试图像,我确实在图块中看到了该图像。但测试图像来自使用 ms-appx 协议的应用程序包,而不是来自应用程序存储区域。

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

注意, vvm.ActiveVideomark.GetThumbnail()调用只是将位图检索为 WriteableBitmap 对象。正如您在代码中看到的那样,我将图像的大小调整为Medium live tile(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);
        }

1 个答案:

答案 0 :(得分:3)

src属性必须包含带有ms-appx:///,ms-appdata:/// local或http [s]:// scheme的URI。正如您在jpegFile.Path中使用的那样,StorageFile.Path属性是一个本地文件系统路径,例如c:\ users \ Robert \ AppData ......它不会有效。因此,在本地应用数据中创建切片图像,然后使用ms-appdata:/// local /在tile有效负载中引用它们。