Private Sub Command1_Click()
Dim Op_X(-1 To 0, -1 To 0) As Integer, Op_Y(-1 To 0, -1 To 0) As Integer
Dim X As Integer, Y As Integer, I As Integer, J As Integer
Pic2.Cls
Grad = 0
Op_X(-1, -1) = 1: Op_X(0, -1) = 0
Op_X(-1, 0) = 0: Op_X(0, 0) = -1
Op_Y(-1, -1) = 0: Op_Y(0, -1) = -1
Op_Y(-1, 0) = 1: Op_Y(0, 0) = 0
For Y = 0 To Pic1.Height - 1
For X = 0 To Pic1.Width - 1
GradX = 0: GradY = 0: Grad = 0
If X = 0 Or Y = 0 Or X = Pic1.Width - 1 Or Y = Pic1.Height - 1 Then
Grad = 0
Else
For I = -1 To 0
For J = -1 To 0
PixelValue = GetPixel(Pic1.hdc, X + I, Y + J) ' dapatkan pixel dari posisi x + i dan y + j
DecTORGB PixelValue, R, G, B 'fungsi proses mendapatkan nilai RGB
Itensity = (R + G + B) / 3 'Itensitas / B & W
GradX = GradX + (Itensity * Op_X(I, J))
GradY = GradY + (Itensity * Op_Y(I, J))
Next J
Next I
Grad = Round(Sqr(Abs(GradX * GradX) + Abs(GradY * GradY)))
End If
If Grad <= 0 Then Grad = 0: If Grad >= 255 Then Grad = 255
SetPixel Pic2.hdc, X, Y, RGB(Grad, Grad, Grad)
Pic2.Refresh
Next X
Pic2.Refresh
Next Y
End Sub






