Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6932089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:39:42+00:00 2026-05-27T11:39:42+00:00

If I create a CGMutablePathRef by adding together two circular paths as shown by

  • 0

image

If I create a CGMutablePathRef by adding together two circular paths as shown by the left image, is it possible to obtain a final CGPathRef which represents only the outer border as shown by the right image?

Thanks for any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:39:43+00:00Added an answer on May 27, 2026 at 11:39 am

    What you are asking for is the union of bezier paths. Apple doesn’t ship any APIs for computing the union of paths. It is in fact a rather complicated algorithm. Here are a couple of links:

    • http://www.cocoadev.com/index.pl?NSBezierPathcombinatorics
    • http://losingfight.com/blog/2011/07/09/how-to-implement-boolean-operations-on-bezier-paths-part-3/

    If you explain what you want to do with the union path, we might be able to suggest some alternatives that don’t require actually computing the union.

    You can draw a pretty decent inner glow without actually computing the union of the paths. Instead, make a bitmap. Fill each path on the bitmap. You’ll use this as the mask. Next, create an inverted image of the mask, that has everything outside of the union area filled. You’ll draw this to make CoreGraphics draw a shadow around the inner edge of the union. Finally, set the mask as your CGContext mask, set the shadow parameters, and draw the inverted image.

    Ok, that sounds complicated. But here’s what it looks like (Retina version on the right):

    glow glow retina

    It’s not perfect (too light at the corners), but it’s pretty good.

    So here’s the code. I’m passing around UIBezierPaths instead of CGPaths, but it’s trivial to convert between them. I use a some UIKit functions and objects. Remember that you can always make UIKit draw to an arbitrary CGContext using UIGraphicsPushContext and UIGraphicsPopContext.

    First, we need an mask image. It should be an alpha-channel-only image that is 1 inside any of the paths, and 0 outside all of the paths. This method returns such an image:

    - (UIImage *)maskWithPaths:(NSArray *)paths bounds:(CGRect)bounds
    {
        // Get the scale for good results on Retina screens.
        CGFloat scale = [UIScreen mainScreen].scale;
        CGSize scaledSize = CGSizeMake(bounds.size.width * scale, bounds.size.height * scale);
    
        // Create the bitmap with just an alpha channel.
        // When created, it has value 0 at every pixel.
        CGContextRef gc = CGBitmapContextCreate(NULL, scaledSize.width, scaledSize.height, 8, scaledSize.width, NULL, kCGImageAlphaOnly);
    
        // Adjust the current transform matrix for the screen scale.
        CGContextScaleCTM(gc, scale, scale);
        // Adjust the CTM in case the bounds origin isn't zero.
        CGContextTranslateCTM(gc, -bounds.origin.x, -bounds.origin.y);
    
        // whiteColor has all components 1, including alpha.
        CGContextSetFillColorWithColor(gc, [UIColor whiteColor].CGColor);
    
        // Fill each path into the mask.
        for (UIBezierPath *path in paths) {
            CGContextBeginPath(gc);
            CGContextAddPath(gc, path.CGPath);
            CGContextFillPath(gc);
        }
    
        // Turn the bitmap context into a UIImage.
        CGImageRef cgImage = CGBitmapContextCreateImage(gc);
        CGContextRelease(gc);
        UIImage *image = [UIImage imageWithCGImage:cgImage scale:scale orientation:UIImageOrientationDownMirrored];
        CGImageRelease(cgImage);
        return image;
    }
    

    That was actually the hard part. Now we need an image that is our glow color everywhere outside of the mask (path union) area. We can use UIKit functions to make this easier than a pure CoreGraphics approach:

    - (UIImage *)invertedImageWithMask:(UIImage *)mask color:(UIColor *)color
    {
        CGRect rect = { CGPointZero, mask.size };
        UIGraphicsBeginImageContextWithOptions(rect.size, NO, mask.scale); {
            // Fill the entire image with color.
            [color setFill];
            UIRectFill(rect);
            // Now erase the masked part.
            CGContextClipToMask(UIGraphicsGetCurrentContext(), rect, mask.CGImage);
            CGContextClearRect(UIGraphicsGetCurrentContext(), rect);
        }
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return image;
    }
    

    With those two images, we can draw an inner glow into the current UIKit graphics context for an array of paths:

    - (void)drawInnerGlowWithPaths:(NSArray *)paths bounds:(CGRect)bounds color:(UIColor *)color offset:(CGSize)offset blur:(CGFloat)blur
    {
        UIImage *mask = [self maskWithPaths:paths bounds:bounds];
        UIImage *invertedImage = [self invertedImageWithMask:mask color:color];
        CGContextRef gc = UIGraphicsGetCurrentContext();
    
        // Save the graphics state so I can restore the clip and
        // shadow attributes after drawing.
        CGContextSaveGState(gc); {
            CGContextClipToMask(gc, bounds, mask.CGImage);
            CGContextSetShadowWithColor(gc, offset, blur, color.CGColor);
            [invertedImage drawInRect:bounds];
        } CGContextRestoreGState(gc);
    }
    

    To test it, I created an image using a couple of circles and put it in a UIImageView:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        UIBezierPath *path1 = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(20, 20, 60, 60)];
        UIBezierPath *path2 = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(50, 50, 60, 60)];
        NSArray *paths = [NSArray arrayWithObjects:path1, path2, nil];
    
        UIGraphicsBeginImageContextWithOptions(self.imageView.bounds.size, NO, 0.0); {
            [self drawInnerGlowWithPaths:paths bounds:self.imageView.bounds color:[UIColor colorWithHue:0 saturation:1 brightness:.8 alpha:.8] offset:CGSizeZero blur:10.0];
        }
        imageView.image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CGMutablePathRef property in a subclassed UIImageview. When I create a new
I write a function such as follows to create a CGPath: +(CGPathRef)CGPathCreateRoundrect:(CGRect)rect radius:(CGFloat)radius {
I am implementing game application.In which i am using layer for animation. CGMutablePathRef path
In iOS there are two C structs that denote paths that describe drawable shapes:
the problem is... I have a path and i create a view in which
// Create a class called Dog containing two String: name and says. In main(),
create table person ( name varchar(15), attr1 varchar(15), attr2 varchar(1), attr3 char(1), attr4 int
Create a flat text file in c++ around 50 - 100 MB with the
Create a file called Valid[File].txt and stick some text in it. Start powershell and
Create Proc CrearNuevoAnuncio @Titulo varchar(250), @Precio int, @Descripcion varchar(250), @IDCategoria int, @IDImagen int, @Login

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.