我使用CGContextFillPath绘制Quartz 2D形状,如下所示:
CGContextRef conPattern = CGBitmapContextCreate(NULL,
shp.size.width*2,
shp.size.height*2,
8,
0,
rgbColorSpace,
(CGBitmapInfo)kCGImageAlphaPremultipliedFirst);
CGContextSetLineWidth(conPattern, 10);
CGContextSetStrokeColorWithColor(conPattern, [UIColor blackColor].CGColor);
Line * start = [verticesPassed objectAtIndex:0];
StandPoint * startPoint = start.origin;
CGContextMoveToPoint(conPattern, ([startPoint.x floatValue]-shp.origin.x)*2 , ([startPoint.y floatValue]-shp.origin.y)*2);
for (Line * vertice in verticesPassed) {
StandPoint * standPoint = vertice.origin;
CGContextAddLineToPoint(conPattern, ([standPoint.x floatValue]-shp.origin.x)*2, ([standPoint.y floatValue]-shp.origin.y)*2);
}
CGContextSetFillColorWithColor(conPattern, [UIColor yellowColor].CGColor);
CGContextFillPath(conPattern);
[self drawText:conPattern startX:0 startY:20 withText:standName];
[self drawText:conPattern startX:0 startY:50 withText:standNumber];
//Make the main image and color it with pattern.
CGImageRef cgImage = CGBitmapContextCreateImage(conPattern);
UIImage *imgPattern = [[UIImage alloc]initWithCGImage:cgImage];
这很好用,并绘制我填充的形状。我想要做的就是显示已画出的线条。
我尝试在CGContextStrokePath中添加,但没有运气:
Line * start = [verticesPassed objectAtIndex:0];
StandPoint * startPoint = start.origin;
CGContextMoveToPoint(conPattern, ([startPoint.x floatValue]-shp.origin.x)*2 , ([startPoint.y floatValue]-shp.origin.y)*2);
for (Line * vertice in verticesPassed) {
StandPoint * standPoint = vertice.origin;
CGContextAddLineToPoint(conPattern, ([standPoint.x floatValue]-shp.origin.x)*2, ([standPoint.y floatValue]-shp.origin.y)*2);
}
CGContextSetFillColorWithColor(conPattern, [UIColor yellowColor].CGColor);
CGContextFillPath(conPattern);
CGContextStrokePath(conPattern);
有人可以建议我如何实现这个目标吗?
答案 0 :(得分:10)
填写时会消耗路径。如果你想要填充和描边,那么你应该使用
CGContextDrawPath(conPattern, kCGPathFillStroke); // both fill and stroke