在CGMutablePath中绘制UIImage

给定CGMutablePathRef如何在其中绘制UIImage? 我知道您可以像下面那样绘制它:

UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [scaledImage drawAtPoint:CGPointMake(0, 0)]; CGContextRestoreGState(context); 

但我不确定我是否有路径(这是一个带圆角的矩形)如何在其中添加图像?

当你说“在CGMutablePath中绘制”时,我必须假设你的意思是“ 剪辑到 CGMutablePath”。 在这种情况下,您只需要添加当前上下文的路径( CGContextAddPath()或任何路径构建函数,如CGContextAddLineToPoint() ),然后调用CGContextClip() 。 然后,您可以在上下文中使用drawAtPoint:CGContextDrawImage()绘制图像。

我认为你正在选择这样做的艰难方式。

您的方法假定您已经获得了位图并创建了基于位图的图形上下文。 在你的地方我会使用UIImage的:

 - (void)drawAtPoint:(CGPoint)point;