I have an application drawing a lot of small rectangles (about 1 million) using GDI+ in C# and the performance is… not so good. I understand that constructing a lot of Rectangle objects for passing them to Graphis.FillRectangle takes some time. I also understand that I cannot avoid this if the Rectangles change from from frame to frame, because Rectangle is designed to be immutable. My question therefore is: is there any possibility to improve the performance of this drawing call except if all Rectangles must be assumed to be visible?
Thanks in advance,
Christoph
I suggest you use the array variant of the call instead:
If that does not work for you because you need different brushes or the like, you should group the primitives by state (brush) and draw the arrays each in a single go. A quick test shows at least three times the performance, i.e. 300K Rectangles drawn individually feel about as choppy as 1M Rectangles drawn in one go.