简体   繁体   English

iOS - 查找由黑色曲线包围的白色像素/区域并创建路径

[英]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() .使用 Swift 方法touchBegan、touchMovedtouchEnded我保存触摸点,然后使用UIGraphicsGetCurrentContext()和方法beginPath()、move(to: Point)、addLine(to: Point) 和 strokePath()画一条线。 This line is repeated on 4 quadrants plus their negative values, therefore 8 lines are drawn.这条线在 4 个象限加上它们的负值上重复,因此绘制了 8 条线。

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.我想知道是否可以用黑线包围的白色像素创建 e 封闭路径/形状。 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谢谢

也许你想要的是“Flood Fill”算法,请看文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM