Vb.net image mask creating smooth along the edges

Hi everyone, I am trying to make my images look beautiful and smooth (smoothing) from using a mask to make a round image, as you see below:

round image

The original image is as follows:

org image

The mask for the image above is as follows (red is the color of the mask):

mask image

It works, but it gives me those not-so-beautiful notched edges around it. The mask is .png, as well as the .png image itself.

The code I use to create the mask is:

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.

The ApplyMask function is as follows:

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

What uses FastPix found here .

Any help to smooth it would be great! Thanks!

UPDATE code for the transparent form that I have:

Public Sub InitializeMyForm()
    BackColor = Color.Plum
    TransparencyKey = BackColor
End Sub
+4
1

, , TextureBrush:

Dim profile As Image = Image.FromFile("c:\...\profile.png")

Protected Overrides Sub OnPaint(e As PaintEventArgs)
  e.Graphics.Clear(Color.SteelBlue)
  e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
  Using tb As New TextureBrush(profile)
    tb.TranslateTransform(120, 64)
    Using p As New GraphicsPath
      p.AddEllipse(120, 64, profile.Width, profile.Width)
      e.Graphics.FillPath(tb, p)
    End Using
  End Using
  MyBase.OnPaint(e)
End Sub

TranslateTransform AddEllipse , "" .

:

enter image description here

0

All Articles