【发布时间】:2011-06-29 17:29:31
【问题描述】:
我正在使用此代码创建圆角图像:
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);
如何添加描边和阴影?
到目前为止对我没用...
谢谢!
【问题讨论】:
-
路径绘制代码绘制的是椭圆形,而不是圆角矩形。对于圆角矩形,您需要选择一个角半径,然后将该半径用作每个圆弧的半径。从一个角到下一个角的直线将为您包括在内。
标签: ios drawing core-graphics quartz-graphics