【问题标题】:Color Vignette Core Image filter for iOS?适用于 iOS 的彩色晕影核心图像过滤器?
【发布时间】:2014-09-30 03:39:25
【问题描述】:

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

【问题讨论】:

    标签: ios ios8 core-image


    【解决方案1】:

    您可以通过将高斯模糊、晕影、带蒙版的混合和原始图像链接在一起来创建滤镜。首先使用CIGaussianBlur 模糊输入图像。接下来,将CIVignette 滤镜应用于相同大小的纯白色图像。最后,使用CIBlendWithMask 滤镜将原始图像与模糊图像混合。

    【讨论】:

    • 我试过了,好像效果不大,我附上我的代码。
    • 你能上传一张你得到的照片吗? (如果您没有足够的代表,只需将其上传到免费图片托管网站,我会将其添加到您的帖子中。)
    • 好的,但请注意 - 它们看起来和我一模一样。
    • 您可以尝试分步进行。例如,只输出模糊的图像,看看它是否正确。如果是这样,输出白色图像,看看它是否正确。如果是这样,输出带有晕影的白色图像,看看它是否正确,等等。也许你的蒙版不正确,或者类似的东西,输出只是输入,因为蒙版完全是白色或黑色或其他什么?
    • 我一直在测试,发现一个更简单的收据:1)CIGaussianBlur 图像,2)创建 CIRadialGradient 蒙版,3)使用 CIBlendWithMask 将模糊图像和图像合并在一起,与径向蒙版!看起来很酷。
    猜你喜欢
    • 1970-01-01
    • 2017-11-18
    • 2013-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-22
    • 2012-04-06
    • 1970-01-01
    相关资源
    最近更新 更多