嘿我試圖讓我的圖片看起來不錯,平滑(抗鋸齒)的,以使圓圖像使用掩模,你看下面: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
取而代之的是二進制掩碼的,你可以把阿爾法遮掩它有屏蔽,屏蔽之間的平滑過渡。 – djv