[quote]But how can I detect a border color? For instance, if a polygon has 12 line segments and each line segment has a different color. In order to fill this polygon with a color using flood fill , I have to detect all 12 colors and keep track each pixel as the color filling moves toward the polygon border.
[/quote]
Usually the fill tools in painting programs are used to replace a color in an Image. Then the border is any color that is not the one that is replaced.
If that don’t apply to you, you can draw the polygons line segments to another off-screen buffer. Where the background is white and the line segments are black. Then you can use this buffer when you fill.
But, Yes, You have to know where the border is and you have to know where you have filled. Exactly how this is done depends on your application, as there are a lot of ways of doing this.
Jeff: I agree that flood fill is not the way to go if you only want to fill a single polygon. However, I enterprated the problem as first drawing one or more, possibly self intersecting, overlapping polygons, and then fill inside like a flood fill. Doing this with using polygons you would have to “AND” all the polygons that contains the start point (meaning finding the area that all the polygons overlap), and then “subtract” the rest. Either useing contains on all polygons for each pixel, or using clipping. I thought it would be easier to use a flood fill 