看看我的绘画应用程序生成的这条奇怪的路径:
中间的红线是一个调试功能,代表输入鼠标移动以及它们之间的距离(线宽为 1 px),黑色是输出,线宽为 30 px。
我绘制此图的方式很简单,只是合并鼠标事件之间的点对点:
//This is called in mouseDragged: and [theEvent locationInWindow] is passed to point
-(void)addPointToCurrentStroke:(CGPoint)point
if (self.newStroke == TRUE) //If the currentStroke doesn't exist or is empty
{
self.currentStroke = CGPathCreateMutable();
CGPathMoveToPoint(self.currentStroke, NULL, point.x, point.y);
self.newStroke = FALSE;
}
else if (self.newStroke == FALSE)
CGPathAddLineToPoint(self.currentStroke, NULL, point.x, point.y);
}
然后,使用适当的用户设置(在本例中为大小 30 和颜色黑色)在 drawRect: 中对该路径进行描边。请注意圆形线帽,这使得它像这样突出变得更加奇怪。
那么为什么我会让这些尖峰偏离预期路径那么远呢?我对此一无所知。如果有人能告诉我这里发生了什么,我将不胜感激。
最佳答案
您的 CG 上下文设置为在路径的每个角处使用斜接连接。当该角处有小角度时,斜接可以伸出很长的距离。使用CGContextSetLineJoin
指定圆形连接或斜角连接。
请参阅Quartz 2D Programming Guide, "Parameters That Affect Stroking" .
关于macos - quartz 2D锯齿线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22885741/