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

  • Home
  • SEARCH
  • 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 5985351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:31:04+00:00 2026-05-22T22:31:04+00:00

How do I draw a blurred shape in Cocoa? Think of a shadow with

  • 0

How do I draw a blurred shape in Cocoa? Think of a shadow with a blurRadius accompanying a filled path, but without sharp-edged foreground path shape.

What I tried is using a filled path with a shadow, and setting the fill color to transparent (alpha 0.0). But that makes the shadow invisible as well, as it is apparently taking the shadow casting “object’s” alpha into account.

  • 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-22T22:31:04+00:00Added an answer on May 22, 2026 at 10:31 pm

    This is actually reasonably tricky. I struggled with this for a while until I came up with this category on NSShadow:

    @implementation NSShadow (Extras)
    
    //draw a shadow using a bezier path but do not draw the bezier path
    - (void)drawUsingBezierPath:(NSBezierPath*) path alpha:(CGFloat) alpha
    {
        [NSGraphicsContext saveGraphicsState];
        //get the bounds of the path
        NSRect bounds = [path bounds];
    
        //create a rectangle that outsets the size of the path bounds by the blur radius amount
        CGFloat blurRadius = [self shadowBlurRadius];
        NSRect shadowBounds = NSInsetRect(bounds, -blurRadius, -blurRadius);
    
        //create an image to hold the shadow
        NSImage* shadowImage = [[NSImage alloc] initWithSize:shadowBounds.size];
    
        //make a copy of the shadow and set its offset so that when the path is drawn, the shadow is drawn in the middle of the image
        NSShadow* aShadow = [self copy];
        [aShadow setShadowOffset:NSMakeSize(0, -NSHeight(shadowBounds))];
    
        //lock focus on the image
        [shadowImage lockFocus];
    
        //we want to draw the path directly above the shadow image and offset the shadow so it is drawn in the image rect
        //to do this we must translate the drawing into the correct location
        NSAffineTransform* transform=[NSAffineTransform transform];
        //first get it to the zero point
        [transform translateXBy:-shadowBounds.origin.x yBy:-shadowBounds.origin.y];
    
        //now translate it by the height of the image so that it draws outside the image bounds
        [transform translateXBy:0.0 yBy:NSHeight(shadowBounds)];
        NSBezierPath* translatedPath = [transform transformBezierPath:path];
    
        //apply the shadow
        [aShadow set];
    
        //fill the path with an arbitrary black color
        [[NSColor blackColor] set];
        [translatedPath fill];
        [aShadow release];
        [shadowImage unlockFocus];
    
        //draw the image at the correct location relative to the original path
        NSPoint imageOrigin = bounds.origin;
        imageOrigin.x = (imageOrigin.x - blurRadius) + [self shadowOffset].width;
        imageOrigin.y = (imageOrigin.y - blurRadius) - [self shadowOffset].height;
    
        [shadowImage drawAtPoint:imageOrigin fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:alpha];
        [shadowImage release];
        [NSGraphicsContext restoreGraphicsState];
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to draw a drop shadow underneath an image to which I
I want to draw UIButton in following shape : I have cut the image,
To draw a dotted line in OpenGL I can use glLineStipple, but how do
I draw a tranlucent rectangle on my panel but on the places that have
To draw a cube which has 6 sides using libgdx need 6 meshes. But
I draw SVG path like this: Start: M x, y Add Curve Q x1,
I draw a rectangle using: <Rectangle Width=300 Height=100 Stroke=Blue StrokeThickness=6> </Rectangle> but there is
I draw texts with Graphics.drawString but I want to draw Strings with rectangle background.
I know how to draw a partial circle(arc) on a HTML5 Canvas but how
I draw a text along a path with Keith Wood's jQuery SVG plugin. How

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.