6

I need to draw a soft wide outline for my GDI+ GraphicsPath. Something like this: A path edge (red) drawn with a smooth pen

A path edge is shown in red. I'd like to use a wide pen which is smooth. I also need an ability to control smoothness of the pen.

I tried to use a gradient brush with the pen but couldn't find a solution that works.

I can achieve the desired result by drawing an outline with a black solid pen and applying a Gaussian smoothing filter on top of the result image, but I want to avoid this because it's slow when I have to process the whole image which could be quite large.

Is there a way to draw a smooth path outline?

Lev
  • 730
  • 12
  • 32

1 Answers1

3

There is no standard way in GDI+ that provides this functionality so you will have to create it.

You could track the line segments and draw a fuzzy, filled circle along the segments. By drawling the fuzzy circle once to a bitmap it should be fairly easy and fast to blit it continuously. By blending it slowly over time to the canvas you can also create a very nice effect and it would allow the user to control the intensity and maybe the size of the circle.

Emond
  • 50,210
  • 11
  • 84
  • 115
  • Is there a simple way to draw a bitmap at every pixel along a GDI+ shape path? It could be hard to calculate coordinates for pixels along a curve. – Lev Apr 20 '15 at 06:39
  • @Lev - The GDI Pen only supports a single color, no texturing. So I am afraid not. For most GDI shapes the formulars are well known so you could calculate them and do the drawing. Perhaps there is a library that already does this. – Emond Apr 20 '15 at 07:11
  • @lev - by the way ,are you using C/C++ or C#? (Just in case I have time to create a demo) – Emond Apr 20 '15 at 09:04
  • So basically I'll have to render shape path myself. I'll still need to use GDI+ to fill a shape. I wonder if in the end this approach is going to be faster than applying a blur on top of the shape drawn with GDI+ as a post processing. – Lev Apr 21 '15 at 04:09
  • Forgot to mention. I'm using C++ – Lev Apr 21 '15 at 04:10
  • @lev - what will be the fastest way depends on how the drawling is created and how complex it is. To create the desired effect blurring might prove to be more complicated than expected; you only want to blur the edges so you need to find those first. – Emond Apr 21 '15 at 04:40
  • All my shapes have solid color fill, with the same color as the edge before smoothing. So I can just blur the whole image. – Lev Apr 21 '15 at 05:54