Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim c As New Color()
        '把图片框1中的图片给一个Bitmap类型
        Dim b As New Bitmap(pictureBox1.Image)
        Dim b1 As New Bitmap(pictureBox1.Image)
        Dim rr As Integer, gg As Integer, bb As Integer, cc As Integer
        For i As Integer = 0 To pictureBox1.Width - 1
            For j As Integer = 0 To pictureBox1.Height - 1
                c = b.GetPixel(i, j)
                rr = c.R
                gg = c.G
                bb = c.B
                cc = CInt((rr + gg + bb) \ 3)
                If cc < 0 Then
                    cc = 0
                End If
                If cc > 255 Then
                    cc = 255
                End If
                '用FromArgb把整型转换成颜色值  
                Dim c1 As Color = Color.FromArgb(cc, cc, cc)
                b1.SetPixel(i, j, c1)
            Next
            pictureBox2.Refresh()
            '刷新
            '图片赋给图片框2
            pictureBox2.Image = b1
        Next
    End Sub
End Class
