title: C#/.Net code to screen capture multiple monitors with scaling
body: <p>We have a large WinForm C# .Net 4.6 program which from time to time needs to do obtain screen captures for debugging purposes. We currently use this code:</p>
  
  <pre><code>private static void DoScreenCapture(string filename)
  {
      // Determine the size of the "virtual screen", including all monitors.
      int screenLeft = SystemInformation.VirtualScreen.Left;
      int screenTop = SystemInformation.VirtualScreen.Top;
      int screenWidth = SystemInformation.VirtualScreen.Width;
      int screenHeight = SystemInformation.VirtualScreen.Height;
  
      // Create a bitmap of the appropriate size to receive the screenshot.
      using (Bitmap bmp = new Bitmap(screenWidth, screenHeight))
      {
          // Draw the screenshot into our bitmap.
          using (Graphics g = Graphics.FromImage(bmp))
          {
              g.CopyFromScreen(screenLeft, screenTop, 0, 0, bmp.Size);
          }
  
          // Stuff the bitmap into a file
          bmp.Save(filename, Imaging.ImageFormat.Png);
      }
  }
  </code></pre>
  
  <p>This code does all that we want, except when the user has scaled his monitors.</p>
  
  <p>I've looked at bunches of Stack Overflow articles. Most of them provide code like we already have, but that doesn't handle the monitor scaling issue. For example:</p>
  
  <p><a href="https://stackoverflow.com/questions/15847637/take-screenshot-of-multiple-desktops-of-all-visible-applications-and-forms">Take screenshot of multiple desktops of all visible applications and forms</a></p>
  
  <p>Some Stack Overflow articles indicate that making our application DPI aware would solve the problem. Yes, it would, but that's more than we can tackle today. For example:</p>
  
  <p><a href="https://stackoverflow.com/questions/47015893/windows-screenshot-with-scaling">Windows screenshot with scaling</a></p>
  
  <p>There is also code which will do a capture for all monitors one at a time, but we much prefer to have all the monitors captured in the same image.</p>
  
  <p>Can someone give me a C# code snippet which will take a screenshot of multiple monitors which have varied scaling factors?</p>
  
  <p>For example, if I have three identical 1920x1080 monitors and arrange them left to right with the leftmost monitor at 175%, the center monitor at 100%, and the rightmost monitor at 150%, then this would be the screenshot that I want:</p>
  
  <p><a href="https://i.stack.imgur.com/0ysJo.png" rel="nofollow noreferrer">Expected screenshot</a></p>
  
  <p>But this is the screenshot that my current code produces. Note that the rightmost monitor is missing a piece on the far right.</p>
  
  <p><a href="https://i.stack.imgur.com/QVplT.png" rel="nofollow noreferrer">Actual screenshot</a></p>