Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: VB7
Expertise: Intermediate
Nov 3, 2003



Application Security Testing: An Integral Part of DevOps

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)))
    Return newBmp
End Function
Marco Bellinaso
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date