Vb.net image mask making smooth along the edges

Viewed 2459

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:

round image

The original image looks like this:

org image

The mask for the image above looks like this (the red being the mask color to take out):

mask image

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.

The code i use to make the mask is this:

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 this:

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

Which uses FastPix found here.

Any help to smooth this out would be great! Thanks!

UPDATE code for transparent form that i have:

Public Sub InitializeMyForm()
    BackColor = Color.Plum
    TransparencyKey = BackColor
End Sub
1 Answers
Related