title: C# Resized images have black borders
body: <p>I have a problem with image scaling in .NET. I use the standard Graphics type to resize images like in this example:</p>
  
  <pre><code>public static Image Scale(Image sourceImage, int destWidth, int destHeight)
  {
          Bitmap toReturn = new Bitmap(sourceImage, destWidth, destHeight);
  
          toReturn.SetResolution(sourceImage.HorizontalResolution, sourceImage.VerticalResolution);
  
          using (Graphics graphics = Graphics.FromImage(toReturn))
          {
              graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
              graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
              graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
              graphics.DrawImage(sourceImage, 0, 0, destWidth, destHeight);
          }
          return toReturn;
      }
  </code></pre>
  
  <p>But I have a big problem with resized images: they have gray and black borders and it's extremely important to make have images without them.</p>
  
  <p>Why do they appear and what I can to do make them disappear? </p>
  
  <p><strong>Sample Output:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/egqYa.jpg" alt="sample output"></p>