Question

I am looking for code/algorithm for filling a shape with a pattern in Java (pattern could be just a solid color or something like hatch).

The shape may not be closed but there are fixed bounds for the shape. The below image shows possible input, you can see there are gaps i.e. it is not fully closed (dotted rectangle shows the bounds for the shape). The output image is what is expected, basically the output should be as if the fill is done in mspaint but the boundary is fixed.

enter image description here input is a collection of graphic primitives (i.e. lines, arc, circle, rectangle). The collection is not ordered, I mean it is not clock-wise or anti-clockwise, it is totally random. When rendered individually it looks as it they are connected.

Was it helpful?

Solution

If you have the bounding box, then a slightly modified flood fill algorithm that stops at either a pixel boundary (e.g. the black region around the outside) or at a bounding box boundary should do the job.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top