如何使用CiFilter使用swift提供凹凸效果?

时间:2016-01-21 10:10:14

标签: ios swift cifilter

我怎样才能在swift中做到这一点?

[1]: http://i.stack.imgur.com/FKb7v.png

我试图将此效果特别设置为图像上的位置。 请提供简单的代码来应用此效果。 提前谢谢。

Error while adding distortion bump effect.

2 个答案:

答案 0 :(得分:0)

试试这段代码:

public typealias Filter = CIImage -> CIImage
public typealias CIParameters = Dictionary<String, AnyObject>

public func bumpDistortion(center: CGPoint, radius: Float, scale: Float) -> Filter {
    return { image in
        let parameters : CIParameters = [
            kCIInputRadiusKey:radius,
            kCIInputCenterKey:CIVector(CGPoint:center),
            kCIInputScaleKey:scale,
            kCIInputImageKey: image]
        let filter = CIFilter(name:"CIBumpDistortion", withInputParameters:parameters)
        return filter!.outputImage!
    }
}

答案 1 :(得分:0)

让我们假设您使用TastyCat中的代码:

 if let image = UIImage(named: "YOUR_IMAGE_NAME") {

        let bumpEffect = self.bumpDistortion(YOUR_POINT  , radius:YOUR_RADIUS, scale:YOUR_SCALE)
        guard let yourCIImage =  CIImage(image: image) else {
            //handle error
            return
        }
        let result = bumpEffect(yourCIImage)
        let theImageWithEffect = UIImage(CIImage:result)
    }