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