Results 1 to 3 of 3

Thread: 20121011 - i00 .Net Image Filters

  1. #1

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    1/2 way accross the galaxy.. and then some

    Lightbulb 20121011 - i00 .Net Image Filters


    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 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.


    Donate Here - and be sure to put "i00 Image Filters", your vbforum user name (or other alias), and if you want the amount disclosed in the description field


    First you will need to import the clsImageFilters.vb file into your project

    After clsImageFilters is in your project, using the filters is as easy as going:

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

    The above will open the file c:\test.png,
    Apply the DropShadow filter,
    And resave 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:

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

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

    In total there are 15 filters, 14 of which can be seen in the test projects (ApplyWPFEffect is used in other filters).
    The filters and there settings are as follows:

    vb Code:
    1. 'Alpha
    2. 'Makes the image translucent by the value specified
    3. b.Filters.Alpha(Amount As Byte)
    4. 'Amount (0 - 255)
    5. '    The amount of alpha to apply to the bitmap 0=Transparent 255=Opaque
    7. 'AlphaMask
    8. 'Creates a silhouette based on the alpha channel of an image
    9. b.Filters.AlphaMask(AlphaColor As Color, SolidColor As Color)
    10. 'AlphaColor
    11. '   The color that the transparent sections will be in the resulting bitmap
    12. 'SolidColor
    13. '   The color that the solid sections will be in the resulting bitmap
    15. 'ApplyWPFEffect
    16. 'Applys a WPF Effect to the bitmap
    17. b.Filters.ApplyWPFEffect(Effect As Effect)
    18. 'Effect
    19. '    The System.Windows.Media.Effects.Effect to apply to the bitmap
    21. 'Brightness
    22. 'Makes the bitmap lighter or darker
    23. b.Filters.Brightness(amount As Single)
    24. 'amount (-1 - 1)
    25. '    The amount of brightness to apply to the bitmap
    26. '    (negative numbers darken the image positive lighten)
    28. 'DropShadow
    29. 'Adds a drop shadow to an image with alpha
    30. b.Filters.DropShadow(ShadowColor As Color, Depth As Point, BlurAmount As Integer)
    31. 'ShadowColor
    32. '    The color of the resulting shadow
    33. 'Depth
    34. '    The x and y offsets for the shadow depth
    35. 'BlurAmount (2 +)
    36. '    How blurred the shadow will appear
    38. 'EdgeDetection
    39. 'Highlights edges in black and white
    40. b.Filters.EdgeDetection()
    42. 'Emboss
    43. 'Adds an emboss effect to the bitmap
    44. b.Filters.Emboss()
    46. 'Fontify
    47. 'Creates an ASCII image (font representation) of an image
    48. b.Filters.Fontify(font As Font, ColorCount As Byte, ColorAlso As Boolean)
    49. 'font
    50. '    Specifies the font that is to be used with the ASCII image
    51. 'ColorCount
    52. '    Specifies the amount of chars that will be used when generating the final image
    53. 'ColorAlso
    54. '    If this value is true each char in the image output will be colored
    56. 'GausianBlur
    57. 'Applies a blur to the bitmap
    58. b.Filters.GausianBlur(Amount As Integer)
    59. 'Amount (2 +)
    60. '    Specifies the amount that the image will be blurred in pixels
    62. 'GrayScale
    63. 'Converts the bitmap a GrayScale Image
    64. b.Filters.GrayScale()
    66. 'HSL
    67. 'Adjusts the Hue, Saturation and Luminance of a bitmap
    68. b.Filters.HSL(hue As Single, sat As Single , lum As Single)
    69. 'hue (0 - 359 but can be any number .. if 361 or 721 is used this is
    70. 'equivalent to 1, 362 or 722 = 2 etc,
    71. 'NOTE: some people prefer to use -180 to + 180 instead)
    72. '    defines the hue of the resulting bitmap (0 = No Change)
    73. 'sat (-1 - 1)
    74. '    defines the saturation of the resulting bitmap (0 = No Change)
    75. 'lum (-1 - 1)
    76. '    defines the Luminance of the resulting bitmap (0 = No Change)
    78. 'Invert
    79. 'Inverts the colors of the bitmap object
    80. b.Filters.Invert
    82. 'OilPainting
    83. 'Creates an artistic oil painting impression of an image
    84. b.Filters.OilPainting(Amount As Integer, BleedTransparentEdges As Boolean)
    85. 'Amount
    86. '    Specifies the brush size for the oil painting
    87. 'BleedTransparentEdges
    88. '    Also applies the oil painting effect to the alpha channel
    90. 'Static
    91. 'Mixes the pixels up of the image to produce a static like effect
    92. '(Although no actual static is added :))
    93. b.Filters.Static(Amount As Integer)
    94. 'Amount (0 +)
    95. '    The zone (in pixels) to swap with other pixels (0 = No Change)
    97. 'TwoTone
    98. 'Gets the average color of each pixel and converts it to either black or white
    99. b.Filters.TwoTone(Amount As Byte)
    100. 'Amount
    101. '    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.


    20121011 - Download
    Total Downloads:

    Downloads per day:

    Version Changes

    • 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

    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.

    Thanks for downloading... Also please provide feedback, rate this thread and say thanks if this helped you

    Suggestions on possible improvements are much appreciated

    Also I extend a special thanks to the users who thanked / rated this post.

    Thanks again

  2. #2

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    1/2 way accross the galaxy.. and then some

    Re: 20120103 - i00 .Net Image Filters

    New version is up with oil painting effect!


  3. #3

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    1/2 way accross the galaxy.. and then some

    Re: 20121011 - i00 .Net Image Filters

    New version is out: 20121011


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width