使用Cocoa将阴影添加到PNG [英] Add drop shadow to PNG using Cocoa
本文介绍了使用Cocoa将阴影添加到PNG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些透明背景的PNG,我想以编程方式添加阴影。我已经看到了为方形物体添加阴影的例子,但没有看到任何复杂的形状。
I have some PNGs with transparent backgrounds that I would like to add shadows to programatically. I've seen examples of adding shadows to square objects, but haven't seen any with complex shapes.
所以我认为我必须做的两个步骤be:
So the two steps I think I'd have to do would be:
- 隔离PNG形状
- 在PNG后面绘制一个模糊,褪色的形状和偏移。
我在Cocoa中绘制的经验不多,所以对于从哪里开始的任何见解都将非常感激!
I don't have much experience with drawing within Cocoa, so any insight on where to begin would be much appreciated!
屏幕截图:
alt http://www.iworkinprogress.com/images/pngExample.png
推荐答案
最简单的方式是打电话在绘制图像之前, CGContextSetShadow
在 drawRect:
中。
Simplest way is to call CGContextSetShadow
in your drawRect:
before you draw the images.
- (void)drawRect:(CGRect)invalidRect
{
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetShadow(c, CGSizeMake(5.0f, 5.0f), 5.0f);
[myImage drawAtPoint:CGPointMake(50.0f, 50.0f)];
}
这篇关于使用Cocoa将阴影添加到PNG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文