Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
500MB 27GB Web Hosting - $9.95/Month
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleInvert the colors in an image using VB .NET
KeywordsVB .NET, graphics, image, grayscale, image processing
CategoriesGraphics
 
The program creates a Bitmap object initialized from the picture. That sets the Bitmap's size and color support.

The code then loops through each pixel in the bitmap and changes the red, green, and blue color components to 225 minus their original value. When it has set each pixel's value, the program sets the picture box's Image property to the bitmap.

 
Private Sub btnGo_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnGo.Click
    Dim bm As New Bitmap(picCanvas.Image)
    Dim X As Integer
    Dim Y As Integer
    Dim r As Integer
    Dim g As Integer
    Dim b As Integer

    For X = 0 To bm.Width - 1
        For Y = 0 To bm.Height - 1
            r = 255 - bm.GetPixel(X, Y).R
            g = 255 - bm.GetPixel(X, Y).G
            b = 255 - bm.GetPixel(X, Y).B
            bm.SetPixel(X, Y, Color.FromArgb(r, g, b))
        Next Y
    Next X

    picCanvas.Image = bm
End Sub
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated