【发布时间】:2015-07-07 04:09:03
【问题描述】:
这样的代码
UIGraphicsBeginImageContextWithOptions(CGSizeMake(100, 100), NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextMoveToPoint(context, 5, 5);
CGContextAddLineToPoint(context, 100, 100);
CGContextSetLineWidth(context, 5);
CGContextSetFillColorWithColor(context, [UIColor blueColor].CGColor);
CGContextFillPath(context);
CGContextSetStrokeColorWithColor(context, [UIColor grayColor].CGColor);
CGContextStrokePath(context);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
当我删除填充颜色时,图像是正确的。 但我不明白为什么我在图像中添加填充颜色什么都不是?
【问题讨论】:
-
您尚未创建路径,因此填充可能会填充整个上下文。您需要创建一个封闭的誓言来履行它。
-
1、如果我没有路径,笔划路径如何生效。 2、如果我把fillPath方法放在stoke路径之后,那么图像是正确的。这要怎么解释?
-
1.您没有可以填充的封闭路径。你只有一条线,你可以抚摸。 2. 最有可能抚摸线条使其成为一条封闭路径,让您可以填充它。
-
@rmaddy 感谢您的回答。