如何打造凸版效果?
我希望在我的应用程序中实现类似著名的“凸版印刷”效果。这就是我要说的:(只是在 PShop 中制作的一个简单示例)
如您所见,它看起来像是被压入背景中的。我想知道是否可以在 Mac 上动态地执行类似的操作。有办法吗?谢谢!
I'm looking to implement something like the famous "letterpress" effect in my application. Here's what I'm talking about: (just a quick example made in PShop)
As you can see, it looks like it's pressed into the background. I wonder if it's possible to do something like this on the Mac dynamically. Is there a way? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用我在 这个答案。首先检查坐标空间,因为我描述了 iPhone 的坐标空间,与 Mac 的正常 Quartz 坐标相比,它具有倒置的 Y 轴。
首先使用文本创建剪切路径,然后在该路径内绘制渐变。
至于内部阴影,您可以在绘制渐变后使用 CGContextSetShadowWithColor() 绘制此阴影,并使用适当的向下偏移和黑色,然后仅使用以下笔画再次绘制文本文本。 deanWombourne 在此处的回答中提供了一些用于类似任务的示例代码。
You can do the gradient fill portion of the text using the code I provide in this answer. Check the coordinate space first, because I described that for the iPhone, which has an inverted Y axis when compared to the Mac's normal Quartz coordinates.
The text is first used to create a clipping path, and the gradient is drawn within that path.
As far as the internal shadow, you might be able to draw this after the gradient is drawn by using
CGContextSetShadowWithColor()
with an appropriate downward offset and black color, then drawing the text again using just the stroke of the text. deanWombourne has some sample code for a similar task in his answer here.这将为您提供一个白色图像,其中文本被剪掉。
在渐变图像的顶部绘制白色图像,并在渐变图像上绘制文本,并在绘制时应用阴影。
This gives you a white image with your text cut out.
Draw the white image with the text cut out on top of the gradient image and apply a shadow while drawing.