我正在尝试创建一个可写位图。我想将图像加载到我的可写中,但它不起作用(请注意图像):
这是我的代码:
var b = new WriteableBitmap(336, 336);
var background = new Canvas();
background.Height = b.PixelHeight;
background.Width = b.PixelWidth;
background.Background = new SolidColorBrush(Colors.Red);
var canvas = new Grid();
canvas.Width = b.PixelWidth;
canvas.Height = b.PixelHeight;
var textBlock = new TextBlock();
textBlock.Text = "sample";
textBlock.Margin = new Thickness(0, 150, 0, 0);
textBlock.Width = 336;
textBlock.Foreground = new SolidColorBrush(Colors.Blue); //color of the text on the Tile
textBlock.FontSize = 26;
canvas.Children.Add(textBlock);
Image img = new Image();
img.Source = new BitmapImage(new Uri("Images/TileBgs/Medium/sun.png", UriKind.Relative));
img.ImageOpened += (s, e) =>
{
b.Render(background, null);
b.Render(img, null);
b.Render(canvas, null);
b.Invalidate(); //Draw bitmap
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream imageStream = new IsolatedStorageFileStream("/Shared/ShellContent/myImage.jpg", System.IO.FileMode.Create, isf))
{
b.SaveJpeg(imageStream, b.PixelWidth, b.PixelHeight, 0, 100);
}
}
};
怎么了??