Drawing path stroke and shadow (iOS)
I'm using this code to create a rounded cornered image:
CGContextBeginPath(context);
CGRect rect = CGRectMake(0, 0, ima开发者_JAVA百科geObj.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);
How can I add a stroke and shadow?
Didn't work for me so far...
Thank you!
You have to do either a CGContextStrokePath or CGContextFillPath to draw the path you made. (make sure you set the stroke color first with CGContextSetStrokeColor) and then you can use CGContextSetShadow to make a shadow, here is an apple developer page describing CoreGraphics Shadows:
http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_shadows/dq_shadows.html
精彩评论