Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
Last active May 31, 2016 15:38
Show Gist options
  • Save KentarouKanno/3b3c0e029673bbe35c4dad723470ff7c to your computer and use it in GitHub Desktop.
Save KentarouKanno/3b3c0e029673bbe35c4dad723470ff7c to your computer and use it in GitHub Desktop.
CoreImage

CoreImage (CIFilter)

【iOS】【swift】たった数行で画像のフィルタ/エフェクトが実現できる超便利フレームワークCoreImage

// セピア【CISepiaTone】

@IBOutlet weak var photoImageView: UIImageView!

if let ciImage = CIImage(image: self.photoImageView.image!), let ciFilter = CIFilter(name: "CISepiaTone") {
    ciFilter.setValue(ciImage, forKey: kCIInputImageKey)
    ciFilter.setValue(1.0, forKey: "inputIntensity")
    let ciContext = CIContext(options: nil)
    
    if let outputImage = ciFilter.outputImage {
        let cgimg = ciContext.createCGImage(outputImage, fromRect: outputImage.extent)
        photoImageView.image = UIImage(CGImage: cgimg, scale:1.0, orientation:UIImageOrientation.Up)
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment