给定CGMutablePathRef如何在其中绘制UIImage?我知道您可以像下面那样绘制它:
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[scaledImage drawAtPoint:CGPointMake(0, 0)];
CGContextRestoreGState(context);
但我不确定我是否有路径(这是一个带圆角的矩形)如何在其中添加图像?
答案 0 :(得分:0)
当你说“在CGMutablePath中绘制”时,我必须假设你的意思是“剪辑到 CGMutablePath”。在这种情况下,您只需要将路径添加到当前上下文(CGContextAddPath()
或任何路径构建函数,如CGContextAddLineToPoint()
),然后调用CGContextClip()
。然后,您可以使用drawAtPoint:
或CGContextDrawImage()
答案 1 :(得分:0)
我认为你选择了艰难的做法。
您的方法假设您已经获得了位图并创建了基于位图的图形上下文。在你的地方我会使用UIImage:
- (void)drawAtPoint:(CGPoint)point;