Option Explicit
Private Declare Function SetPixelV Lib "gdi32" (ByVal hDC As Long, _
ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long
Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, _
ByVal Y As Long) As Long
Public Sub SoftenBlur(Target As Long, X As Single, Y As Single, _
radius As Long, Steps As Long, Alpha As Integer)
Dim cX As Long
Dim cY As Long
Dim TempColor(3) As Long
Dim TempRadius As Integer
Dim I As Integer
Dim u As Integer
Dim Red(3) As Long
Dim Green(3) As Long
Dim Blue(3) As Long
Dim Color0 As Long
Dim Color1 As Long
Dim Color2 As Long
Dim Color3 As Long
Dim Done() As Boolean
ReDim Done(-radius To radius, -radius To radius)
For I = 1 To Steps
TempRadius = radius / Steps * I
For cX = -TempRadius To TempRadius 'Step 2
For cY = -TempRadius To TempRadius 'Step 2
If Not Done(cX, cY) Then
If (cX * cX) + (cY * cY) <= TempRadius * TempRadius Then
TempColor(0) = GetPixel(Target, cX + X, cY + Y)
TempColor(1) = GetPixel(Target, cX + X, cY + Y - 1)
TempColor(2) = GetPixel(Target, cX + X - 1, cY + Y - 1)
TempColor(3) = GetPixel(Target, cX + X - 1, cY + Y)
For u = 0 To 3 '==> RGB + Fehlerbehandlung
Blue(u) = TempColor(u) \ 65536
Green(u) = (TempColor(u) - Blue(u) * 65536) \ 256
Red(u) = TempColor(u) - Blue(u) * 65536 - Green(u) * 256
If Red(u) < 0 Then Red(u) = 0
If Red(u) > 255 Then Red(u) = 255
If Green(u) < 0 Then Green(u) = 0
If Green(u) > 255 Then Green(u) = 255
If Blue(u) < 0 Then Blue(u) = 0
If Blue(u) > 255 Then Blue(u) = 255
Next u
Color0 = RGB(((Red(0) * Alpha) + Red(1) + Red(2) + Red(3)) / (Alpha + 3), _
((Green(0) * Alpha) + Green(1) + Green(2) + Green(3)) / (Alpha + 3), _
((Blue(0) * Alpha) + Blue(1) + Blue(2) + Blue(3)) / (Alpha + 3))
Color1 = RGB((Red(0) + (Red(1) * Alpha) + Red(2) + Red(3)) / (Alpha + 3), _
(Green(0) + (Green(1) * Alpha) + Green(2) + Green(3)) / (Alpha + 3), _
(Blue(0) + (Blue(1) * Alpha) + Blue(2) + Blue(3)) / (Alpha + 3))
Color2 = RGB((Red(0) + Red(1) + (Red(2) * Alpha) + Red(3)) / (Alpha + 3), _
(Green(0) + Green(1) + (Green(2) * Alpha) + Green(3)) / (Alpha + 3), _
(Blue(0) + Blue(1) + (Blue(2) * Alpha) + Blue(3)) / (Alpha + 3))
Color3 = RGB((Red(0) + Red(1) + Red(2) + (Red(3) * Alpha)) / (Alpha + 3), _
(Green(0) + Green(1) + Green(2) + (Green(3) * Alpha)) / (Alpha + 3), _
(Blue(0) + Blue(1) + Blue(2) + (Blue(3) * Alpha)) / (Alpha + 3))
SetPixelV Target, cX + X, cY + Y, Color0
SetPixelV Target, cX + X, cY + Y - 1, Color1
SetPixelV Target, cX + X - 1, cY + Y - 1, Color2
SetPixelV Target, cX + X - 1, cY + Y, Color3
Done(cX, cY) = True
End If
End If
Next cY
Next cX
Next I
End Sub
|