Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF渲染:使用DrawingImage与DrawingVisual以接收drawingContext_C#_Wpf - Fatal编程技术网

C# WPF渲染:使用DrawingImage与DrawingVisual以接收drawingContext

C# WPF渲染:使用DrawingImage与DrawingVisual以接收drawingContext,c#,wpf,C#,Wpf,我需要用WPF渲染一些几何图形。我不想使用形状,因为它们的UI开销很大。我想通过drawingContext进行渲染。现在有不同的方法来达到drawingContext。据我所知,一种选择是使用绘图类的后代,例如Drawinggroup,请参见: using(var context = System.Windows.Media.drawingGroup.Open()) { context.DrawGeometry(Brushes.Blue, shapeOutline

我需要用WPF渲染一些几何图形。我不想使用形状,因为它们的UI开销很大。我想通过drawingContext进行渲染。现在有不同的方法来达到drawingContext。据我所知,一种选择是使用绘图类的后代,例如Drawinggroup,请参见:

 using(var context = System.Windows.Media.drawingGroup.Open())
      {
        context.DrawGeometry(Brushes.Blue, shapeOutlinePen, polygon);
      }
有了它,我可以创建DrawingImage并将其用作图像源以显示,请参见:

   var drawingImage = new DrawingImage(drawingGroup);
   this.image1.Source = drawingImage;
另一个选项是使用DrawingVisual类,如下所示:

  var visual = new DrawingVisual();
  using (DrawingContext context = visual.RenderOpen())
        {
         context.DrawGeometry(Brushes.Blue, shapeOutlinePen, polygon1);
         context.DrawGeometry(Brushes.Blue, shapeOutlinePen, polygon2);
         context.Close();
        }

  collection.Add(visual);
在本例中,集合是一个VisualCollection,它使用Frameworkelement作为其主机(父级)。可以在UI中使用此Frameworkelement以显示视觉效果

现在回答我的问题:

  • 有没有更多的方法来实现这一点
  • 你怎么决定走哪条路
  • Drawingimage提供了DrawingVisual没有的功能?(或者相反 周围)
  • 这两种方法都有哪些后果
  • 性能和/或多线程注意事项如何

谢谢你的输入

使用
DrawingContext
最简单、最直接的方法是派生UIElement或FrameworkElement的重写
OnRender
方法:

public class SimpleDrawing : UIElement
{
    protected override void OnRender(DrawingContext drawingContext)
    {
        base.OnRender(drawingContext); // not strictly necessary

        // your rendering code goes here
    }
}
Thanx我将测试这个(第三个)方法!然而,仍然没有决定该怎么走,为什么。。。