Skip to content

Instantly share code, notes, and snippets.

@defsan
Created April 18, 2015 19:56
Show Gist options
  • Save defsan/c94323553772ff7d4bfe to your computer and use it in GitHub Desktop.
Save defsan/c94323553772ff7d4bfe to your computer and use it in GitHub Desktop.
Swift grayscale image
grayImage.lockFocus()
var ciImage:CIImage = CIImage(data: image.TIFFRepresentation)
var monochromeFilter:CIFilter = CIFilter(name: "CIColorMonochrome")
monochromeFilter.setDefaults()
monochromeFilter.setValue(ciImage, forKey:kCIInputImageKey)
monochromeFilter.setValue(CIColor(red: 0, green: 0, blue: 0, alpha: 1), forKey:"inputColor")
monochromeFilter.setValue(NSNumber(float: 1), forKey:"inputIntensity")
var outputImage:CIImage = monochromeFilter.valueForKey(kCIOutputImageKey) as! CIImage
outputImage.drawAtPoint(NSPoint.zeroPoint, fromRect: NSRect(origin: NSPoint.zeroPoint, size: image.size), operation: NSCompositingOperation.CompositeCopy, fraction: 0.6)
grayImage.unlockFocus()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment