1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

grayscale

Discussion in 'Visual Basic ( VB )' started by RajanPanchal, Jul 8, 2008.

  1. RajanPanchal

    RajanPanchal New Member

    Joined:
    Jul 2, 2008
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    How to change an image to grayscale using Visual baisc
     
  2. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    This should work in vb.net :smile::

    Code:
    Private Sub btnGo_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnGo.Click
        Dim bm As New Bitmap(picCanvas.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
    
        picCanvas.Image = bm
    End Sub
     
    shabbir likes this.

Share This Page