title: Render many elements to DrawingVisual
body: <p>I have some problems with performance in my code…
  I need to render many-colored rectangles to my DrawingVisual.</p>
  
  <p>The first version is simple:</p>
  
  <pre><code>using (DrawingContext dc = Canvas.RenderOpen())
  {
     for (Int32 x = 0; x &lt; widthCount; x++)
        for (Int32 y = 0; y &lt; heightCount; y++)
        {
            Color c;
            Double value = mass[x, y];
            c = GetColorByValue(value);
            dc.DrawRectangle(new SolidColorBrush(c), null,
            new Rect(x * step - step / 2, y * step - step / 2, step, step));
         }
  }
  </code></pre>
  
  <p>And it works normal in case of the quantity of rectangles is about 250x250 (and it gets 200Mb RAM). But if the number of them is 750x750 the process of rendering is too long and slow (gets more than 2.5Gb RAM)</p>
  
  <p>The next step was using a bitmap like a buffer. But there is a problem with the size of my DrawingVisual. Visual is really large.
  So it is impossible to create a full-size bitmap because the constructor of RenderTargetBitmap throws the Exception “The image data generated an overflow during processing”.</p>
  
  <p>Finally I created a small bitmap and stretched it to my visual. However the problem is the same (it works too slow and gets a lot of RAM).</p>
  
  <p>What should I do to make the process of rendering elements to get adequate time and sources?</p>
  
  <p>Regards!</p>
  
  <p>Thanks!</p>