1

我不确定如何从WriteAbleBitmaptoIconicTileData的 url 属性IconImage

到目前为止,这是我的代码:

        protected override void OnInvoke(ScheduledTask task)
        {
            ShellTile tile = ShellTile.ActiveTiles.FirstOrDefault();

            if (tile != null)
            {
                WriteableBitmap genTile = renderTile(202, 202);

                tile.Update(new IconicTileData()
                {
                    Title = "IconicTileData",
                    IconImage = /* PATH TO genTile */
                });
            }

            ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(3));

            NotifyComplete();
        }

        private WriteableBitmap renderTile(int width, int height)
        {
            Canvas can = new Canvas();
            can.Background = new SolidColorBrush(Color.FromArgb(255, 0, 255, 0));
            can.Width = width;
            can.Height = height;

            WriteableBitmap tileImage = new WriteableBitmap(width, height);

            tileImage.Render(can, null);

            tileImage.Invalidate();
            return tileImage;
        }

解决方案是保存文件?我该怎么做,ShellTile 不与应用程序共享相同的空间?

4

1 回答 1

1

将文件保存到独立存储,然后在 Uri 中使用“isostore:”前缀。

public static void StoreSavedResultImage(string filename, WriteableBitmap wb)
        {
            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (isf.FileExists(filename))
                    isf.DeleteFile(filename);

                using (IsolatedStorageFileStream fs = isf.CreateFile(filename))
                {
                    wb.SaveJpeg(fs, wb.PixelWidth, wb.PixelHeight, 0, 100);
                    fs.Close();
                    wb = null;
                    img = null;
                }
            }
        }

如果您想在动态磁贴中引用独立存储中的文件,则该文件应保存在 /Shared/ShellContent 文件夹中。

Uri wideUri = new Uri("isostore:/Shared/ShellContent/app_wide.jpg"), UriKind.Absolute);

tile.Update(new IconicTileData()
                {
                    Title = "IconicTileData",
                    IconImage = wideUri
                });
于 2012-12-18T03:15:44.053 回答