简体   繁体   中英

Using NSShadow for non-rectangular shapes

I'm drawing a shadow of various non-rectangular shapes inside the CIImage object. I did this by subclassing the CIFilter and combining my own filter kernel and the gaussian blur filter. I'm wondering whether a performance gain can be achieved by using the NSShadow.

Also I'm not sure whether NSShadow can be used to draw a shadow of a non-rectangular shape? For example in the answer for another question I found that in order to use NSShadow one first needs to create a NSBezierPath of the shape.

Any hints, suggestions or am I totally off here by trying to use NSShadow in this situation?

I don't know whether it would be any faster, but it would certainly be easier. And remember, the less code you have, the fewer bugs you have.

NSShadow works with any shape, rectangular or otherwise. In fact, some things that we wouldn't ordinarily think of as a shadow can be, in fact, implemented as shadows. A glow, for example, is simply a white “shadow”. I'd guess that focus rings are shadows internally.

You do not need to create an NSBezierPath. Drawing an image with a shadow will work just fine. The only thing that doesn't is drawing a gradient (as in NSGradient).

For the benefit of other readers: All of this applies equally in Quartz, to CGContext's shadow properties and the exclusion of CGGradient and probably CGShading.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM