locked
Fill an irregular shape with color in System.Drawing RRS feed

  • Question

  • Hello,
    How do I fill an irregular shape with a given color in an image with System.Drawing?

    Let's say I have a map of North America and I want to paint the USA with a color given by my user. It's just like doing a fill with paint or photoshop right in the middle of the USA. Is there a way to do this with System.Drawing?

    I just want to know if it's possible and an explanation on how to do it. I don't necessarily need the exact code for it.

    Wednesday, June 14, 2006 2:17 PM

Answers

  • You need to be able to model the points that make up the shape you want to fill. In your example you would need to know all the points that make up the USA, maybe stored in a GraphicsPath object or even a list of points to form a polygon.

    You can then use Graphics.FillPath/FillPolygon to flood the interior of the shape with colour. If you already have the points that make up the shape you want to fill then it's trivial. If you don't then it could be much more difficuly but since I'm not aware of the context surrounding your post I cannot specify further.

    Wednesday, June 14, 2006 2:28 PM

All replies