我有一个对象NSImage,我想绘制到CGContext . 我发现CGContext没有相应的方法,但似乎有一个CGImage方法,剪辑
func clip(to: CGRect, mask: CGImage)
请问我该怎么做?
最简单的方法是创建 NSGraphicsContext 包装你的 CGContext ,并绘制到:
NSGraphicsContext
CGContext
let gc: CGContext = ... let nsImage: NSImage = ... let rect: CGRect = ... let priorNsgc = NSGraphicsContext.current defer { NSGraphicsContext.current = priorNsgc } NSGraphicsContext.current = NSGraphicsContext(cgContext: gc, flipped: false) nsImage.draw(in: rect)
1 回答
最简单的方法是创建
NSGraphicsContext
包装你的CGContext
,并绘制到: