我有一个用C#编写的Windows应用商店应用程序,可以处理照片。我想在中等大小的实时平铺(150 x 150)中显示用户在应用程序中选择的最后一张照片。我正在使用下面的代码来执行此操作。当我运行应用程序时,我没有收到任何错误,但我也没有在实时互动程序中看到所选照片。我知道我至少做了一些正确的事情。我这么说是因为如果用户还没有选择照片,那么我会显示一个测试图像,我会在平铺中看到该图像。但测试图像来自使用
毫秒appx
协议,而不是从应用程序存储区域。
我找到了一些关于这个主题的SO帖子,但都是针对Windows Phone的。我看着
已知文件夹
Windows应用商店应用程序文件的列表,但似乎没有任何内容映射到
共享内容
Windows Phone中用于实时平铺的文件所需的文件夹。我的代码有什么问题?
注意
vvm.ActiveVideomark.GetThumbnail()
调用只需将位图作为
可写位图
对象正如您在代码中看到的,我正在将图像大小调整为中等活动平铺所需的大小(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);
}