Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


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

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

 

 

 

 

 


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

 

 

Sitemap