swiftmacosnsimageciimage

How to convert NSImage to CIImage?


I would like to convert an NSImage to a CIImage in Swift 2.2 for a macOS app.

How can I do this?


Solution

  • Here's one way:

    let image = NSImage(contentsOfFile: "...")!
    let imageData = image.tiffRepresentation!
    
    let ciImage = CIImage(data: imageData)