分配给活动磁贴的动态图像不显示

本文关键字:动态 图像 显示 活动 分配 | 更新日期: 2023-09-27 18:19:49

我有一个用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);
        }

分配给活动磁贴的动态图像不显示

src属性必须包含一个带有ms-appx:///,ms的URI-appdata:///local,或http[s]://schemes。与jpegFile.Path一起使用的StorageFile.Path属性是一个本地文件系统路径,类似于c:''users''Robert''AppData。。。这将是无效的。因此,在本地应用程序数据中创建你的互动程序图像,然后使用ms-appdata:///local/以在瓦片有效载荷中引用它们。