Welcome to MSDN Blogs Sign in | Join | Help

Tips for creating massive amounts of shapes

I am often asked how to reduce the creation time for a massive number of shapes.

 

Try a few things:

1)      Use XamlReader.Load when you can (with the mini-language), which allows you to use the native parser and not managed code to create new shapes

2)      Use the mini-language for Paths or lines (whether using Xamlreader or C#) – both Silverlight and WPF optimize the mini-language internally, in different ways. When the mini-language is used, Silverlight does not create managed object for each PathFigure, Point etc– which saves creation time and space:

http://msdn.microsoft.com/en-us/library/cc189041(VS.95).aspx

 

3)      Switch to Bitmaps if appropriate.

4)      Prototype! Prototype! Prototype! Don't write everything and realize that SL can't generate 100,000 managed objects every 10msec. =)

 

Generally, for drawing massive number of shapes, you want to reduce the amount of time spent in managed creation time.

-Seema

Published Thursday, May 28, 2009 10:10 AM by seemar

Comments

# Tips for creating massive amounts of shapes | Microsoft Share Point

# re: Tips for creating massive amounts of shapes

Friday, May 29, 2009 7:17 PM by EugenRata

Well, no body is expecting to paint 100,000 objects. I would be happy if SL | WPF would paint 2000 rectangles at least with a reasonable speed.

I could achieve this using Path and Geometries + XamlReader, but the problem here is I can't set the gradient Brush for each rectangle. So, I'm back to my issue.

Any idea?

Just show me a simple sample (WPF is fine, but must be compatible with SL) that paints 2000 rectangles each with a gradient and when you resize the window it will repaint and scale immediatly all the rectangles.

I bet $100 that at least 100 developers would like to see such a sample!

Thx

# re: Tips for creating massive amounts of shapes

Saturday, May 30, 2009 7:22 AM by Gongdo

Also IsHitTestVisible="False" will increase graphic performance after objects loaded, if objects don't need to interact with user.

However I'm not sure whether it could reduce amount of creating time or not. How is it, Seema?

# re: Tips for creating massive amounts of shapes

Sunday, June 07, 2009 2:01 AM by SharpGIS

Regarding #2, how would I set the data on an path geometry?

The following throws throws an ArgumentException:

myPath.SetValue(Path.DataProperty, "M 10,100 C 10,300 300,-200 300,100");

# re: Tips for creating massive amounts of shapes

Tuesday, June 09, 2009 7:04 PM by EugenRata

yeah, you can't set the Path value as a string in Silverlight.

However it works correctly in WPF.

Any idea Seema?

Anonymous comments are disabled
 
Page view tracker