Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleConvert almost white pixels to white
DescriptionThis example shows how to convert almost white pixels to white in Visual Basic 6.
Keywordspixels, color, convert, color conversion
CategoriesGraphics
 
This program cleans up almost white pixels. It loops over the pixels in an image. If a pixel's total red, green, and blue components is greater than 3 * 128, the program makes the pixel white.
 
Private Sub Form_Load()
Dim file_name As String
Dim X As Integer
Dim Y As Integer
Dim r As Integer
Dim g As Integer
Dim b As Integer

    picOriginal.AutoRedraw = True
    For Y = 0 To picOriginal.ScaleHeight - 1
        For X = 0 To picOriginal.ScaleWidth - 1
            UnRGB picOriginal.Point(X, Y), r, g, b
            If r + g + b > 3 * 128 Then
                picOriginal.PSet (X, Y), vbWhite
            End If
        Next X
    Next Y

    picOriginal.Picture = picOriginal.Image

    file_name = App.Path
    If Right$(file_name, 1) <> "\" Then file_name = _
        file_name & "\"
    SavePicture picOriginal.Picture, file_name & "clean.bmp"
End Sub
 
My book Visual Basic Graphics Programming shows how to apply much more sophisticated filtering methods to images.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated