0

我正在尝试动态构建动态磁贴。由于一些 SO 建议,它运行良好,我有以下代码:

WriteableBitmap wbmp = new WriteableBitmap(173, 173);


TextBlock text = new TextBlock() { FontSize = (double)Resources["PhoneFontSizeLarge"], Foreground = new SolidColorBrush(Colors.White) };

text.Text = "my text";
wbmp.Render(text, new TranslateTransform() { Y = 20 });
wbmp.Invalidate();

// save image to isolated storage
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
     using (IsolatedStorageFileStream imageStream = new IsolatedStorageFileStream("/Shared/ShellContent/MyImage.jpg", System.IO.FileMode.Create, isf))
            {

                wbmp.SaveJpeg(imageStream, wbmp.PixelWidth, wbmp.PixelHeight, 0, 100);
            }
}

问题是该图块具有黑色(或者,更好,透明)背景。我想使用强调背景色,我该怎么做?

4

2 回答 2

1

以这种方式解决:

Canvas can = new Canvas();
can.Background = (SolidColorBrush)Application.Current.Resources["PhoneAccentBrush"];
can.Width = 173;
can.Height = 173;

wbmp.Render(can, null);
于 2011-11-08T01:01:21.490 回答
0

您最好使用 Resources["TransparentBrush"] 作为背景,然后保存为 png,否则,您的 tile 将在主题更改时出现错误的颜色。

于 2011-12-15T15:03:14.287 回答