title: Converting RGB to Gray scale?
body: <p>I am new to Visual Basic, I've done image processing in matlab in the past. But require Image Processing in Visual Basic as of this moment. Okay, I've been able to display the image and read up on converting to grayscale. However my image is in jpeg format and i keep running into the Bitmap function for only bmp images in several grayscale converter tutorials and my code keep producing errors for attempts in manipulation for JPEG format. How do i read in the jpeg and perform the grayscale manipulation. Here is the code.</p>
  
  <pre><code>Public Class Form1
  Private Sub showButton_Click(sender As System.Object, e As System.EventArgs) Handles showButton.Click
      ' Show the Open File dialog. If the user clicks OK, load the
      ' picture that the user chose.
      If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
          PictureBox1.Load(OpenFileDialog1.FileName)
      End If
  End Sub
  
  Private Sub GrayImageButton_Click(sender As System.Object, e As System.EventArgs) Handles GrayImageButton.Click
   Dim bm As New jpeg(PictureBox1.Image)
      Dim X As Integer
      Dim Y As Integer
      Dim clr As Integer
  
      For X = 0 To bm.Width - 1
          For Y = 0 To bm.Height - 1
              clr = (CInt(bm.GetPixel(X, Y).R) + _
                     bm.GetPixel(X, Y).G + _
                     bm.GetPixel(X, Y).B) \ 3
              bm.SetPixel(X, Y, Color.FromArgb(clr, clr, clr))
          Next Y
      Next X
      PictureBox1.Image = bm
  End Sub
  </code></pre>
  
  <p>The error I'm recieving is </p>
  
  <p>Error1 :  Value of type 'WindowsApplication1.jpeg' cannot be converted to 'System.Drawing.Image'. </p>
  
  <p>When I implement this with a bmp image it works perfectly, but not with a jpeg. I will be grateful for any help with this issue. Thanks</p>