title: Image draw speed
body: <p>i am working on a game, but currently I am running benchmarks.</p>
  
  <p>If anyone can help me on this matter, I would greatly appreciate it.</p>
  
  <p>What I am doing, is I fire the paint event on a panel when I click the start button, with this code:</p>
  
  <pre><code>    private void startToolStripMenuItem_Click(object sender, EventArgs e)
      {
          try
          {
              pnlArea.Invalidate();
  
          }
          catch (Exception)
          {
              throw;
          }
      }
  </code></pre>
  
  <p>I then do this in my paint event:</p>
  
  <pre><code>    private void pnlArea_Paint(object sender, PaintEventArgs e)
      {
          try
          {
              stopwatch = new Stopwatch();
              // Begin timing
              stopwatch.Start();
  
              if (gameStatus == GameStatus.PlaceHead)
              {
                  e.Graphics.DrawImage(dictHead["HeadRight"], 100, 100, 15, 15);
              }
  
              //e.Graphics.Clear(Color.White);
  
              if (gameStatus == GameStatus.GameTest)
              {
                  int x = 0;
                  int y = 0;
                  for (int i = 0; i &lt; 5000; i++)
                  {
                      x += 15;
                      if (x &gt; 1000)
                      {
                          x = 0;
                          y += 15;
                      }
  
                      e.Graphics.DrawImage(body.Value, x, y, 15, 15);
  
                  }
              }
  
              toolTimer.Text = Math.Round((stopwatch.Elapsed.TotalMilliseconds / 1000), 2).ToString() + "s";
  
              // Stop timing
              stopwatch.Stop();
          }
          catch (Exception)
          {
  
              throw;
          }
      }
  </code></pre>
  
  <p>This is the body part I am drawing in the code above:</p>
  
  <p><img src="https://i.stack.imgur.com/qO53V.png" alt="enter image description here"></p>
  
  <p>This is the exact size --> 15px x 15px</p>
  
  <p>but this takes up to 1.2 seconds sometimes!!!
  is there a way I can improve this?</p>
  
  <p>this is a sample of the end result screen:
  <img src="https://i.stack.imgur.com/RnV8p.png" alt="enter image description here"></p>