title: Create image thumbnail with rounded corners
body: <p>I need to create a thumbnail image with transparent rounded corners. Before this requirement I used the simple:</p>
  
  <pre><code>using (var b = new Bitmap(dataSize.Width, dataSize.Height, PixelFormat.Format32bppArgb))
  using (var g = Graphics.FromImage(b))
  {
      g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Default;
      g.DrawImage(original, 0, 0, b.Width, b.Height);
  }
  </code></pre>
  
  <p>which produced great results (for reductions to approx 50x50px) even without any interpolation. Now with the rounded corners I used the following algorithm (the 4 'if's are there so I can have variable roundness on each of the 4 corners):</p>
  
  <pre><code>using (var b = new Bitmap(dataSize.Width, dataSize.Height, PixelFormat.Format32bppArgb))
  using (var g = Graphics.FromImage(b))
  {
      // set interpolation
      g.InterpolationMode = InterpolationMode.HighQualityBicubic;
      g.SmoothingMode = SmoothingMode.HighQuality;
  
      // transformation to scale and shift the brush
      var transform = new Matrix();
      transform.Scale(ratio, ratio);
      transform.Translate(start.X / ratio, start.Y / ratio);
      var brush = new TextureBrush(original) { Transform = transform };
  
      // create path for stamping the iamge
      var gp = new GraphicsPath(FillMode.Winding);
      if (descriptor.CornerRadiusLeftTop &gt; 0)
          gp.AddArc(descriptor.GetLeftTopCorner(b.Size), 180, 90);
      else
          gp.AddLine(-1, -1, -1, -1);
  
      if (descriptor.CornerRadiusRightTop &gt; 0)
          gp.AddArc(descriptor.GetRightTopCorner(b.Size), 270, 90);
      else
          gp.AddLine(b.Width + 1, -1, b.Width + 1, -1);
  
      if (descriptor.CornerRadiusRightBottom &gt; 0)
          gp.AddArc(descriptor.GetRightBottomCorner(b.Size), 0, 90);
      else
          gp.AddLine(b.Width + 1, b.Height + 1, b.Width + 1, b.Height + 1);
  
      if (descriptor.CornerRadiusLeftBottom &gt; 0)
          gp.AddArc(descriptor.GetLeftBottomCorner(b.Size), 90, 90);
      else
          gp.AddLine(-1, b.Height + 1, -1, b.Height + 1);
      // stamp the image with original
      g.FillPath(brush, gp);
  }
  </code></pre>
  
  <p>but this approach produced ugly un-interpolated imaged with really jagged gradients. Is there a better approach to create transparent thumbnails or are there some settings I could use to improve the output?</p>