在OSX上,我如何用渐变填充轨迹? [英] On OSX, how do I gradient fill a path stroke?

查看:131
本文介绍了在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:

左方块是在路径中绘制的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 上的类别方法将为您执行此操作,而不需要下拉到Core Graphics。

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天全站免登陆