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
 
 
 
 
 
TitleDarken an image using Point and PSet (shows how to perform simple image processing)
Keywordsdarken, brightness, darkness, Point, PSet
CategoriesGraphics
 
Use Point to read point values and PSet to store them. For each pixel, decrease the red, green, and blue components' values by some fraction.
 
Private Sub cmdGo_Click()
Dim clr As Long
Dim r As Integer
Dim g As Integer
Dim b As Integer
Dim X As Integer
Dim Y As Integer
Dim fraction As Single

    cmdGo.Enabled = False
    MousePointer = vbHourglass
    DoEvents

    fraction = CSng(txtBrightness)

    picTo.AutoRedraw = True
    picTo.Width = picFrom.Width
    picTo.Height = picFrom.Height
    picTo.ScaleMode = vbPixels
    picFrom.ScaleMode = vbPixels

    For Y = 0 To picFrom.ScaleHeight
        For X = 0 To picFrom.ScaleWidth
            ' Get the source pixel's color components.
            clr = picFrom.Point(X, Y)
            r = clr Mod 256
            g = (clr \ 256) Mod 256
            b = clr \ 256 \ 256

            ' Decrease the brightness.
            r = r * fraction
            g = g * fraction
            b = b * fraction

            ' Write the new pixel.
            picTo.PSet (X, Y), RGB(r, g, b)
        Next X
        DoEvents
    Next Y

    ' Make the changes permanent.
    picTo.Picture = picTo.Image

    cmdGo.Enabled = True
    MousePointer = vbDefault
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated