我正在使用iOS应用程序中的UIBezierPath()和DragGesture在画布上绘制线条.为此,我收集手势点并将它们添加到路径中,该路径是UIBezierPath的对象.然后,我设置了特定的线宽,并在图形上下文中对路径进行了描边.
However, I'm facing an issue when trying to draw a circle shape quickly. Instead of getting a smooth curve, the connecting points of the path create corners, resulting in an angular shape rather than a circular one. This issue specifically occurs when drawing circles rapidly, and it affects the overall quality of my drawings. For more visualisation look here:
func draw(size: CGSize, drawingImage: UIImage, lines: [Line], path: UIBezierPath) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(size, false, 1.0)
drawingImage.draw(at: .zero)
let pathCount = lines.count
let pointCount = lines[pathCount-1].line.count
let point = lines[pathCount-1].line[pointCount-1]
path.addLine(to: point.toCGPoint())
let context = UIGraphicsGetCurrentContext()!
context.addPath(path.cgPath)
context.setStrokeColor(Color.white.cgColor)
path.lineWidth = 50
path.lineCapStyle = .round
path.lineJoinStyle = .round
path.stroke()
let myImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return myImage
}
我正在寻求指导,如何确保路径的连接点创建平滑的曲线,即使在快速绘制圆形时也是如此.如有任何见解或建议,我们将不胜感激.谢谢!