我已经在 Core Image 中测试了晕影滤镜,虽然不错 - 我想知道是否有人通过链接 iOS 的各种 Core Image 滤镜来实现彩色晕影效果(而不是黑边,它柔化了边缘)?或者给我指点一个教程来做到这一点?
根据下面的答案,这是我的代码 - 但似乎没有太大效果。
func colorVignette(image:UIImage) -> UIImage {
let cimage = CIImage(image:image)
let whiteImage = CIImage(image:colorImage(UIColor.whiteColor(), size:image.size))
var output1 = CIFilter(name:"CIGaussianBlur", withInputParameters:[kCIInputImageKey:cimage, kCIInputRadiusKey:5]).outputImage
var output2 = CIFilter(name:"CIVignette", withInputParameters:[kCIInputImageKey:whiteImage, kCIInputIntensityKey:vignette, kCIInputRadiusKey:1]).outputImage
var output = CIFilter(name:"CIBlendWithMask", withInputParameters:[kCIInputImageKey:cimage, kCIInputMaskImageKey:output2, kCIInputBackgroundImageKey:output1]).outputImage
return UIImage(CGImage:ctx.createCGImage(output, fromRect:cimage.extent()))
}
func colorImage(color:UIColor, size:CGSize) -> UIImage {
UIGraphicsBeginImageContextWithOptions(size, false, 0)
color.setFill()
UIRectFill(CGRect(x:0, y:0, width:size.width, height:size.height))
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
最佳答案
您可以通过将高斯模糊、晕影、混合蒙版和原始图像链接在一起来创建滤镜。首先使用 CIGaussianBlur
模糊输入图像。接下来,将 CIVignette
滤镜应用于相同大小的纯白色图像。最后,使用 CIBlendWithMask
将原始图像与模糊图像混合。过滤器。
关于ios - 适用于 iOS 的 Color Vignette Core Image 过滤器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25173325/