【发布时间】:2014-08-28 05:28:04
【问题描述】:
我有一个用 C# 编写的适用于照片的 Windows 应用商店应用。我想在中等大小的动态磁贴 (150 x 150) 中显示用户在应用程序中选择的最后一张照片。我正在使用下面的代码来做到这一点。当我运行该应用程序时,我没有收到任何错误,但我也没有在动态磁贴中看到所选照片。我知道我至少在做一些正确的事情。我这样说是因为如果用户还没有选择照片,那么我会显示一张测试图像,并且我确实会在图块中看到该图像。但是测试图片来自使用ms-appx协议的应用包,而不是来自应用存储区。
我发现了一些关于该主题的 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);
}
【问题讨论】:
标签: c# windows-runtime windows-store-apps live-tile