Performance of FillRectangle() and Clear()
protected void PaintDocument(Graphics g)
{
Clear background to desired backcolor
(via Graphics.Clear())
Fill a black rectangle for the page's drop-shadow
(via Graphics.FillRectangle())
Fill a white rectangle for the page itself
(via Graphics.FillRectangle())
Perform some custom drawing code
}
The custom drawing code draws the actual contents of the document, and does quite a lot of calculations, painting polygons, and some pretty complex clipping regions.
I was a little concerned about performance so have just run a profiler over my code. Much to my surprise, only approximately 25% of my painting time is spent in my custom code, whereas the Clear() and FillRectangle() calls take up about 25% each. [Interestingly, if I turn off double buffering (with DoubleBuffered=false) then Clear() drops to only 0.05%, but FillRectangle() still takes most of the time.]
Why are Clear() and FillRectangle() so slow?!? Is there anything I can do to improve performance with these calls?
-
Andrew Wilkinson

