问题
How do I combine two or more CIImage into another one. I tried using ciContext.drawImage. How do I get a CGImage from it ?? What I have understood is that I am writing into a context from which I should be able to get an Image. Please let me know if I have understood anything wrong.
let eaglContext = EAGLContext(API: .OpenGLES2)
let ciContext = CIContext(EAGLContext: eaglContext)
ciContext.drawImage(firstCIImage, inRect: firstRect, fromRect: secondRect)
ciContext.drawImage(secondCIImage, inRect: secondRect, fromRect: secondRect)
回答1:
You may try something like that:
var outputImage: CIImage?
let images : Array<CIImage> = [] // add all your CIImages that you'd like to combine
for image in images {
outputImage = outputImage == nil ? image : image.imageByCompositingOverImage(outputImage!)
}
var cgImage: CGImageRef
if let image = outputImage {
let eaglContext = EAGLContext(API: .OpenGLES2)
let ciContext = CIContext(EAGLContext: eaglContext)
cgImage = ciContext.createCGImage(image, fromRect: image.extent)
}
回答2:
You should use CIFilter-s for that :)
tutorial
来源:https://stackoverflow.com/questions/31996715/how-do-i-combine-two-ore-more-ciimage