Vb.net图像蒙版沿着边缘平滑

嘿所有我想通过使用蒙版来使我的图像看起来漂亮和平滑(抗锯齿),以便制作圆形图像,如下所示:

原始图像如下所示:

上面图像的掩码看起来像这样(红色是要取出的掩码颜色):

它有效,但它给了我周围不那么漂亮的锯齿状边缘.掩码是.png,图像本身也是.png.

我用来制作面具的代码是这样的:

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.

ApplyMask函数是这样的:

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

其中使用FastPix发现here.

任何有助于平滑这一点的帮助都会很棒!谢谢!

UPDATE
我有透明表格的代码:

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

解决方法

玩弄这个,我确实设法使用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位置使用相同的点信息,以便适当地“居中”纹理画笔.

结果:

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...