3

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.) enter image description here

make
  • 9,467
  • 3
  • 8
  • 14
  • There is a similar question: [How to draw inside the black edges in iOS SDK with OpenGL ES?](https://stackoverflow.com/questions/50944736/how-to-draw-inside-the-black-edges-in-ios-sdk-with-opengl-es) – Rabbid76 Jan 12 '19 at 15:53

1 Answers1

3

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.

solidpixel
  • 10,688
  • 1
  • 20
  • 33
  • @solidpixel, i am also facing same issues, i want to draw inside the line, i have done context?.setBlendMode(.sourceIn) with this, but it took too m ch time to drawing. – Paresh Patel Nov 29 '19 at 08:28