簡體   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