title: How to create a bitmap from a Device Context?
body: <p>I have been drawing into a Device Context, and now I want to be able to save the contents of the device context to an image. If saving directly from the bitmap is not the best way then how can I get from the device context to the bitmap? I am trying to do this in C#.</p>
  
  <p>EDIT: Thanks to SeriesOne I was able to modify his code to save a DC into a BMP. Here is how I changed it:</p>
  
  <pre><code>  Rectangle bmpRect = new Rectangle(0, 0, 640, 480);
                     // Create a bitmap
                     using (Bitmap bmp = new Bitmap(bmpRect.Width, bmpRect.Height))
                     {
                         Graphics gfx = Graphics.FromHdc(hdcScreen);
                         bmp.Save("C:\\MyBitmap.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
                         gfx.Dispose();
                     }
  </code></pre>