简体   繁体   English

使用NSShadow处理非矩形形状

[英]Using NSShadow for non-rectangular shapes

I'm drawing a shadow of various non-rectangular shapes inside the CIImage object. 我正在CIImage对象内绘制各种非矩形形状的阴影。 I did this by subclassing the CIFilter and combining my own filter kernel and the gaussian blur filter. 我是通过子类化CIFilter并结合我自己的滤镜内核和高斯模糊滤镜来实现的。 I'm wondering whether a performance gain can be achieved by using the NSShadow. 我想知道使用NSShadow是否可以实现性能提升。

Also I'm not sure whether NSShadow can be used to draw a shadow of a non-rectangular shape? 另外我不确定NSShadow是否可用于绘制非矩形的阴影? 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. 例如,在另一个问题的答案中,我发现要使用NSShadow,首先需要创建形状的NSBezierPath。

Any hints, suggestions or am I totally off here by trying to use NSShadow in this situation? 有任何提示,建议,还是在这种情况下尝试使用NSShadow完全不适合我?

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. 记住,代码越少,bug越少。

NSShadow works with any shape, rectangular or otherwise. NSShadow可以使用任何形状,矩形或其他形状。 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. 您不需要创建NSBezierPath。 Drawing an image with a shadow will work just fine. 绘制带有阴影的图像会很好用。 The only thing that doesn't is drawing a gradient (as in NSGradient). 唯一没有做的就是绘制渐变(如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. 为了其他读者的利益:所有这些在Quartz中同样适用于CGContext的阴影属性以及CGGradient和CGShading的排除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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