本文介绍了CGContext线条图:CGContextFillPath不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都知道为什么CGContextFillPath无法在下面的代码段中使用?我正在使用以下代码绘制到UIImageView。它正确地描述了路径,但忽略了CGContextFillPath。
Anyone have any idea why CGContextFillPath won't work in the code snippet below? I'm using the following code to draw to a UIImageView. It's stroking the path correctly, but ignoring CGContextFillPath.
UIGraphicsBeginImageContext(self.frame.size);
[drawingView.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextSetRGBFillColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), firstMovedTouch.x, firstMovedTouch.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
CGContextFillPath(UIGraphicsGetCurrentContext());
drawingView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
推荐答案
我认为你需要致电 CGContextClosePath
,然后才能填充路径。我不确定你想要绘制什么,但是 CGContextFillPath
将填充路径内的区域,我只在这里看到单行。
I think you need to call CGContextClosePath
before you can fill the path. I am not sure what you are trying to draw, but CGContextFillPath
will fill the area inside the path and I only see single line here.
这篇关于CGContext线条图:CGContextFillPath不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!