WPF drawing performance with large numbers of geometries

Posted by MyFaJoArCo on Stack Overflow See other posts from Stack Overflow or by MyFaJoArCo
Published on 2010-03-06T18:08:48Z Indexed on 2010/04/18 11:23 UTC
Read the original article Hit count: 288

Filed under:
|
|
|

Hello,

I have problems with WPF drawing performance. There are a lot of small EllipseGeometry objects (1024 ellipses, for example), which are added to three separate GeometryGroups with different foreground brushes. After, I render it all on simple Image control. Code:

DrawingGroup tmpDrawing = new DrawingGroup();
GeometryGroup onGroup = new GeometryGroup();
GeometryGroup offGroup = new GeometryGroup();
GeometryGroup disabledGroup = new GeometryGroup();

for (int x = 0; x < DisplayWidth; ++x)
{
    for (int y = 0; y < DisplayHeight; ++y)
    {
        if (States[x, y] == true) onGroup.Children.Add(new EllipseGeometry(new Rect((double)x * EDGE, (double)y * EDGE, EDGE, EDGE)));
        else if (States[x, y] == false) offGroup.Children.Add(new EllipseGeometry(new Rect((double)x * EDGE, (double)y * EDGE, EDGE, EDGE)));
        else disabledGroup.Children.Add(new EllipseGeometry(new Rect((double)x * EDGE, (double)y * EDGE, EDGE, EDGE)));
    }
}

tmpDrawing.Children.Add(new GeometryDrawing(OnBrush, null, onGroup));
tmpDrawing.Children.Add(new GeometryDrawing(OffBrush, null, offGroup));
tmpDrawing.Children.Add(new GeometryDrawing(DisabledBrush, null, disabledGroup));
DisplayImage.Source = new DrawingImage(tmpDrawing);

It works fine, but takes too much time - >0.5s on Core 2 Quad, >2s on Pentium 4. I need <0.1s everywhere. All Ellipses, how you can see, are equal. Background of control, where is my DisplayImage, is solid (black, for example), so we can use this fact. I tried to use 1024 Ellipse elements instead of Image with EllipseGeometries, and it was working much faster (~0.5s), but not enough. How to speed up it?

Regards, Oleg Eremeev

P.S. Sorry for my English.

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf