I'm trying to add a image on a video, and then I found
CodePudding user response:
In Swift, you can use the newish (since iOS 13) protocol-based interface for CIFilters
:
import CoreImage.CIFilterBuiltins
let filter = CIFilter.blendWithMask()
filter.inputImage = image
filter.backgroundImage = otherImage
filter.maskImage = mask
let output = filter.outputImage
Alternatively, you can use the string-based API that is used in the Objective-C code above in Swift as well:
let filter = CIFilter(name: "CIBlendWithMask")
filter?.setValue(image, forKey: kCIInputImageKey)
filter?.setValue(otherImage, forKey: kCIInputBackgroundImageKey)
filter?.setValue(mask, forKey: kCIInputMaskImageKey)
let output = filter.outputImage