2016-07-30 36 views

回答

2

下面介紹如何將NSAttributedString繪製到NSImage上。我沒有測試轉換爲CIImage雖然(最後一行),但它不應該太難:

let string = NSAttributedString(string: "Hello World!", attributes: [NSFontAttributeName: NSFont.labelFontOfSize(10)]) 
let image = NSImage(size: string.size()) 
image.lockFocus() 
NSGraphicsContext.saveGraphicsState() 
NSGraphicsContext.currentContext()!.shouldAntialias = true 
string.drawAtPoint(NSZeroPoint) 
NSGraphicsContext.restoreGraphicsState() 
image.unlockFocus() 

let ciimage = CIImage(data: image.TIFFRepresentation!)! 
+0

謝謝!那就是訣竅。此外,轉換到CIImage工作正常,我的自定義CIFilter處理它沒有問題。 – Optimalist