Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Visual Basic ( VB ) (http://www.go4expert.com/forums/visual-basic/)
-   -   grayscale (http://www.go4expert.com/forums/grayscale-t11954/)

RajanPanchal 8Jul2008 17:15

grayscale
 
How to change an image to grayscale using Visual baisc

SaswatPadhi 7May2009 20:00

Re: grayscale
 
This should work in vb.net :smile::

Code: vb

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



All times are GMT +5.5. The time now is 13:33.