Click here to Skip to main content
Click here to Skip to main content

Tagged as

VB.NET Image Filters

, 10 Oct 2012 Ms-PL
Rate this:
Please Sign up or sign in to vote.
A collection of 10 easy to use image filters in VB.NET
filters_small.png - Click to enlarge image


I have seen a few image filters written in VB, but most are poorly implemented, slow or just overly-complex. So I decided to create a simple class that contains a variety of filters and is easy to use.


I originally created this class to render a drop shadow on a custom shaped tooltip that I created in my spell check. Somewhat bored over my break, I decided to expand on this class and it quickly grew into its own project.

Using the Code

Using the filters is as easy as going:

Using b As New Bitmap("c:\test.png")
    b.Filters.DropShadow(Color.Black, New Point(8, 8), 4)
    b.Save("c:\test.png", Imaging.ImageFormat.Png)
End Using

The above will open the file c:\test.png, apply the DropShadow filter, and re-saves the image over the original file.

More details on specific filters and their options are listed later in this section.

The code can only be used on a bitmap object, so if you want to draw directly in a paint event, you will need to first render to a bitmap object like so:

Private Sub Form_Paint(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    'Create a bitmap object to draw onto
    Using b As New Bitmap(128, 128)
        'Create a graphics object so we can render onto the bitmap
        Using g = Graphics.FromImage(b)
            'Make graphics edges nice and "smooth"
            g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
            'Draw a circle
            g.DrawEllipse(Pens.Red, New Rectangle(10, 10, 108, 108))
        End Using
        'Static the circle that we drew with amount of 8
        'Draw the output to the form
        e.Graphics.DrawImage(b, New Point(0, 0))
    End Using
End Sub

The result of the code above will paint the following on your form:

In total there are 10 filters, which can be seen in the test projects. The filters and their settings are as follows:

'Makes the image translucent by the value specified
b.Filters.Alpha(Amount As Byte)
'Amount (0 - 255)
'    The amount of alpha to apply to the bitmap 0=Transparent 255=Opaque

'Creates a silhouette based on the alpha channel of an image
b.Filters.AlphaMask(AlphaColor As Color, SolidColor As Color)
'   The color that the transparent sections will be in the resulting bitmap
'   The color that the solid sections will be in the resulting bitmap

'Makes the bitmap lighter or darker
b.Filters.Brightness(amount As Single)
'amount (-1 - 1)
'    The amount of brightness to apply to the bitmap 
'    (negative numbers darken the image positive lighten)

'Adds a drop shadow to an image with alpha
b.Filters.DropShadow(ShadowColor As Color, Depth As Point, BlurAmount As Integer)
'    The color of the resulting shadow
'    The x and y offsets for the shadow depth
'BlurAmount (2 +)
'    How blurred the shadow will appear

'Highlights edges in black and white

'Adds an emboss effect to the bitmap

'Creates an ASCII image (font representation) of an image
b.Filters.Fontify(font As Font, ColorCount As Byte, ColorAlso As Boolean)
'    Specifies the font that is to be used with the ASCII image
'    Specifies the amount of chars that will be used when generating the final image
'    If this value is true each char in the image output will be colored

'Applies a blur to the bitmap
b.Filters.GausianBlur(Amount As Integer)
'Amount (2 +)
'    Specifies the amount that the image will be blurred in pixels

'Converts the bitmap a GrayScale Image

'Adjusts the Hue, Saturation and Luminance of a bitmap
b.Filters.HSL(hue As Single, sat As Single , lum As Single)
'hue (0 - 359 but can be any number .. if 361 or 721 is used this is
'equivalent to 1, 362 or 722 = 2 etc, 
'NOTE: some people prefer to use -180 to + 180 instead)
'    defines the hue of the resulting bitmap (0 = No Change)
'sat (-1 - 1)
'    defines the saturation of the resulting bitmap (0 = No Change)
'lum (-1 - 1)
'    defines the Luminance of the resulting bitmap (0 = No Change)

'Inverts the colors of the bitmap object

'Creates an artistic oil painting impression of an image
b.Filters.OilPainting(Amount As Integer, BleedTransparentEdges As Boolean)
'    Specifies the brush size for the oil painting
'    Also applies the oil painting effect to the alpha channel

'Mixes the pixels up of the image to produce a static like effect 
'(Although no actual static is added :))
b.Filters.Static(Amount As Integer)
'Amount (0 +)
'    The zone (in pixels) to swap with other pixels (0 = No Change)

'Gets the average color of each pixel and converts it to either black or white
b.Filters.TwoTone(Amount As Byte)
'    The tollance used to determine whether the pixel is black or white

The Test Project

The test project includes two testing forms. The form that opens when you run the project (pictured below) allows you to load an image file and then specify the filters (and appropriate options for each filter) that you wish to apply.

There is also a simple test that just shows all of the filters that are possible with preset options (pictured below); this can be accessed by clicking the "Simple Test" button on the main form.

filters_small.png - Click to enlarge image


Total downloads:

Downloads per day:

Change Log


  • GausianBlur now uses WPF rendering for faster results (~11x faster in tests)
  • Added ApplyWPFEffect that allows WPF effects to be used on bitmaps
  • Fixed a bug with the OilPainting filter where it would incorrectly paint transparent sections to parts of the image
  • Changed interface to support saving and added undo
  • Added TwoTone filter
  • Added Fontify filter
  • Added EdgeDetection filter


  • Added OilPainting Filter


  • Initial Release


All of the filters have been written by Kris Bennett here at i00 Productions unless stated below.

HSL - This filter is a modified version of the one by Miran.Uhan, the original article can be found here.


This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


About the Author

Software Developer (Senior) i00 Productions
Australia Australia
I hope you enjoy my code. It's yours to use for free, but if you do wish to say thank you then a donation is always appreciated.
You can donate here.

Comments and Discussions

QuestionTake 5! PinmemberJens-Madsen27-Feb-14 22:32 
AnswerRe: Take 5! Pinprofessional i0028-Feb-14 2:07 
GeneralMy vote of 2 PinprofessionalRameez Raja (RAJ)12-Dec-13 8:08 
GeneralRe: My vote of 2 [modified] Pinprofessional i0013-Dec-13 5:36 
GeneralMy vote of 5 Pinprofessionalketan italiya6-Aug-13 1:42 
GeneralRe: My vote of 5 Pinprofessional i006-Aug-13 17:08 
QuestionRe: My vote of 5 PinprofessionalRavi Bhavnani9-Sep-13 16:54 
AnswerRe: My vote of 5 Pinprofessional i0013-Sep-13 22:11 
GeneralRe: My vote of 5 PinprofessionalRavi Bhavnani14-Sep-13 12:04 
AnswerRe: My vote of 5 Pinprofessional i0014-Sep-13 1:43 
GeneralRe: My vote of 5 PinprofessionalRavi Bhavnani14-Sep-13 12:03 
GeneralRe: My vote of 5 Pinprofessional i0014-Sep-13 16:42 
AnswerRe: My vote of 5 PinprofessionalRavi Bhavnani15-Sep-13 9:16 
AnswerRe: My vote of 5 PinprofessionalRavi Bhavnani15-Sep-13 10:22 
GeneralRe: My vote of 5 Pinprofessional i0015-Sep-13 14:27 
GeneralRe: My vote of 5 PinprofessionalRavi Bhavnani15-Sep-13 14:48 
GeneralRe: My vote of 5 PinprofessionalRavi Bhavnani17-Sep-13 12:56 
GeneralRe: My vote of 5 Pinprofessional i0017-Sep-13 14:11 
QuestionUsing the filters in a new project Pinmembertomweber31-Oct-12 23:50 
AnswerRe: Using the filters in a new project Pinmembertweber20121-Nov-12 0:22 
GeneralRe: Using the filters in a new project Pinmemberi001-Nov-12 5:10 
AnswerRe: Using the filters in a new project Pinmemberi001-Nov-12 5:14 
QuestionSystem.Design missing for me in FrameWork 4 Pinmembertomweber19-Oct-12 8:29 
AnswerRe: System.Design missing for me in FrameWork 4 [modified] Pinmemberi0019-Oct-12 16:19 
QuestionNice code............ PinmemberPatil Kishor10-Oct-12 8:28 
QuestionSaving Issue Pinmemberstorm625-Aug-12 20:42 
AnswerRe: Saving Issue Pinmemberi0025-Aug-12 20:48 
GeneralRe: Saving Issue Pinmemberstorm626-Aug-12 18:38 
<pre lang="xml">&lt;pre lang=&quot;vb&quot;&gt;Private Sub SaveToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem1.Click
           Dim Savefiledialog1 As New SaveFileDialog()
           Savefiledialog1.Filter = &amp;quot;Bitmap Image (*.bmp)|*.bmp |All Files |*.*&amp;quot;
           If Savefiledialog1.ShowDialog() = DialogResult.OK Then
               bpImage.Image.Save(Savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
           End If
       Catch ex As Exception
           MsgBox(&amp;quot;No Image is opened for save&amp;quot;)
       End Try
   End Sub&lt;/pre&gt;</pre>
'this is code for saving image this code works on my other projects but not on your this project the error is
'image' is not a member of 'ImageFilters.bufferedPanel'
do you have any idea about this error with your project. I am modifying your code and adding cartoonize effect in this project but before going to start it When I try to save edited image is not working

GeneralRe: Saving Issue Pinmemberi0026-Aug-12 18:47 
GeneralRe: Saving Issue Pinmemberstorm627-Aug-12 0:20 
GeneralRe: Saving Issue Pinmemberi0027-Aug-12 1:07 
GeneralRe: Saving Issue Pinmemberstorm627-Aug-12 19:04 
GeneralRe: Saving Issue Pinmemberi0027-Aug-12 1:13 
GeneralRe: Saving Issue Pinmemberstorm627-Aug-12 19:05 
GeneralRe: Saving Issue Pinmemberi0015-Oct-12 15:01 
GeneralRe: Saving Issue Pinmemberstorm616-Oct-12 6:27 
GeneralRe: Saving Issue Pinmemberstorm616-Oct-12 6:47 
QuestionVoting 0... Not going to blindly download PinmemberElkay24-Feb-12 11:14 
AnswerRe: Voting 0... Not going to blindly download Pinmemberi0027-Feb-12 16:25 
GeneralMy vote of 5 Pinmembermanoj kumar choubey23-Feb-12 22:20 
AnswerWhy the downloads are broken PinmemberZac Greve17-Feb-12 5:35 
GeneralRe: Why the downloads are broken Pinmemberi0021-Feb-12 3:05 
QuestionDownload Broken [Modified] PinmemberZac Greve16-Feb-12 19:53 
SuggestionClarification is not enough. PinmentorMd. Marufuzzaman7-Feb-12 20:56 
GeneralMy vote of 5 Pinmemberdean.armstrong5-Feb-12 18:47 
GeneralMy vote of 3 PinmvpDave Kreskowiak4-Feb-12 18:24 
GeneralRe: My vote of 3 Pinmemberi004-Feb-12 18:50 
GeneralRe: My vote of 3 PinmvpDave Kreskowiak5-Feb-12 4:57 
GeneralRe: My vote of 3 Pinmemberi005-Feb-12 13:34 
GeneralRe: My vote of 3 PinmvpDave Kreskowiak5-Feb-12 17:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150327.1 | Last Updated 10 Oct 2012
Article Copyright 2012 by i00
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid