title: DrawToBitmap - System.ArgumentException: Parameter is not valid
body: <p>Im creating a <code>Label</code> and sometimes Im using <code>.DrawToBitmap()</code>. I dont know why, but after Im running my program for a while (and calling <code>.DrawToBitmap()</code> often) I get the exception:</p>
  
  <pre><code>System.ArgumentException: Parameter is not valid.
     at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
     at System.Drawing.Bitmap..ctor(Int32 width, Int32 height)
  </code></pre>
  
  <p>Somehow I cannot call this function that often. If I would radically try this:</p>
  
  <pre><code>while(true)
  {
  
    System.Windows.Forms.Label label = new Label();
  
    label.Font = new Font("Arial", 20);
    label.Text = "test";
  
    try
    {
      Bitmap image = new Bitmap(300, 500);
      label.DrawToBitmap(image, label.ClientRectangle);
    }
    catch (Exception e)
    {
      Console.WriteLine(e);
    }
  }
  </code></pre>
  
  <p>I got after 5-6 secs (1000-2000 calls) the exception. What is the problem? How to avoid this?</p>
  
  <p>Edit: Thank you guys for the idea with <code>Dispose()</code> - somehow everything is working perfect if I use it on <code>label</code>. Even if I dont use it on Bitmap its fine. Both of the answers are great, I can only accept 1 of them :(</p>