ndr.hax
ndr.hax

Reputation: 625

iOS - Find white pixels/area enclosed by a black curve and create path

Using Swift methods touchBegan, touchMoved and touchEnded I save the touch points and than I draw a line using UIGraphicsGetCurrentContext() with methods beginPath(), move(to: Point), addLine(to: Point) and strokePath(). This line is repeated on 4 quadrants plus their negative values, therefore 8 lines are drawn.

Here is an example: Example image

I save this drawing as an Image when the user taps the tick (Done green button at top-right) for later manipulations.

I wonder if it's possible to create e closed path/shape with white pixels enclosed by the black lines. I want to fill the white area with custom color when the user touches inside it.

The shape is created by user input and I have no idea how it would look like.

Would be thankful to whoever finds the time to give it's contribute.

Thank you

Upvotes: 1

Views: 201

Answers (1)

Changwei
Changwei

Reputation: 672

Maybe what you want is the "Flood Fill" algorithm, please see the article.

Upvotes: 0

Related Questions