Windows phone 7 如何在Mango中为活动磁贴设置WriteableBitmap返回颜色?
我正在尝试动态构建一个活动磁贴。 由于一些SO建议,它运行良好,我有以下代码:Windows phone 7 如何在Mango中为活动磁贴设置WriteableBitmap返回颜色?,windows-phone-7,live-tile,Windows Phone 7,Live Tile,我正在尝试动态构建一个活动磁贴。 由于一些SO建议,它运行良好,我有以下代码: WriteableBitmap wbmp = new WriteableBitmap(173, 173); TextBlock text = new TextBlock() { FontSize = (double)Resources["PhoneFontSizeLarge"], Foreground = new SolidColorBrush(Colors.White) }; text.Text = "my
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);
}
}
问题是瓷砖的背景是黑色的(或者更好的是透明的)。我想使用强调背景色,我该怎么做?通过以下方式解决:
Canvas can = new Canvas();
can.Background = (SolidColorBrush)Application.Current.Resources["PhoneAccentBrush"];
can.Width = 173;
can.Height = 173;
wbmp.Render(can, null);
您最好使用参考资料[“TransparentBrush”]作为背景,然后保存到png,否则,您的磁贴将在主题更改时使用错误的颜色