如何在 Mango 中设置动态图块的 WriteableBitmap 背景颜色?

发布于 2024-12-14 07:57:42 字数 797 浏览 1 评论 0原文

我正在尝试动态构建动态图块。 由于一些建议,它运行得很好,我有这个代码:

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);
            }
}

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

I'm trying to dynamically build a live tile.
It runs fine thanks to some SO suggestions and I have this code:

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);
            }
}

The problem is that the tile has a black (or, better, transparent) background. I would like to use accent background color, how can I do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半山落雨半山空 2024-12-21 07:57:42

是这样解决的:

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

wbmp.Render(can, null);

Solved in this way:

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

wbmp.Render(can, null);
思念绕指尖 2024-12-21 07:57:42

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

You're better to use Resources["TransparentBrush"] as the background, and then save to png, otherwise, your tile will be the wrong color on a theme change.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文