如何在 Swift 中添加具有模糊效果的渐变视图?我可以很轻松地向视图添加渐变层 (CAGradientLayer)。我还可以单独添加模糊视图(UIVisualEffectView)。
如何将两者结合起来创建一个模糊视图,该视图还具有渐变元素,其中完全模糊渐变到不模糊?
类似效果的示例:
如果你知道的话核心图像 https://developer.apple.com/library/content/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html#//apple_ref/doc/uid/TP40004346,您可以轻松地将两个过滤器链接在一起,一个来自 CICategoryBlur,另一个来自 CICategoryGradient 类别。
这是一个用法示例。 TO链,只需将第一个过滤器的输出作为下一个过滤器的输入:
func convertImageToBW(image:UIImage) -> UIImage {
let filter = CIFilter(name: "CIPhotoEffectMono")
// convert UIImage to CIImage and set as input
let ciInput = CIImage(image: image)
filter?.setValue(ciInput, forKey: "inputImage")
// get output CIImage, render as CGImage first to retain proper UIImage scale
let ciOutput = filter?.outputImage
let ciContext = CIContext()
let cgImage = ciContext.createCGImage(ciOutput!, from: (ciOutput?.extent)!)
return UIImage(cgImage: cgImage!)
}
上面的链接是 Apple 文档。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)