1. Home
  2. Computing & Technology
  3. Visual Basic

GDI+ Graphics in Visual Basic 2005 .NET
Code Your Own Photographic Effects

By Dan Mabbutt, About.com

Mar 10 2007

You can also create your own photo effects by manipulating the bits themselves. Here's an example where the photo is distorted by moving pixels gradually to a new position in the photograph.

Dim myImage As Bitmap = _
   New Bitmap("C:\zion.jpg", True)
Dim x, y, i As Integer
Dim myImageColor As Color
i = 0
For y = 0 To myImage.Height - 1
   i += 1
   For x = 0 To myImage.Width - 1
      If x + i < myImage.Width Then
         myImageColor = myImage.GetPixel(x + i, y)
      Else
         myImageColor = myImage.GetPixel(x, y)
      End If
      myImage.SetPixel(x, y, myImageColor)
   Next
Next
PictureBox.Image = myImage

--------
Click Here to display the illustration
Click the Back button on your browser to return
--------

And here's a "fade to black" effect created by changing the color of the pixels themselves.

Dim myImage As Bitmap = _
   New Bitmap("C:\zion.jpg", True)
Dim x, y As Integer
Dim newColor As Color
Dim pixelColor As Color
For y = 0 To myImage.Height - 1
   For x = 0 To myImage.Width - 1
      pixelColor = myImage.GetPixel(x, y)
      If pixelColor.R - x > 0 _
         And pixelColor.G - x > 0 _
         And pixelColor.B - x > 0 Then
         newColor = _
            Color.FromArgb(255, _
            pixelColor.R - x, _
            pixelColor.G - x, _
            pixelColor.B - x)
      Else
         newColor = _
         Color.FromArgb(255, 0, 0, 0)
      End If
      myImage.SetPixel(x, y, newColor)
   Next
Next
PictureBox.Image = myImage

--------
Click Here to display the illustration
Click the Back button on your browser to return
--------

Explore Visual Basic
By Category
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Using VB.NET
  5. GDI+ Graphics in Visual Basic 2005 .NET

©2009 About.com, a part of The New York Times Company.

All rights reserved.