开发者

How to properly draw a GeometryDrawing on a Canvas in WPF (performance-wise)

A few d开发者_如何学运维ays ago I asked the following question: How to draw graphics as efficiently as possible in WPF

The consensus was that using a Canvas as host-object in combination with GeometryDrawing classes I had nothing to fear performance-wise.

Though, after implementing a simple test, I came to the conclusion the application chokes on only 3000 of those objects on-screen.

During the implementation, I noticed I had to encapsulate a GeometryDrawing object in 2 different objects (DrawingImage and Image) before I could make the Canvas render it, I think this is where the chokepoint is. Below is an example code on how I do this currently:

//Node
GeometryDrawing geoNode = new GeometryDrawing(
    new SolidColorBrush(Utils.IntToColor(graphNode.Color)), 
    new Pen(Brushes.Black, graphNode.Thickness), 
    new EllipseGeometry(new Point(graphNode.Position.X, graphNode.Position.Y), 16, 16)
);

Image imageNode = new Image
{
    Source = new DrawingImage(geoNode),
};

SetLeft(imageNode, graphNode.Position.X);
SetTop(imageNode, graphNode.Position.Y);

Children.Add(imageNode);

My questions are:

  • Is encapsulating the GeometryDrawing objects the proper method to get them rendered?

  • Is there a faster way to display my GeometryDrawing objects without having to encapsulate them (eg. something else than Canvas)?

  • Am I expecting too much if I want good performance with 3000 on-screen objects using WPF? It doesn't seem like a high-number to me, as a proper 2D engine can render 10000 objects and still run smoothly. Besides, it has been pointed out that "under the hood" WPF uses DirectX.

Thanks!


I ended up using WPF for the interface and used SlimDX/XNA for the actual rendering. The library that came out of it this will be available some time later.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜