问题
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