VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim B As New Bitmap(PictureBox1.Width, PictureBox1.Height)
Dim G As Graphics = Graphics.FromImage(B)
G.Clear(Color.FromArgb(30, 130, 170))
PictureBox1.Image = B.Clone
G.Dispose()
B.Dispose()
End Sub
Public Shared Function MakeImageGrayscale(ByVal bmp As Bitmap) As Bitmap
Dim B As New Bitmap(bmp.Width, bmp.Height)
Dim cMatrix As New ColorMatrix(New Single()() _
{New Single() {0.299, 0.299, 0.299, 0, 0}, _
New Single() {0.587, 0.587, 0.587, 0, 0}, _
New Single() {0.114, 0.114, 0.114, 0, 0}, _
New Single() {0, 0, 0, 1, 0}, _
New Single() {0, 0, 0, 0, 1}})
Dim imageAttrib As New ImageAttributes()
imageAttrib.SetColorMatrix(cMatrix)
Dim gr As Graphics = Graphics.FromImage(B)
' Apply the grayscale image attribute
gr.DrawImage(bmp, New Rectangle(0, 0, bmp.Width, bmp.Height), _
0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, imageAttrib)
gr.Dispose()
Return B
End Function
Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
Dim B As Bitmap = PictureBox1.Image
Dim C As Color = B.GetPixel(e.X, e.Y)
Me.Text = C.ToString
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
PictureBox1.Image = MakeImageGrayscale(PictureBox1.Image)
End Sub