在 swift MacOS 中,点不会在 CGContext 中绘制

Dots won't draw in CGContext in swift MacOS

我有问题。我的点 (GCRect) 不会绘制在我的 CGImage 上。虽然坐标是正确的。

这是我的代码

  public func drawFaceDots (onImage image : CGImage) -> CGImage {
    let faceRect = CGRect(x: 0, y: 0, width: image.width, height: image.height)
    let diameter : CGFloat = 5

    print(faceRect)
    let context = CGContext(data:  nil, width: image.width, height: image.height, bitsPerComponent: 8, bytesPerRow: 4 * image.width, space: CGColorSpaceCreateDeviceRGB(), bitmapInfo: CGImageAlphaInfo.premultipliedFirst.rawValue)!

    //context.draw(image, in: faceRect)
    context.setFillColor(NSColor.red.cgColor)

    for point in self.orignalFace! {
        print("Point(\(point.x);\(point.y))")
        let widthX = point.x * CGFloat(image.width) + diameter
        let heightY = point.y * CGFloat(image.height) + diameter
        let boundingRect = CGRect(x: CGFloat(image.width) * point.x, y: CGFloat(image.height) * point.y, width: widthX, height: heightY)

        print("BoundingRect : \(boundingRect))")

        context.addEllipse(in: boundingRect)
        context.setFillColor(NSColor.green.cgColor)

    }

    return context.makeImage()!

}

谁能帮帮我?

您定义了贝塞尔曲线路径,但从未请求绘制它。

添加:

context.fillPath() 

或者:

context.drawPath(using: .fill)

循环后。