Creating Mask from Path


Not a CoreGraphics expert, I'd really appreciate some help.

I'm trying to create a mask from a path. (See red path in image).<a href="https://skitch.com/jordanx/fdkrb/skitch.jpg" rel="nofollow"><img alt="Skitch.jpg" class="b-lazy" data-src="https://img.skitch.com/20110607-bya4wncbwpcpck5mmxxuq186j4.preview.jpg" data-original="https://img.skitch.com/20110607-bya4wncbwpcpck5mmxxuq186j4.preview.jpg" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a><br />

Instead of the red path, I'd like the path to be a mask to an image underneath.

Could really use a hand. Thanks in advance

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { mouseSwiped = YES; UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:self.view]; currentPoint.y -= 20; UIGraphicsBeginImageContext(self.view.frame.size); [drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 20.0); CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0); CGContextBeginPath(UIGraphicsGetCurrentContext()); CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y); CGContextStrokePath(UIGraphicsGetCurrentContext()); drawImage.image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); lastPoint = currentPoint; mouseMoved++; if (mouseMoved == 10) { mouseMoved = 0; } }


Once you have the path created, use CGContextReplacePathWithStrokedPath convert it to a path you can fill to get the same results as stroking the path. Then you can use CGContextClip to set the clipping mask to this path.


The solution I came up with was:

<ul><li>Have UIView image on screen.</li> <li>Create UIImageView image with [UIColor clearColor] background color</li> <li>Use CoreGraphics to fill UIImageView with color</li> <li>Save UIImageView, then in TouchesMoved or UIPanGestureRecognizer, draw savedImage, Stroke Path after setting kCGContentBlendClear, save Image and repeat.</li> </ul>


  • Camera is not following the airplane in Scenekit
  • error when trying to undo Context
  • NaN replacement in node.js with an integer [duplicate]
  • Camera Multiple Image Capture in iOS
  • UIImage and UIImageView problem
  • appendBezierPathWithGlyph fails in [NSBezierPath currentPoint]
  • Changing UILabel position to strokeEnd of CGPath
  • drawing application for iOS performance issue
  • how to give UIImage negative color effect
  • Subclassing UIToolbar and overriding drawRect: - UIBarButtonItems NOT displaying
  • IOS/Objective-C: Pass Touch Event on ScrollView to View Below using HitTouch
  • How can I use layers on WebGL?
  • Custom uinavigatonbar exception
  • Looking for details on the PixelOffsetMode Enumeration in .Net, WinForms
  • How to resize CIImage?
  • UIBezierPath not updated as expected
  • Opengl Iphone SDK: How to tell if you're touching an object on screen?
  • Android SurfaceView: Show Video after Images
  • SKPhysicsJointFixed doesn't keep nodes together while moving one
  • Get touch points in UIScrollView through UITapGestureRecognizer
  • animating a custom CALayer property
  • Draw smooth line in InkCanvas WPF with Kinect
  • Drag and drop without removing UIButton
  • Get byte[] from
  • IndexSizeError on drawImage on IE and Edge
  • Why does it draw lines in the wrong place?
  • For loop with if condition on multiple R functions
  • as3-flash: any way to access all the instances placed in different frames from document class?
  • wxPython: displaying multiple widgets in same frame
  • Time complexity of a program which involves multiple variables
  • Atlas images wrong size on iPad iOS 9
  • Change multiple background-images with jQuery
  • R - Combining Columns to String Based on Logical Match
  • Android screen density dpi vs ppi
  • DirectX11 ClearRenderTargetViewback with transparent buffer?
  • Change an a tag attribute in JavaScript based on screen width
  • embed rChart in Markdown
  • Unable to use reactive element in my shiny app