devxlogo

GetGreyScaleImage – Convert a bitmap to greyscale

GetGreyScaleImage – Convert a bitmap to greyscale

' Convert a bitmap to greyscale - the function returns a new bitmap,'  it does not directly modify the input image.' Note: requires the GetGreyScale function'' Example:'    Dim bmp As New Bitmap("D:sample.gif")'    PictureBox1.Image = GetGreyScaleImage(bmp)Function GetGreyScaleImage(ByRef bmp As Bitmap) As Bitmap    ' create a new empty bitmap with the same size of the original bitmap    Dim newBmp As New System.Drawing.Bitmap(bmp.Width, bmp.Height)    Dim x, y As Integer    ' draw the new bitmap pixel-by-pixel, by converting to greyscale the pixels     ' in the original bitmap    For x = 1 To bmp.Width - 1        For y = 1 To bmp.Height - 1            newBmp.SetPixel(x, y, GetGreyScale(bmp.GetPixel(x, y)))        Next    Next    Return newBmpEnd Function

devx-admin

Share the Post: