ios - 适用于 iOS 的 Color Vignette Core Image 过滤器?

标签 ios ios8 core-image

我已经在 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/

相关文章:

ios swift - 如何在浏览应用程序时保持视频播放

ios - 如何从 Visual Studio 中选择合适的 iPhoneSimulator 设备? (iPhoneSimulator 始终启动 3.5 英寸设备)

ios - 这个 objective-c 代码是否创建了一个强大的引用循环?

ios - 主队列上的 Touch ID

ios - UIViewController interfaceOrientation 属性已弃用

ios - CIImage 和 CIFilter 实现细节

python - 如何找到两个不同音频样本之间的标度?

ios - 处理 iPhone 6/6+ 启动图像

ios - 使用 CILanczosScaleTransform Core Image Filter 调整图像大小

core-image - 核心图像过滤器 "CIDepthBlurEffect"不适用于 iOS 11/Xcode 9.0