简体   繁体   中英

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.

I suppose it should look like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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