0

我正在尝试创建一个可写位图。我想将图像加载到我的可写中,但它不起作用(请注意图像): 在此处输入图像描述

这是我的代码:

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

怎么了??

4

1 回答 1

1
     var canvas = new Canvas();
        canvas.Width = 336;
        canvas.Height = 336;
        canvas.Background = new SolidColorBrush(Colors.Red);
        var textBlock = new TextBlock();
        textBlock.Text = "sample";
        textBlock.Margin = new Thickness(130, 250, 0, 0);
        textBlock.Width = 336;
        textBlock.Foreground = new SolidColorBrush(Colors.Blue); 
        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.Margin = new Thickness(40, 10, 0, 0);
        img.Width = 250;
        canvas.Children.Add(img);
        Maingrid.Children.Add(canvas);
于 2014-04-24T07:47:08.123 回答