title: Vb.net image mask making smooth along the edges
body: <p>Hey all i am trying to get my images to look nice and smooth (antialiasing) from using a mask in order to make the round image as you see below:</p>
  
  <p><img src="https://i.stack.imgur.com/YZ7Wr.png" alt="round image"></p>
  
  <p>The original image looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/KoI4H.png" alt="org image"></p>
  
  <p>The mask for the image above looks like this (the red being the mask color to take out):</p>
  
  <p><img src="https://i.stack.imgur.com/sDQpm.png" alt="mask image"></p>
  
  <p>It works but it gives me those not-so-nice jagged edges around it. The mask is an .png and also the image itself is a .png.</p>
  
  <p>The code i use to make the mask is this:</p>
  
  <pre><code>picNextTopic1.Image = Image.FromStream(wc.OpenRead(anAPI.wallOrgPostImage(keying).Replace("{width}", "50").Replace("{height}", "50"))) 'Download the image from the website.                  
  picNextTopic1.Image = ApplyMask(New Bitmap(picNextTopic1.Image), New Bitmap(My.Resources.mask), Color.Red) 'Apply mask to the downloaded image above.
  </code></pre>
  
  <p>The ApplyMask function is this:</p>
  
  <pre><code>Public Function ApplyMask(ByVal bImg As Bitmap, ByVal bMask As Bitmap, ByVal maskColor As Color) As Image
      Dim wImg As Integer = bImg.Width
      Dim hImg As Integer = bImg.Height
      Dim wMask As Integer = bMask.Width
      Dim hMask As Integer = bMask.Height
      Dim intMask As Integer = maskColor.ToArgb
      Dim intTransparent As Integer = Color.Transparent.ToArgb
  
      Using fpImg As New FastPix(bImg)
          Using fpMask As New FastPix(bMask)
              Dim pixelsImg = fpImg.PixelArray
              Dim pixelsMask = fpMask.PixelArray
  
              For y As Integer = 0 To Math.Min(hImg, hMask) - 1
                  For x As Integer = 0 To Math.Min(wImg, wMask) - 1
                      Dim iImg As Integer = (y * wImg) + x
                      Dim iMask As Integer = (y * wMask) + x
  
                      If pixelsMask(iMask) = intMask Then
                          pixelsImg(iImg) = intTransparent
                      End If
                  Next
              Next
          End Using
      End Using
  
      Return bImg
  End Function
  </code></pre>
  
  <p>Which uses <strong>FastPix</strong> found <a href="http://www.vbforums.com/showthread.php?t=586709" rel="nofollow noreferrer">here</a>.</p>
  
  <p>Any help to smooth this out would be great! Thanks!</p>
  
  <p><strong>UPDATE</strong>
  code for transparent form that i have:</p>
  
  <pre><code>Public Sub InitializeMyForm()
      BackColor = Color.Plum
      TransparencyKey = BackColor
  End Sub
  </code></pre>