我正在尝试在 Canvas 上绘制 ~150 个 GeometryDrawing 对象。
我通过将它们添加到绘图组来做到这一点。在绘图组Open()
中,添加 GeometryDrawings,使用 绘制组,DrawingContext
然后Close()
使用DrawingContext
. 我将结果添加到 aImage.Source
并将其添加到画布中。
关闭时,我的应用程序抛出一个System.StackOverflowException
,我似乎无法找出原因?
internal void Draw(List<GameObject> gameObjects, List<Ray> lighting)
{
DrawingGroup group = new DrawingGroup();
List<GeometryDrawing> geometries = new List<GeometryDrawing>();
geometries.AddRange(Draw(gameObjects));
geometries.AddRange(Draw(lighting));
DrawingContext dc = group.Open();
foreach (GeometryDrawing g in geometries)
{
group.Children.Add(g);
}
dc.DrawDrawing(group);
dc.Close();
Image image = new Image();
image.Width = 800;
image.Height = 500;
DrawingImage di = new DrawingImage(group);
image.Source = di;
Canvas.SetTop(image, 0);
Canvas.SetLeft(image, 0);
canvas.Children.Add(image);
}