0

I am using C# and I am drawing the picture programmatically (since the picture can differ according to run time values of the parameters in my application). I end up with non generic closed contours (which consist of straight lines and curves). Now I need to fill those with different colors. Any idea how can I accomplish this?

Thanks in advance.

Milena
  • 1
  • 1

3 Answers3

0

Take a look at flood fill algorithms. You're probably better off drawing to a bitmap, then rendering to the forms (I assume you're using WinForms).

Community
  • 1
  • 1
Pontus Gagge
  • 17,166
  • 1
  • 38
  • 51
0

If it is Winforms I think best one is FillRegion. Or try Flood Fill. Unfortunately this is not that easy because there no native Flood fill in .net. But there are free implementations and ways to import it from GDI

Community
  • 1
  • 1
Andrey
  • 59,039
  • 12
  • 119
  • 163
0

You can use the PathGradientBrush for this. Here's a code example.

Public NotInheritable Class PathGradientBrush
          Inherits System.Drawing.Brush
     Member of System.Drawing.Drawing2D
Summary:
Encapsulates a System.Drawing.Brush object that fills the interior of a System.Drawing.Drawing2D.GraphicsPath object with a gradient. This class cannot be inherited.
Andrew Morton
  • 24,203
  • 9
  • 60
  • 84
Ralf de Kleine
  • 11,464
  • 5
  • 45
  • 87