简体   繁体   English

wp8 writeablebitmap不呈现

[英]wp8 writeablebitmap doesn't render

I try to render some elements on writeable bitmap. 我尝试在可写位图上渲染一些元素。 It works when rendering textblock but not something else for example rectangle. 它在渲染文本块时起作用,而在其他情况下(例如矩形)则不起作用。 Why so? 为什么这样?

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

You are trying to render a Rectangle with Height = 0 - you have defined its Width twice. 您尝试渲染Height = 0的Rectangle已定义两次Width。

I suppose it should look like this: 我想它应该像这样:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM