How do I combine two ore more CIImage

五迷三道 提交于 2019-12-07 14:32:15

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!