核心图形中的内阴影 [英] Inner shadow in Core Graphics

查看:39
本文介绍了核心图形中的内阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Core Graphics 中做一些类似于 Photoshop 的内阴影效果.如果我用这种效果绘制/填充路径,我想要得到类似于以下内容:

I want to do something similar to Photoshops inner shadow effect in Core Graphics. If I draw/fill a path with this effect, I want get something similar to the following:

推荐答案

以下是制作此图像所需的图层,从后到前:

Here are the layers you need to create to make this image, from back to front:

基色,在本例中为白色背景.

The base color, in this case a white background.

阴影.

投射阴影的形状.这是通过找到内部形状的边界框,将该框扩大超过阴影的宽度,然后在具有内部形状的框上切一个洞来实现的.

The shape casting the shadow. This is made by finding the bounding box of the inner shape, expanding that box by more than the width of the shadow, then cutting a hole in the box with the inner shape.

用内部形状剪裁这些.

然后最后绘制周围的彩色形状,在这种情况下是一个内部形状被切掉的矩形.

Then finally drawing the surrounding colored shape, in this case a rectangle with the inner shape cut out.

注意:根据预期的外观,投射阴影的形状可能与填充前景色的形状相同,也可能不同.内部形状和外部形状之间的薄部分将投射减少的阴影.如果不需要这种效果,则需要更大的外部形状以获得一致的内部阴影.此外,如果阴影超出外部形状,则需要对阴影进行显式剪裁.

Note: Depending upon the expected look, the shape casting the shadow may or may not be the same shape filling the foreground color. A thin section between the inner shape and the outer shape would cast a reduced shadow. If that effect is not desired, a larger outer shape would be required to get the consistent inner shadow. Also, the explicit clipping of the shadow is required in case the shadow extends beyond the outer shape.

要绘制一个中间有孔的形状,例如这个示例形状,您需要绘制一条带有两个子路径的路径.一个子路径是外框,另一个子路径是内部不规则形状.如果您使用默认的非零缠绕数规则,您需要在与内部不规则形状相反的方向上指定外部框的点.例如,按顺时针顺序指定外部框的点将需要按逆时针顺序指定内部形状的点.参考Quartz 2D Programmer's Guide's section on Paths 了解更多详情.

To draw a shape with a hole in the middle, like this example shape, you'll want to draw a path with two subpaths. One subpath would be the outer box, and the other would be the inner irregular shape. If you're using the default nonzero winding number rule, you'll want to specify the points for the outer box in the opposite direction than the inner irregular shape. For example, specifying the outer box's points in clockwise order would require specifying the inner shape's points in counter-clockwise order. Refer to the Quartz 2D Programmer's Guide's section on Paths for more details.

这篇关于核心图形中的内阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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