ios - 绘制路径描边和阴影(iOS)

标签 ios drawing core-graphics quartz-graphics

我正在使用以下代码创建圆角图像:

CGContextBeginPath(context);
CGRect rect = CGRectMake(0, 0, imageObj.size.width, imageObj.size.height);

    CGContextAddRect(context, rect);


CGContextSaveGState(context);
CGContextTranslateCTM (context, CGRectGetMinX(rect), CGRectGetMinY(rect));
CGContextScaleCTM (context, ovalWidth, ovalHeight);
fw = CGRectGetWidth (rect) / ovalWidth;
fh = CGRectGetHeight (rect) / ovalHeight;
CGContextMoveToPoint(context, fw, fh/2);
CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1);
CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 1);
CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 1);
CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 1);
CGContextRestoreGState(context);

CGContextClosePath(context);
CGContextClip(context);

CGContextDrawImage(context, CGRectMake(0, 0, w, h), imageObj.CGImage);

如何添加笔触和阴影?

到目前为止还没有为我工作...

谢谢!

最佳答案

您必须执行CGContextStrokePath或CGContextFillPath来绘制您创建的路径。 (确保首先使用CGContextSetStrokeColor设置笔触颜色),然后可以使用CGContextSetShadow制作阴影,这是一个描述CoreGraphics Shadows的苹果开发人员页面:

http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_shadows/dq_shadows.html

关于ios - 绘制路径描边和阴影(iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6524805/

相关文章:

Opengl 像素完美 2D 绘图

python - 在 wxPython Canvas 中强制重绘

objective-c - 在 iOS 中绘制 1 像素宽的路径

ios - 如何以编程方式显示 MKUserLocation 注释 View ?

ios - 在 iOS 上创建动态 pdf 文档

android - Canvas.clipPath(Path) 未按预期剪切

ios - 如何使用 Swift 将 CAShapeLayer 之外的所有内容设为黑色且不透明度为 50%?

iphone - 如何清除并重新绘制 quartz 图

IOS 调整 UILabel 宽度

ios - 通过 CoreData 属性显示 tableView 项目