locked
How to read image pixel by pixel? RRS feed

  • Question

  • on a vb form i have placed a picture box and a jpeg image is loaded. Now I need to read the pixel value from one corner to another in order to manipulate the image. Help me!!!!!
    Monday, June 7, 2010 1:44 AM

Answers

  • You can use below code for reading pixels from picturebox.

        Dim bmp As New Drawing.Bitmap(PictureBox1.Image)
       
        Dim x As Integer
        Dim y As Integer
    
        For y = 0 To bmp.Height
          For x = 0 To bmp.Width
            MessageBox.Show(bmp.GetPixel(x, y).ToString())
          Next x
        Next y


    Regards
    Nayan Paregi (MCTS)
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    • Proposed as answer by Cor Ligthert Monday, June 7, 2010 6:33 AM
    • Marked as answer by Liliane Teng Friday, June 11, 2010 9:10 AM
    Monday, June 7, 2010 4:42 AM
  • Hello Chandan,
    Thanks for your post.
    If you want to use the .R,.G and the .B individually, you can also try this

    Dim bmp As New Drawing.Bitmap(PictureBox1.Image)
            Dim x As Integer
            Dim y As Integer
            Dim clr As Integer
            For y = 0 To bmp.Height
                For x = 0 To bmp.Width
                    With bmp.GetPixel(x, y)
                        clr = .R & .G & .B
                        MessageBox.show(.R)
                        MessageBox.show(.G)
                        MessageBox.show(.B)
                        MessageBox.Show(clr)
                    End With
                Next x
            Next y

    If you have any problems, please feel free to follow up.
    Best regards,
    Liliane



    Please mark the replies as answers if they help and unmark them if they provide no help. Thanks
    • Marked as answer by Liliane Teng Friday, June 11, 2010 9:10 AM
    Friday, June 11, 2010 3:37 AM

All replies

  • You can use below code for reading pixels from picturebox.

        Dim bmp As New Drawing.Bitmap(PictureBox1.Image)
       
        Dim x As Integer
        Dim y As Integer
    
        For y = 0 To bmp.Height
          For x = 0 To bmp.Width
            MessageBox.Show(bmp.GetPixel(x, y).ToString())
          Next x
        Next y


    Regards
    Nayan Paregi (MCTS)
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    • Proposed as answer by Cor Ligthert Monday, June 7, 2010 6:33 AM
    • Marked as answer by Liliane Teng Friday, June 11, 2010 9:10 AM
    Monday, June 7, 2010 4:42 AM
  • Hello Chandan,
    Thanks for your post.
    If you want to use the .R,.G and the .B individually, you can also try this

    Dim bmp As New Drawing.Bitmap(PictureBox1.Image)
            Dim x As Integer
            Dim y As Integer
            Dim clr As Integer
            For y = 0 To bmp.Height
                For x = 0 To bmp.Width
                    With bmp.GetPixel(x, y)
                        clr = .R & .G & .B
                        MessageBox.show(.R)
                        MessageBox.show(.G)
                        MessageBox.show(.B)
                        MessageBox.Show(clr)
                    End With
                Next x
            Next y

    If you have any problems, please feel free to follow up.
    Best regards,
    Liliane



    Please mark the replies as answers if they help and unmark them if they provide no help. Thanks
    • Marked as answer by Liliane Teng Friday, June 11, 2010 9:10 AM
    Friday, June 11, 2010 3:37 AM