logo  Image Effects
This Chapter
Convert Graphics
Image Attribute
Special Effects
Picture Boxes
Rotate & Flip
Chapters
Home Page
Colours, RGB
Computer Specifications
Dates&Times
Disk Drives
Files
Folders
GPS and OS Ref
VB.Net Forms
Image Files
If & Select
List/Array
Mathematics
NuGet
Sound
String Functions
Sun and Moon
User Controls
Validation
DigitalDan Sites
My Other Sites
Contact Site

Note
Some pages
may contain
inaccuracies
Hits=5
Picture with no effects
A normal picture with no effects
VB.Net includes a set of special effects for images. Thesse include coberting to black/white, blurring, colour balancing etc. The functions below use a sample of the available special effects to demonstrate how they work. The pictures included with each function provide indicate a possible outcome of applying the effect. (Many effects have multiple properties and offer a huge variety of possible outcomes.
 
Adjust Brightness and Contrast
Adjusting Brightness/Contrast
Brightness=30 and Contrast=30

Private Function Effect_BrightnessContrast(bmp As Bitmap, brightnessLevel1 As Integer, contrastLevel1 As Integer) As Bitmap
 ' brightnessLevel1 -255 to 255
 ' contrastLevel1 -100 to 100
 Dim effect1 As New Imaging.Effects.BrightnessContrastEffect(brightnessLevel1, contrastLevel1)
 bmp.ApplyEffect(effect1)
 Return bmp
End Function
  
Blurring a Picture
Blurred Image
radius=5 and expand-edge=FALSE

Private Function Effect_Blur(bmp As Bitmap, radius1 As Single, expandedge1 As Boolean) As Bitmap
 ' radius 0 to 255 (255 = extremely blurry)
 ' expandEdge = True or False (expands bitmap and blurs into expanded region)
 Dim effect1 As New Imaging.Effects.BlurEffect(radius1, expandedge1)
 bmp.ApplyEffect(effect1)
 Return bmp
End Function
  
Adjusting Colour Balance
Adjusted Colour Balance
cyanRed=-40 magentaGreen=50 yellowBlue=-30

Private Function Effect_ColourBalance(bmp As Bitmap, cyanRed1 As Integer, magentaGreen1 As Integer, yellowBlue1 As Integer) As Bitmap
 ' all properties -100 to 100
 ' 1st colour decreases between -100 and 0
 ' 2nd colour increases between 0 and 100
 Dim effect1 As New Imaging.Effects.ColorBalanceEffect(cyanRed1, magentaGreen1, yellowBlue1)
 bmp.ApplyEffect(effect1)
 Return bmp
End Function
  
Black and White Photograph
Black and White Effect

Private Function Effect_GreyScale(bmp As Bitmap) As Bitmap
 Dim gse As New Imaging.Effects.GrayScaleEffect
 Dim grayScaleMatrix As ColorMatrix = gse.Matrix
 Dim attributes As New System.Drawing.Imaging.ImageAttributes()
 attributes.SetColorMatrix(grayScaleMatrix)
 Using g As Graphics = Graphics.FromImage(bmp)
  g.DrawImage(bmp, New Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, attributes)
 End Using
 Return bmp
End Function
  
Photographic Negative
Photographic Negative Effect

Private Function Effect_Invert(bmp As Bitmap) As Bitmap
 Dim ie As New Imaging.Effects.InvertEffect
 Dim grayScaleMatrix As ColorMatrix = ie.Matrix
 Dim attributes As New System.Drawing.Imaging.ImageAttributes()
 attributes.SetColorMatrix(grayScaleMatrix)
 Using g As Graphics = Graphics.FromImage(bmp)
  g.DrawImage(bmp, New Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, attributes)
 End Using
 Return bmp
End Function
  
Old Sepia Photograph
Sepia Effect

Private Function Effect_Sepia(bmp As Bitmap) As Bitmap
 Dim se As New Imaging.Effects.SepiaEffect
 Dim sepiaMatrix As ColorMatrix = se.Matrix
 Dim attributes As New System.Drawing.Imaging.ImageAttributes()
 attributes.SetColorMatrix(sepiaMatrix)
 Using g As Graphics = Graphics.FromImage(bmp)
  g.DrawImage(bmp, New Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, attributes)
 End Using
 Return bmp
End Function
  
Sharpen a Picture
Sharpen Effect
radius=45 and amount=10

Private Function Effect_Sharpen(bmp As Bitmap, radius1 As Single, amount1 As Single) As Bitmap
 ' radius 0 to 255 .. increasing number of pixels (not to scale) used for each pixel calculation
 ' amount 0 to 100 .. 0=no sharpenning 100=max sharpenning
 Dim effect1 As New Imaging.Effects.SharpenEffect(radius1, amount1)
 bmp.ApplyEffect(effect1)
 Return bmp
End Function
  
Colour Tinting a Picture
Tint Effect
colour=Color.Blue and amount=50

Private Function Effect_Tint(bmp As Bitmap, colour1 As Color, amount1 As Integer) As Bitmap
 ' colour1  the colour used as a base for tinting
 ' amount1 -100 to 100 how much "hue" (colour1 tint) to apply
 Dim effect1 As New Imaging.Effects.TintEffect(colour1, amount1)
 bmp.ApplyEffect(effect1)
 Return bmp
End Function
  
Make Vivid Effect
Vivid Effect

Private Function Effect_Vivid(bmp As Bitmap) As Bitmap
 Dim effect1 As New Imaging.Effects.VividEffect()
 bmp.ApplyEffect(effect1)
 Return bmp
End Function
  

DigitalDan.co.uk