wp8 writeablebitmap不呈现

时间:2014-02-05 09:57:52

标签: c# windows-phone-8 render writeablebitmap

我尝试在可写位图上渲染一些元素。它在渲染文本块时有效,但在其他方面不起作用,例如矩形。为什么这样?

void bm_ImageOpened(object sender, RoutedEventArgs e)
{
        WriteableBitmap wbm = new WriteableBitmap((BitmapImage)sender);

        TextBlock tb = new TextBlock();
        tb.FontSize = 40;
        tb.Text = "text";

        Rectangle rt = new Rectangle();
        rt.Width = 50;
        rt.Width = 30;
        rt.Fill = new SolidColorBrush(Colors.Red);

        TranslateTransform tf = new TranslateTransform();
        tf.X = 100;
        tf.Y = 100;
        wbm.Render(tb, tf); //this works
        wbm.Render(rt, tf); //this not

        wbmi.Invalidate();
}

1 个答案:

答案 0 :(得分:1)

您正尝试渲染高度= 0的Rectangle - 您已将其宽度定义了两次。

我想它应该是这样的:

rt.Width = 50;
rt.Height = 30;