2017-12-08 20 views
0

私はCGContextに描画したいオブジェクトNSImageを持っています。 は、私は、それを行うにしてください必要がありますかどのようにクリップCGContextにNSImageを描画する方法

func clip(to: CGRect, mask: CGImage) 

、CGContextには、対応する方法がないことがわかったが、CGImage方法があるように思われますか?

+0

はCIImageオブジェクトにNSImgeオブジェクトに変換します。その後、CGContextを作成することができます。 –

答えて

0

最も簡単な方法は、あなたのCGContextをラップNSGraphicsContextを作成し、それに描画するためにです:

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) 
関連する問題