title: C# screenshot bug?
body: <p>I use the following code to take a screenshot:</p>
  
  <pre><code>var rc = SystemInformation.VirtualScreen;
  Bitmap bmp = new Bitmap(rc.Width, rc.Height);
  Graphics g = Graphics.FromImage(bmp);
  g.CopyFromScreen(rc.Left, rc.Top, 0, 0, bmp.Size, CopyPixelOperation.SourceCopy);
  </code></pre>
  
  <p>Now this works wonderfully and it's easy to work with, however I always come across little 'white dots' in some of the screenshots. This can be very annoying and distort the image when it occurs in larger quantities.</p>
  
  <p>I managed to narrow down the issue and when I try to take a screenshot of the following image the bug occurs: </p>
  
  <p><img src="https://i.imgur.com/OTFpahP.png" alt="bug-causing image"></p>
  
  <p>The output of the screenshot looks like this:</p>
  
  <p><img src="https://i.imgur.com/8nd1uz2.png" alt="bug"></p>
  
  <p>How can you fix this?
  And out of curiosity, how is this explained?</p>
  
  <p>In my testing environment the screenshot isn't saved at all. I directly use it with the following code:</p>
  
  <pre><code>pictureBox1.Image = bmp;
  </code></pre>
  
  <p>tl;dr I'm trying to take screenshots and some of the pixels are replaced with white and distort the result.</p>
  
  <p>Thank you very much in advance.</p>
  
  <p>EDIT: It turns out that the bitmap makes the area transparent (white comes from the background color of the form, thanks for spotting this spender!)</p>
  
  <p><img src="https://i.imgur.com/zLOaLcM.png" alt="bug with different background"></p>
  
  <p>But obviously as you can clearly see in the first picture; I'm not trying to capture any transparent content. Why does it do this?</p>
  
  <p>EDIT2:</p>
  
  <p>This is the whole class I'm using to select my screenshot:</p>
  
  <pre><code>public partial class SnippingTool : Form
  {
      public static Image Snip()
      {
          var rc = SystemInformation.VirtualScreen;
  
          Bitmap bmp = new Bitmap(rc.Width, rc.Height);
          Graphics g = Graphics.FromImage(bmp);
          g.CopyFromScreen(rc.Left, rc.Top, 0, 0, bmp.Size, CopyPixelOperation.SourceCopy);
  
          var snipper = new SnippingTool(bmp);
  
          if (snipper.ShowDialog() == DialogResult.OK)
          {
              return snipper.Image;
          }
  
          return null;
      }
  
      public SnippingTool(Image screenShot)
      {
          InitializeComponent();
          this.BackgroundImage = screenShot;
          this.ShowInTaskbar = false;
          this.FormBorderStyle = FormBorderStyle.None;
          this.StartPosition = FormStartPosition.Manual;
  
          int screenLeft = SystemInformation.VirtualScreen.Left;
          int screenTop = SystemInformation.VirtualScreen.Top;
          int screenWidth = SystemInformation.VirtualScreen.Width;
          int screenHeight = SystemInformation.VirtualScreen.Height;
  
          this.Size = new System.Drawing.Size(screenWidth, screenHeight);
          this.Location = new System.Drawing.Point(screenLeft, screenTop);
  
  
          this.DoubleBuffered = true;
      }
  
      public Image Image { get; set; }
  
      private Rectangle rcSelect = new Rectangle();
      private Point pntStart;
  
      protected override void OnMouseDown(MouseEventArgs e)
      {
          if (e.Button != MouseButtons.Left) return;
          pntStart = e.Location;
          rcSelect = new Rectangle(e.Location, new Size(0, 0));
          this.Invalidate();
      }
  
      protected override void OnMouseMove(MouseEventArgs e)
      {
          if (e.Button != MouseButtons.Left) return;
          int x1 = Math.Min(e.X, pntStart.X);
          int y1 = Math.Min(e.Y, pntStart.Y);
          int x2 = Math.Max(e.X, pntStart.X);
          int y2 = Math.Max(e.Y, pntStart.Y);
          rcSelect = new Rectangle(x1, y1, x2 - x1, y2 - y1);
          this.Invalidate();
      }
  
      protected override void OnMouseUp(MouseEventArgs e)
      {
          if (rcSelect.Width &lt;= 0 || rcSelect.Height &lt;= 0) return;
          Image = new Bitmap(rcSelect.Width, rcSelect.Height);
          using (Graphics gr = Graphics.FromImage(Image))
          {
              gr.DrawImage(this.BackgroundImage, new Rectangle(0, 0, Image.Width, Image.Height),
                  rcSelect, GraphicsUnit.Pixel);
          }
          DialogResult = DialogResult.OK;
      }
  
      protected override void OnPaint(PaintEventArgs e)
      {
          using (Brush br = new SolidBrush(Color.FromArgb(120, Color.Black)))
          {
              int x1 = rcSelect.X; int x2 = rcSelect.X + rcSelect.Width;
              int y1 = rcSelect.Y; int y2 = rcSelect.Y + rcSelect.Height;
              e.Graphics.FillRectangle(br, new Rectangle(0, 0, x1, this.Height));
              e.Graphics.FillRectangle(br, new Rectangle(x2, 0, this.Width - x2, this.Height));
              e.Graphics.FillRectangle(br, new Rectangle(x1, 0, x2 - x1, y1));
              e.Graphics.FillRectangle(br, new Rectangle(x1, y2, x2 - x1, this.Height - y2));
          }
          using (Pen pen = new Pen(Color.Red, 3))
          {
              e.Graphics.DrawRectangle(pen, rcSelect);
          }
      }
  
      protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
      {
          if (keyData == Keys.Escape) this.DialogResult = DialogResult.Cancel;
          return base.ProcessCmdKey(ref msg, keyData);
      }
  }
  </code></pre>
  
  <p>On my form I then go:</p>
  
  <pre><code>pictureBox1.Image = SnippingTool.Snip();
  </code></pre>