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 Rectangle
s 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 Rectangle
s must be assumed to be visible?
Thanks in advance, Christoph
I suggest you use the array variant of the call instead:
FillRectangles(Brush brush, Rectangle[] rects);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With