Search code examples
microsoft-band

Hard time creating a Microsoft Band tile icon


It says in the Microsoft Band SDK Documentation about using a WriteableBitmap to create a tile icon, but how do I get it to point to the existing image I made for the Tile?


Solution

  • If your Windows Phone app has an asset named "Assets/Icon1.png", then that asset can be made into a BandIcon by something like:

    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();
    }