Building a Stroke Class to outline your images via GDI+
I won’t prattle on. The aim was to find a way to transform this image:
Into this image (done in GIMP):
All this within the restraints of a winforms app for .NET framework 3.5 (don’t ask..).
I found this excellent answer on StackOverflow. I amalgamated this with a few other techniques (the main one being a fast blurring class to provide the option of blurred edges to the stroke – to essentially produce Glow) and got things working. The answer does depend on a SuperFastBlur alghorithm (see here) which was written in C#. I couldn’t be bothered to convert it to VB.net, so I just compiled it into a library and included it in my project.
Then, you simply include the Classes at the bottom of this page (I just saved the all to a single file). To apply a Stroke to your image, you then just use:
|
1 2 |
Dim stroke As New Stroke _image = stroke.Apply(_image, _strokeWidth, _strokeColor, _strokeBlur, _strokeLineJoin) |
_image is either Image or Bitmap and the other parameters should be self explanatory. Here are some results:
And some unexpected funky effects by changing LineJoin:
Not perfect, but not bad for GDI+?
The code:
|
1 |









Leave a Reply