Possible Duplicate:
drawing UIImage inside a CGMutablePath可能重复:在CGMutablePath中绘制UIImage
I have a path in my drawRect that looks like this:
我的drawRect中有一条路径如下:
CGContextSetLineWidth(context, 1.5);
CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextAddEllipseInRect(context, rect);
CGContextStrokePath(context);
CGContextClip(context);
CGContextTranslateCTM(context, 0.0, rect.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, rect, self.image_.CGImage);
UIGraphicsBeginImageContext(rect.size);
UIImage * circleUserProfile = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[circleUserProfile drawAtPoint:CGPointMake(0, 0)];
CGContextRestoreGState(context);
and I have a UIImage, and I want so that the UIImage to clip inside this circle. The code above seemed to be doing what I asked before here, but still doesn't work. Why is this?
我有一个UIImage,我想让UIImage夹在这个圈子里面。上面的代码好像在做我之前问过的,但仍然无法正常工作。为什么是这样?
1 个解决方案
#1
1
When you call UIGraphicsBeginImageContext
, you're creating a new context, pushing your previous one (that you did all your drawing in), and making the new (empty) one the current context. You need to begin your image context prior to calling UIGraphicsGetCurrentContext
and performing your drawing.
当您调用UIGraphicsBeginImageContext时,您正在创建一个新的上下文,推送您的上一个上下文(您完成了所有绘图),并将新(空)一个作为当前上下文。您需要在调用UIGraphicsGetCurrentContext并执行绘图之前开始图像上下文。
#1
1
When you call UIGraphicsBeginImageContext
, you're creating a new context, pushing your previous one (that you did all your drawing in), and making the new (empty) one the current context. You need to begin your image context prior to calling UIGraphicsGetCurrentContext
and performing your drawing.
当您调用UIGraphicsBeginImageContext时,您正在创建一个新的上下文,推送您的上一个上下文(您完成了所有绘图),并将新(空)一个作为当前上下文。您需要在调用UIGraphicsGetCurrentContext并执行绘图之前开始图像上下文。