Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The following set of routines create versions of a UIImage with either only the content <strong>inside</strong> a path, or only content <strong>outside</strong> that path. </p> <p>Both make use of the <code>compositeImage</code> method, which uses CGBlendMode. CGBlendMode is very powerful for masking anything you can draw against anything else you can draw. Calling compositeImage: with other blend modes can have interesting (if not always useful) effects. See the <a href="https://developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CGContext/Reference/reference.html#//apple_ref/c/tdef/CGBlendMode" rel="noreferrer">CGContext Reference</a> for all the modes.</p> <p>The clipping method I described in my comment to your OP does work and is probably faster, but only if you have UIBezierPaths defining all the regions you want to clip.</p> <pre><code>- (UIImage*) compositeImage:(UIImage*) sourceImage onPath:(UIBezierPath*) path usingBlendMode:(CGBlendMode) blend; { // Create a new image of the same size as the source. UIGraphicsBeginImageContext([sourceImage size]); // First draw an opaque path... [path fill]; // ...then composite with the image. [sourceImage drawAtPoint:CGPointZero blendMode:blend alpha:1.0]; // With drawing complete, store the composited image for later use. UIImage *maskedImage = UIGraphicsGetImageFromCurrentImageContext(); // Graphics contexts must be ended manually. UIGraphicsEndImageContext(); return maskedImage; } - (UIImage*) maskImage:(UIImage*) sourceImage toAreaInsidePath:(UIBezierPath*) maskPath; { return [self compositeImage:sourceImage onPath:maskPath usingBlendMode:kCGBlendModeSourceIn]; } - (UIImage*) maskImage:(UIImage*) sourceImage toAreaOutsidePath:(UIBezierPath*) maskPath; { return [self compositeImage:sourceImage onPath:maskPath usingBlendMode:kCGBlendModeSourceOut]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload