0

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?

Heinrich Ulbricht
  • 10,064
  • 4
  • 54
  • 85
Cris
  • 12,124
  • 27
  • 92
  • 159

2 Answers2

1

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);
Cris
  • 12,124
  • 27
  • 92
  • 159
0

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.

Anthony Wieser
  • 4,351
  • 1
  • 23
  • 25