本文介绍了MacOS和Swift 3-如何将结果从一个过滤器传递到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此线程中的扩展问题.我不确定如何将CIAffineClamp的结果作为CIGaussianBlur的源传递.下面的代码可以很好地构建,但不会生成最终的图像.

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
}

推荐答案

似乎与此是同一问题:

iOS 6上的CIGaussianBlur和CIAffineClamp

请尝试以下操作:

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

这篇关于MacOS和Swift 3-如何将结果从一个过滤器传递到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 05:48