- Код: Выделить всё
Dim w As Integer, h As Integer
Private Sub Form_Load()
w = Picture1.ScaleWidth
h = Picture1.ScaleHeight
End Sub
Private Sub Picture1_Click()
Dim X As Single, Y As Single
Dim I As Single, J As Single
Dim Sx, Sy, S
Dim piX As Integer, piY As Integer
Dim R, G, B
Dim N
Dim Mx(2, 2) As Integer
Dim My(2, 2) As Integer
Mx(0, 0) = -1: Mx(1, 0) = -2: Mx(2, 0) = -1
Mx(0, 1) = 0: Mx(1, 1) = 0: Mx(2, 1) = 0
Mx(0, 2) = 1: Mx(1, 2) = 2: Mx(2, 2) = 1
My(0, 0) = -1: My(1, 0) = 0: My(2, 0) = 1
My(0, 1) = -2: My(1, 1) = 0: My(2, 1) = 2
My(0, 2) = -1: My(1, 2) = 0: My(2, 2) = 1
Sx = 0
Sy = 0
S = 0
For Y = 1 To h - 1
For X = 1 To w - 1
Sx = 0
Sy = 0
S = 0
For J = -1 To 1
For I = -1 To 1
piX = I + X
piY = J + Y
p = Picture1.Point(piX, piY)
R = p Mod 256
G = (p \ 256) Mod 256
B = (p \ 256 \ 256) Mod 256
N = (R + G + B) / 3
Sx = Sx + N * Mx(I + 1, J + 1)
Sy = Sy + N * My(I + 1, J + 1)
Next I
Next J
S = Sqr(Sx ^ 2 + Sy ^ 2)
If S > 255 Then S = 255
If S < 0 Then S = 0
Picture1.PSet (X, Y), RGB(S, S, S)
Next X
Next Y
End Sub