我拼命尝试将可写位图设置为辅助图块图像的来源。我想我快到了,但它拒绝工作。谁能看到我错过了什么?我会很感激!
我正在使用以下方法创建位图:
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();
图像通过以下方式保存到计算机:
await WriteableBitmapSaveExtensions.SaveToFile(bitmap, ApplicationData.Current.LocalFolder,"image.png", CreationCollisionOption.ReplaceExisting);
该图像可以在目录中找到:
C:\Users\<USER>\AppData\Local\Packages\<PKGID>\LocalState
我正在使用这种方法创建辅助磁贴:
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);
}
磁贴已创建并固定到开始屏幕,但图像是 100% 透明的。