MacOS and Swift 3 - how to pass result from one filter to another

强颜欢笑 提交于 2019-12-12 05:09:32

问题


Expanding question from this thread. I'm not sure how to pass the result from CIAffineClamp as a source for CIGaussianBlur. The following code builds just fine but does not yield a resulting image.

guard
    let blurFilter = CIFilter(name: "CIGaussianBlur"),
    let clampFilter = CIFilter(name: "CIAffineClamp"),
    let imageURL = Bundle.main.url(forResource: "my-image", withExtension: "png"),
    let ciImage = CIImage(contentsOf: imageURL)
else {
    return
}

let transform = AffineTransform.identity

clampFilter.setValue(ciImage, forKey: "inputImage")
clampFilter.setValue(NSAffineTransform(transform: transform), forKey: "inputTransform")

blurFilter.setValue(clampFilter.outputImage, forKey: kCIInputImageKey)
blurFilter.setValue(10, forKey: kCIInputRadiusKey)

guard
    let result = blurFilter.outputImage,
    let cgImage = context.createCGImage(result, from: result.extent)
else {
    // this guard fails in here
    return
}

回答1:


Seems to be the same issue with this:

CIGaussianBlur and CIAffineClamp on iOS 6

Please try this:

    let cgImage = context.createCGImage(result, from: ciImage.extent)


来源:https://stackoverflow.com/questions/39942029/macos-and-swift-3-how-to-pass-result-from-one-filter-to-another

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