gpt4 book ai didi

Vb.net 图像蒙版使边缘平滑

转载 作者:行者123 更新时间:2023-12-02 04:20:38 25 4
gpt4 key购买 nike

嘿,我正在尝试使用蒙版使图像看起来漂亮且平滑(抗锯齿),以便制作圆形图像,如下所示:

round image

原始图像如下所示:

org image

上图的蒙版看起来像这样(红色是要取出的蒙版颜色):

mask image

它可以工作,但它给我带来了周围不太好的锯齿状边缘。蒙版是 .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 .

任何帮助解决这个问题的帮助都会很棒!谢谢!

更新我拥有的透明表单代码:

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 位置使用相同的点信息,以便适本地将纹理画笔“居中”。

结果:

enter image description here

关于Vb.net 图像蒙版使边缘平滑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20661126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com