很难创建 Microsoft Band 磁贴图标

Hard time creating a Microsoft Band tile icon

Microsoft Band SDK 文档中提到使用 WriteableBitmap 创建磁贴图标,但如何让它指向我为磁贴制作的现有图像?

如果您的 Windows Phone 应用程序有一个名为 "Assets/Icon1.png" 的资产,那么可以通过以下方式将该资产制作成 BandIcon:

using Microsoft.Band;
using Microsoft.Band.Tiles;
using Microsoft.Band.Tiles.Pages;
using Windows.Storage;
using Windows.Storage.Streams;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media.Imaging;

...

StorageFile imageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Icon1.png"));
using (IRandomAccessStream fileStream = await imageFile.OpenAsync(FileAccessMode.Read)
{
    WriteableBitmap bitmap = new WriteableBitmap(1,1);
    await bitmap.SetSourceAsync(fileStream);
    return bitmap.ToBandIcon();
}