Wednesday, August 18, 2010

color code detection in VB

 Public Function ConvertToGrayscale(ByVal source As Bitmap) as Bitmap

  Dim bm as new Bitmap(source.Width,source.Height)

  Dim x

  Dim y

  For y=0 To bm.Height

    For x=0 To bm.Width

      Dim c as Color = source.GetPixel(x,y)

      Dim luma as Integer = CInt(c.R*0.3 + c.G*0.59 + c.B*0.11)

      bm.SetPixel(x,y,Color.FromArgb(luma,luma,luma)

    Next

  Next

  Return bm

End Function

No comments:

Post a Comment