在 OSX 上,如何渐变填充路径笔划? [英] On OSX, how do I gradient fill a path stroke?

查看:29
本文介绍了在 OSX 上,如何渐变填充路径笔划?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Cocoa 或 Quartz 中的大量绘图函数,绘制路径并使用渐变填充它们相当容易.然而,我似乎无法找到一种可接受的方法来描边"-绘制一条线宽为几个像素的路径并使用渐变填充此描边.这是怎么做的?

Using the plethora of drawing functions in Cocoa or Quartz it's rather easy to draw paths, and fill them using a gradient. I can't seem to find an acceptable way however, to 'stroke'-draw a path with a line width of a few pixels and fill this stroke using a gradient. How is this done?

显然这个问题不够清楚.感谢您到目前为止的答复,但我已经想通了.我想做的是:

Apparently the question wasn't clear enough. Thanks for the responses so far, but I already figured that out. What I want to do is this:


(来源:emle.nl)

左边的方块是在路径中绘制的 NSGradient,后跟路径笔画消息.正确的是我想做的;我想使用渐变填充笔触.

The left square is NSGradient drawn in a path followed by a path stroke message. The right is what I want to do; I want to fill the stroke using the gradient.

推荐答案

如果将 NSBezierPath 转换为 CGPath,则可以使用 CGContextReplacePathWithStrokedPath() 方法来检索作为描边路径轮廓的路径.Graham Cox 出色的 GCDrawKit 有一个 -strokedPath 类别NSBezierPath 上的方法,它将为您完成此操作,而无需下拉到核心图形.

If you convert the NSBezierPath to a CGPath, you can use the CGContextReplacePathWithStrokedPath() method to retrieve a path that is the outline of the stroked path. Graham Cox's excellent GCDrawKit has a -strokedPath category method on NSBezierPath that will do this for you without needing to drop down to Core Graphics.

一旦你有了勾勒出的路径,你就可以用 NSGradient 填充该路径.

Once you have the outlined path, you can fill that path with an NSGradient.

这篇关于在 OSX 上,如何渐变填充路径笔划?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆