The original image looks like this:
The mask of the above image looks like this (red is the mask color to be taken out):
It works, but it gives The not-so-pretty jagged edges around me. The mask is .png, and the image itself is also .png.
The code I used to make the mask is like this:
p>
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 like 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.Tran sparent.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< /pre>I found it here using FastPix.
Any help to smooth this would be great! Thanks!
UPDATE
I have the code for the transparent form:Public Sub InitializeMyForm()
BackColor = Color.Plum
TransparencyKey = BackColor
End Sub
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 and AddEllipse positions use the same point Information to properly "center" the texture brush.
Result:
Hey all I want to make my image look by using a mask Beautiful and smooth (anti-aliased) to make a circular image, as shown below:
The original image looks like this:
The mask of the above image looks like this (Red is to Mask color taken out):
It works, but it gives me jagged edges that are not so beautiful around me. The mask is .png, and the image itself is also .png.
The code I used to make the mask looks like 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 like 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)
D im 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
The use of FastPix found here.
Any help to smooth this would be great! Thanks!
UPDATE
I have the code for the transparent form:
Public Sub InitializeMyForm()
BackColor = Color.Plum
TransparencyKey = BackColor
End Sub
Toying with this, I did manage to use TextureBrush to make a smooth image in this way:
p>
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 and AddEllipse positions use the same point information in order to properly "center" the texture brush.< /p>
Result: