iOS- How to paint in the within limits

本小妞迷上赌 提交于 2019-12-06 06:38:13

问题


I used the scanning line seed filling algorithm to realize the color filling function.

But I don't know how to do that. When my pen lands in the flower, I need to draw only Inside the black edge of the flower,do not draw in the hair.

I have tried to use : CALayer *layer = [CALayer layer]; layer.contents = (__bridge id)(image.CGImage); self.drawView.layer.mask = layer; But the plan didn't work. if any one gives solution it would be so great,Thank you. (English is not my native language; please excuse typing errors.)


回答1:


Use a two pass approach.

  • Use the same algorithm as the fill algorithm to create a stencil mask which fills the area you want to allow the pen to draw.
  • Draw the pen with stencil testing to constrain it to the allowed region.

Similar approach could be used to create an alpha-mask on the fly (e.g. as a texture), and mix that with the pen drawing.



来源:https://stackoverflow.com/questions/54019522/ios-how-to-paint-in-the-within-limits

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!