FieldOffset(2) Public B As Byte
FieldOffset(3) Public A As Byte
FieldOffset(0) Public col As Integer
End Structure
Private m_radius As Integer = 5
''' summary
''' 高斯卷积矩阵
''' /summary
''' remarks/remarks
Private gaussMatrix As Integer()
''' summary
''' 卷积核
''' /summary
【vb.net图片描边 vb中图片框】''' remarks/remarks
Private nuclear As Integer = 0
''' summary
''' 模糊半径
''' /summary
''' value/value
''' returns/returns
''' remarks/remarks
Public Property Radius() As Integer
Get
Return m_radius
End Get
Set(ByVal Value As Integer)
If (m_radiusValue) Then
m_radius = Value
MakeGaussMatrix()
End If
End Set
End Property
''' summary
''' 高斯模糊
''' /summary
''' param name="bmp"要处理的图像/param
''' remarks/remarks
Public Sub MaskShadow(ByVal bmp As Bitmap)
If nuclear = 0 Then MakeGaussMatrix()
Dim rt As Rectangle = New Rectangle(0, 0, bmp.Width, bmp.Height)
' 克隆临时位图,作为卷积源
Dim tmp As Bitmap = bmp.Clone()
Dim dest As BitmapData = https://www.04ip.com/post/bmp.LockBits(rt, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb)
Dim source As BitmapData = https://www.04ip.com/post/tmp.LockBits(rt, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb)
Debug.Print(Radius)
Debug.Print(dest.Width.ToString)
Debug.Print(nuclear)
Dim Number As Integer = (bmp.Height * dest.Stride - 1) / 4' 图像数据元素的个数 , 注意.net中数组下标是从0开始的
Dim bmpdata(Number) As Integer
Dim tmpdata(Number) As Integer
Dim TMPrgb(Number) As rgbA '临时参考颜色
Dim BMPrgb(Number) As rgbA '计算结果后的颜色
'ReDim bmpdata(Number)
'ReDim TMPrgb(Number)
Marshal.Copy(source.Scan0, tmpdata, 0, Number)
Dim i As Long
Dim j As Long
j = Number
Dim w, h As Long
Dim yi, xi As Long
Dim iw, ih, iiw, iih, iii As Long
Dim k As Long
Dim nn As Integer = (Radius * 2 + 1) ^ 2
Dim n As Integer = Radius * 2 + 1
w = bmp.Width
h = bmp.Height
' System.Array.Copy(TMPrgb, tmpdata, j)
For i = 0 To j
TMPrgb(i).col = tmpdata(i)
Next i
i = 0
For i = 0 To j
ih = Int(i / w)
iw = i - ih * w
Dim r As Double = 0
Dim g As Double = 0
Dim b As Double = 0
Dim a As Double = 0
Dim weight As Double
For k = 0 To nn
'需要解决的是周边遍历颜色值然后相加(r=r1*weight1+r2*weight2+r3*weight3+r4*weight4+r5*weight5+...r*weight)
yi = Int(k / n)
xi = k - yi * n
yi -= Radius
xi -= Radius
iiw = iw + xi
iih = ih + yi
'yi = Int(k / n)
'xi = k - yi * n
'iih = ih + yi - Radius
'iiw = iw + xi - Radius
If (iiw0 OrElse iih0) Or (iiww - 1 OrElse iihh - 1) Then
iiw = iw
iih = ih
iii = i
Else
iii = iih * w
iii += iiw
End If
weight = gaussMatrix(k) / 1000
r += TMPrgb(iii).R * weight
g += TMPrgb(iii).G * weight
b += TMPrgb(iii).B * weight
a += TMPrgb(iii).A * weight
Next
'TMPrgb(i).col = tmpdata(i)
'r = TMPrgb(i).R * weight
'g = TMPrgb(i).G * weight
'b = TMPrgb(i).B * weight
BMPrgb(i).R = IIf(r255, 255, r)
BMPrgb(i).G = IIf(g255, 255, g)
BMPrgb(i).B = IIf(b255, 255, b)
BMPrgb(i).A = IIf(a255, 255, a)
bmpdata(i) = BMPrgb(i).col
'Debug.Print(TMPrgb(i).R)
Next
Marshal.Copy(bmpdata, 0, dest.Scan0, Number)
tmp.UnlockBits(source)
bmp.UnlockBits(dest)
newbmp = bmp.Clone
tmp.Dispose()
' End Try
End Sub
''' summary
''' 高斯卷积矩阵
推荐阅读
- 显卡玩不了荒野行动怎么办,荒野行动pc帧数不稳定
- 中国防震减灾公众号关注,防震减灾安全平台
- 如何打造一个团队ppt,如何打造一个优秀的团队ppt
- u盘下载格式是什么mv,u盘下载视频格式
- 如何迅速成为新媒体写作高手,如何迅速成为新媒体写作高手作文
- 手机什么软件可以拼接视频,手机可以拼视频的软件
- 梅赛德斯直播蹦迪素材,抖音梅赛德斯的仪式感
- mysql5.5怎么样 mysql5560
- 电商商家如何诚信经营,商家应如何诚信经营