我有一个问题。我的点 (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)
在循环之后。
关于swift - 点不会在 swift MacOS 中绘制在 CGContext 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50600260/