0

Do you have any idea how Graphics object using resources?

I am drawing several thousands GraphicsPath objects with latitude longitude coordinate on a Panel. Initially those Graphicspaths has to be zoomed (transformed - 4 matrix transformation actually). Then user can move the map around, zooming, with each action called for repainting the graphics path.

The problem is the whole thing is still responsive when zoom level is around 2000-10000, but when it gets to hundreds of thousands (which is the street level zoom) it takes too long to paint and cause the whole application unresponsive. Check the free memory, still plenty of them. CPU usage is still OK.

How come drawing the same thousands of Graphics Path, with the same 4 matrix transformation each becomes extremely slow when zoom factor were increased? Is the problem in the System.Graphics itself when handling Graphics Path coordinate with large number? Do you guys ever face the same problem?

  • Sorry good people, for not including the code: so here is chunk of the "slow" code: basicaly the iteration part of _paint method. it runs over 30,000 Graphics path, most are polylines extracted from esri shp files. the coordinates for x are + and y are - and fliped upside down so hence the required matrix transform to be painted on panel. The problem is at low value variable zI, it's much faster than the hi-value variable zI. Hi-value zi means much of the graphics path is outside the painted area. I try to reduce the amount of zi by checking isVisible or by interecting rectangle bound. but that still not fast enough. any ideas?

                foreach (GraphicsPath vectorDraw in currentShape.vectorPath)
                {
                    GraphicsPath paintPath = (GraphicsPath)vectorDraw.Clone();
    
    
                    OperationMatrix = new Matrix();
                    OperationMatrix.Translate(-DisplayPort.X, -DisplayPort.Y);
                    paintPath.Transform(OperationMatrix);
                    OperationMatrix = new Matrix();
                    OperationMatrix.Scale(zI, zI);
                    paintPath.Transform(OperationMatrix);
                    OperationMatrix = new Matrix(1, 0, 0, -1, 0, DisplaySize.Height);
                    paintPath.Transform(OperationMatrix);
    
                    OperationMatrix = new Matrix();
                    OperationMatrix.Translate(ClientGap.Width, -ClientGap.Height);
                    paintPath.Transform(OperationMatrix);
    
                    //if (WiredPort.IsVisible(paintPath.GetBounds())) //Futile attempt
                    //{
    
                    Pen LandBoundariesPen = new Pen(Color.FromArgb(255, 225, 219, 127));
    
                    GraphContext.DrawPath(LandBoundariesPen, paintPath); // this is the slowest part. When commented it goes faster.
    
                    pathCountX++;
                }
    

Help .... :)

  • You should show us your code if you want we could help you – Daniele Armanasco Apr 04 '13 at 12:48
  • 2
    Any painting code that needs to render hundreds of thousands of paths is going to be slow. There is no magic fix, you will need to reconsider your design. Take a cue from, say, Google maps and note how it starts to drop details when you zoom out. – Hans Passant Apr 04 '13 at 13:46

1 Answers1

0

For high performance rendering, directX is perferred over WPF. You can also consider using opengl in C#.

Edit: For tutorial on how to use Open GL in C# via the TAO framework, visit below link: http://xinyustudio.wordpress.com/2008/12/01/using-opengl-in-c-taoframework/

David
  • 15,894
  • 22
  • 55
  • 66