0

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();
}
peke-tsu
  • 51
  • 5

1 Answers1

1

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;
Romasz
  • 29,662
  • 13
  • 79
  • 154