I'm desperately trying to set a writeable bitmap as the source of a secondary tiles image. I think I'm almost there but it refuses to work. Can anybody see what I'm missing? I would be VERY grateful!
I'm creating the bitmap using:
var bitmap = new WriteableBitmap(150, 150);
Stream stream = bitmap.PixelBuffer.AsStream();
stream.Seek(0, SeekOrigin.Begin);
var pixels = new byte[stream.Length];
for (int i = 0; i < pixels.Length; i += 4)
{
pixels[i] = 255;
pixels[i + 1] = 0;
pixels[i + 2] = 189;
pixels[i + 3] = 9;
}
stream.Write(pixels, 0, pixels.Length);
bitmap.Invalidate();
The image is saved to the computer with:
await WriteableBitmapSaveExtensions.SaveToFile(bitmap, ApplicationData.Current.LocalFolder,"image.png", CreationCollisionOption.ReplaceExisting);
The image can be found in the directory:
C:\Users\<USER>\AppData\Local\Packages\<PKGID>\LocalState
I'm creating the secondary tile using this method:
CreateSecondaryTileFromWebImage("image.png", "tildId","shortName","displayName","arguments", MainPage.GetElementRect((FrameworkElement)sender));
public async Task CreateSecondaryTileFromWebImage(string bitmapName, string tileId, string shortName, string displayName, string arguments, Rect selection)
{
//Create uri
var bitmap = new Uri(string.Format("ms-appdata:///local/{0}", bitmapName));
//Create tile
SecondaryTile secondaryTile = new SecondaryTile(tileId, shortName, displayName, arguments, TileOptions.ShowNameOnLogo, bitmap);
//Confirm creation
await secondaryTile.RequestCreateForSelectionAsync(selection, Windows.UI.Popups.Placement.Above);
}
The tile is created and pinned to the startscreen but the image is 100% transparent.