2016-07-30 21 views

Antwort

2

So zeichnen Sie eine NSAttributedString auf eine NSImage. Ich habe die Umwandlung zu CIImage though (die letzte Zeile) nicht getestet, aber es sollte nicht zu schwierig sein:

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

Vielen Dank! Das hat den Trick gemacht. Auch die Konvertierung in ein CI-Image funktionierte einwandfrei, und mein benutzerdefinierter CIFilter bewältigte das Problem problemlos. – Optimalist