Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is rendering a lot of repeated images more or less performant than using brushes in WPF?

An application our company is working on currently displays many rectangle shapes with gradients to draw 'Tiles'. An internal discussion came about that posed a question of performance. These tiles are about 100 pixels by 200 pixels, and are either gradient shaded red, yellow, or green. At any given time, there could be up to 100 of these tiles on screen. Would it be more performant for us to create an image for each (red, yellow, green) and repeat it when needed, or would it be better for us to continue drawing them using standard WPF brushes?

EDIT: To clarify, the gradient brush we're using is a LinearGradientBrush.

like image 819
Kilhoffer Avatar asked Jan 13 '10 18:01

Kilhoffer


2 Answers

From experience, drawing them using brushes will have far better performance. The overhead of loading up the tile images and rendering them is large compared to rendering filled rectangles.

like image 55
Charlie Avatar answered Nov 09 '22 03:11

Charlie


The only way to clear this up would be to try it both ways and measure the performance of each approach.

You'd need to add code to time the render loop and log the result to file, then force a 1000 (or even 100,000) redraws to be able to get a realistic figure.

My gut feeling is that the LinearGradientBrush would be quicker than loading an image (even from resources) - but I'm willing to be proved wrong.

like image 38
ChrisF Avatar answered Nov 09 '22 03:11

ChrisF