title: Need something to draw many images quickly in WPF
body: <p>I'm working on Generator of cellular automata in .NET 3.5. I decided to use WPF because I wanted to learn something new in WPF.</p>
  
  <p>I draw OneDimensional automata like Rule 30 and TwoDimensional like <a href="http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life" rel="noreferrer">Life</a>.</p>
  
  <p>I need something to draw many images quick.</p>
  
  <p>For example, dimensions of mesh is 64 x 64 and size of cell is 12px. So I draw 64*64 = 4096 images in one step. And interval between one step is about 100 ms.</p>
  
  <p>I rewrite my application to the WinForms and there is everything ok. But in WPF is slow and I don't know why.</p>
  
  <hr>
  
  <p><strong>My example of drawing in WPF:</strong></p>
  
  <p>I have a class derived from Image. In this class I draw a bitmap and I use it in Source property.</p>
  
  <pre><code>        public void DrawAll()
      {
  
          DrawingGroup dg = new DrawingGroup();
  
  
          for (byte i = 0; i &lt; this.DimensionX; ++i)
          {
  
              for (byte j = 0; j &lt; this.DimensionY; ++j)
              {
  
                  Piece p = this.Mesh[i][j];
  
                  Rect rect = new Rect(j * this.CellSize + (j + 1), i * this.CellSize + (i + 1),
                      this.CellSize, this.CellSize);
  
                  ImageDrawing id = new ImageDrawing();
                  id.Rect = rect;
  
                  if (p == null)
                      id.ImageSource = this._undefinedPiece.Image.Source;
                  else
                      id.ImageSource = p.Image.Source;
  
  
                  dg.Children.Add(id);
  
  
              }
  
          }
  
          DrawingImage di = new DrawingImage(dg);
  
          this.Source = di;
  
      }
  </code></pre>
  
  <p>Second example of drawing in WPF:</p>
  
  <p>I have derived class from Canvas and override OnRender function. Based on this article: <a href="http://sachabarber.net/?p=675" rel="noreferrer">http://sachabarber.net/?p=675</a></p>
  
  <pre><code>protected override void OnRender(DrawingContext dc)
      {
          base.OnRender(dc);
  
          for (byte i = 0; i &lt; this.DimensionX; ++i)
          {
  
              for (byte j = 0; j &lt; this.DimensionY; ++j)
              {
  
  
                  Rect rect = new Rect(j * this.CellSize + (j + 1), i * this.CellSize + (i + 1),
                      this.CellSize, this.CellSize);
  
  
  
                  BitmapImage bi;
  
                  int counter = i + j + DateTime.Now.Millisecond;
  
                  if (counter % 3 == 0)
                      bi = this.bundefined;
                  else if (counter % 3 == 1)
                      bi = this.bwhite;
                  else
                      bi = this.bred;
  
  
                  dc.DrawImage(bi, rect);
  
                  ++counter;
  
              }
  
          }
      }
  </code></pre>
  
  <p>Thanks for all replies</p>