Core Graphics中的内部阴影 [英] Inner shadow in Core Graphics

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

问题描述

我想在Core Graphics中做类似于Photoshops内部的阴影效果。如果我绘制/填充具有这种效果的路径,我希望得到类似于以下内容的内容: alt text http://i45.tinypic。 com / 357kile.png

解决方案

以下是您需要创建的图层,从后到前面:

基本颜色,在这种情况下是白色背景。



阴影。



铸造阴影的形状。这是通过找到内部形状的边界框,使该框扩展超过阴影的宽度,然后在内部形状的框中切出一个洞。



用内部形状剪裁这些。然后最后画出周围的彩色形状,在这种情况下,一个矩形的内部形状被切掉。注意:根据预期的外观,投射阴影的形状可能与填充前景色的形状相同或不同。内部形状和外部形状之间的薄部分会减少阴影。如果不需要这种效果,则需要更大的外形以获得一致的内部阴影。此外,如果阴影延伸超出外形,则需要显式剪切阴影。



要在中间绘制一个带孔的形状,就像这个示例形状,你会想绘制一条具有两个子路径的路径。一个子路径是外框,另一个是内部不规则形状。如果您使用的是默认的非零卷绕编号规则,则需要为内部不规则形状指定相反方向上的外部框的点。例如,按顺时针顺序指定外框的点将需要以逆时针顺序指定内形的点。请参阅 Quartz 2D程序员指南关于路径的部分了解更多详情。


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: alt text http://i45.tinypic.com/357kile.png

解决方案

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 shadow.

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.

Clipping these 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.

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.

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

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