繁体   English   中英

无法使动态生成的切片正常工作(Windows Phone)

[英]Can't get dynamically generated tile working (Windows Phone)

我有在Application_Deacitvated / Closing()中执行的方法。

public bool createBackTile()
    {
        if(AlarmClock.IsExists())
        {

            ImageBrush background = new ImageBrush()
            {
                ImageSource = new BitmapImage(new Uri("/BackBackgroundTheme.png", UriKind.Relative)),
                AlignmentX = AlignmentX.Center,
                AlignmentY = AlignmentY.Center
            };

            // Preparing tile image.
            TextBox tileImageData = new TextBox()
            {
                Text = AlarmClock.Read().ToShortTimeString(),
                FontSize = 45,
                FontWeight = FontWeights.Bold,
                Foreground = new SolidColorBrush(Colors.White),
                //Background = background,
                Height = 173,
                Width = 173,
                HorizontalContentAlignment = HorizontalAlignment.Center,
                VerticalContentAlignment = VerticalAlignment.Center,
                Padding = new Thickness(-12),
                Margin = new Thickness(0),
                Clip = new RectangleGeometry { Rect = new Rect(0, 0, 173, 173) }
            };

            Canvas canvas = new Canvas()
            {
                Width = 173,
                Height = 173,
                Background = background,
                Margin = new Thickness(0)
            };

            canvas.Children.Add(tileImageData);

            // Saving tile image.
            WriteableBitmap tileImage = new WriteableBitmap(173, 173);
            tileImage.Render(canvas, null);
            tileImage.Render(tileImageData, null);
            tileImage.Invalidate();
            using(var stream = IsolatedStorageFile.GetUserStoreForApplication().CreateFile("/Shared/ShellContent/BackBackground.jpg"))
            {
                tileImage.SaveJpeg(stream, 173, 173, 0, 100);
            }

            // Sets data for tile.
            StandardTileData tileData = new StandardTileData()
            {
                BackgroundImage = new Uri("BackgroundAlarmSet.png", UriKind.Relative),
                BackBackgroundImage = new Uri(@"isostore:/Shared/ShellContent/BackBackground.jpg"),
                BackContent = "",
                BackTitle = "",
            };

            // Sets tile.
            ShellTile.ActiveTiles.FirstOrDefault().Update(tileData);

            return true;
        }

        return false;
    }

因此,如您所见,我想生成一个带有文本的图块,其文本位于图像背景“ BackBackgroundTheme.png”的中心。 我正在尝试将该图块保存在IsolatedStorage中,并将其分配给BackBackgroundImage。

但这是行不通的。 磁贴正在翻转,但BackBackground完全是黑色的。 我已经加载了这种可操纵的背景,似乎确实只是黑匣子。 那么,如何使其工作呢?

试试: BackgroundImage = new Uri(@"isostore:/Shared/ShellContent/BackBackground.jpg", UriKind.Absolute)

我终于找到问题所在。

似乎在Application_Closing / Deactivating()中未正确完成切片图像的生成。 因此,我将图像生成移到其他地方,现在,当应用程序关闭/停用时,我只是将先前生成的图像设置为图块。

尝试这个:

canvas.Children.Add(tileImageData);
canvas.UpdateLayout();
        // Saving tile image.
        WriteableBitmap tileImage = new WriteableBitmap(173, 173);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM