-
-
Save anupamchugh/67c3f068c7df8f8a43a6823a8936543b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func maskInputImage(){ | |
let bgImage = UIImage.imageFromColor(color: .blue, size: self.inputImage.size, scale: self.inputImage.scale)! | |
let beginImage = CIImage(cgImage: inputImage.cgImage!) | |
let background = CIImage(cgImage: bgImage.cgImage!) | |
let mask = CIImage(cgImage: self.outputImage.cgImage!) | |
if let compositeImage = CIFilter(name: "CIBlendWithMask", parameters: [ | |
kCIInputImageKey: beginImage, | |
kCIInputBackgroundImageKey:background, | |
kCIInputMaskImageKey:mask])?.outputImage | |
{ | |
let ciContext = CIContext(options: nil) | |
let filteredImageRef = ciContext.createCGImage(compositeImage, from: compositeImage.extent) | |
self.outputImage = UIImage(cgImage: filteredImageRef!) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment